Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 1dc429fc0da4cc5ff4f62617760447613f85980b authored by vbhandawat on 01 February 2021, 13:54:09 UTC, committed by GitHub on 01 February 2021, 13:54:09 UTC
Add files via upload
1 parent 17f20a6
  • Files
  • Changes
  • 345c390
  • /
  • Tracking
  • /
  • bottomViewAnalysis.m
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:1dc429fc0da4cc5ff4f62617760447613f85980b
directory badge Iframe embedding
swh:1:dir:d95c030c609a587149c58f34f4d09a16b4a9bdc6
content badge Iframe embedding
swh:1:cnt:9f4b124970d15610a09f8dfb42aa1880f878e0a6
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
bottomViewAnalysis.m
%This code performs image processing on the bottom view.
%This is used for a preperation for tracking leg movement in getLegs2
%(called by the parent function "mainTrack").
%@Chanwoo Chun <cc2465@cornell.edu>

function [binVid, legTips, notTouching, addedFirst, addedLast] = bottomViewAnalysis(M,frBegin,frEnd,wallUpper,wallLower,background)

%Here, we are adding more frames to analyse before and after the defined
%starting frame (frBegin) and ending frame (frEnd). This will be fixed back
%by getLegs2 function. We need to add the additional frames at the front
%and at the end, since there is going to be a moving window operation 
%across the frames. By appending more data at the beginning and at the
%end, the moving window operation can be operated at those portions.
addedFirst=20;%1
addedLast=20;%1
%Make sure the code is not appending excessive amount of frames.
if frBegin<=addedFirst
    addedFirst=frBegin-1;
end
frBegin=frBegin-addedFirst;

if size(M.data.frames,4)<=frEnd+addedLast
    addedLast=size(M.data.frames,4)-frEnd;
end
frEnd=frEnd+addedLast;

wallUpper = int16(wallUpper);
wallLower = int16(wallLower);

tframes = frEnd-frBegin+1;

M.data.frames = M.data.frames(:,:,:,frBegin:frEnd);
frames = squeeze(M.data.frames);

%Declaring the video matrices.
A = zeros(wallLower-wallUpper+1,size(M.data.frames, 2),size(M.data.frames, 3),tframes);
S = zeros(wallLower-wallUpper+1,size(M.data.frames, 2),size(M.data.frames, 3),tframes);
J = zeros(wallLower-wallUpper+1,size(M.data.frames, 2),size(M.data.frames, 3),tframes);
K = zeros(wallLower-wallUpper+1,size(M.data.frames, 2),size(M.data.frames, 3),tframes);

SE = strel('disk',2);
SE2 = strel('disk',6);

%Perform frame-wise image processes. At the end, J will be a video that
%only shows the tips of the legs as white blobs. K will be a video of a
%skeleton. A will be a background subtracted raw video.
figure
for i = 1:tframes
    A(:,:,i) = M.data.frames(wallUpper:wallLower,:,i) - background(wallUpper:wallLower,:);
    
    %binarize image
    S(:,:,i) = imbinarize(A(:,:,i),4); %use 4 or 7 (7 for bright vid).
    
    %remove noise
    J(:,:,i) = bwareaopen(S(:,:,i), 20);
    
    imshow(mat2gray((J(:,:,i))))
    drawnow
    
    %dilate image
    J(:,:,i)=imdilate(J(:,:,i),strel('disk',2));
    
    %get skeleton of the fly by thinning
    K(:,:,i)=bwmorph(J(:,:,i),'thin',Inf);
  
    %get endpoints of the skeletons
   J(:,:,i) = bwmorph(K(:,:,i),'endpoints');
    
    %dilate the endpoints
   J(:,:,i)=imdilate(J(:,:,i),SE2);
end

%Determine if the fly touched the wall by using the skeleton video.
%This will be used for determining a given frame is valid for future
%analysis.
K=squeeze(sum(K,2));
touchTop = find(prod(K(1:50,:),1));    
touchBottom = find(prod(K(end-50:end,:),1));

touch = union(touchTop,touchBottom);

notTouching = ones(size(K,2),1);
notTouching(touch) = 0;

a=denoise(notTouching.',50);
    
notTouching = a.';
notTouching = notTouching(1+addedFirst:end-addedLast,:);

%Before this, J showed a leg tips at all frames. However, we only need to
%see leg tips during stance phases (footprint).
%As a reminder, J was a black video where leg tips were shown as white
%blobs (objects). We know from experiments that a fly's stance phase lasts
%about 13 frames. Therefore, we are going to look at each pixel and see how
%its value changes through time. In the time series, we are only going to
%keep a group of points that are composed of more than 13 white points
%(value 1). Smaller groups will be erased (changed to zero 0). In other
%words, it is similar to denoising. After doing this for every individual
%pixel, the resulting video will only show stance phases. I wrote a
%vectorized code for denoising. This allows us to perform this
%operation fairly quickly. Remember, this is a moving window operation and
%this is why we needed to append more frames at the beginning and end the
%end.
for h = 1:size(J,1)
   for w = 1:size(J,2)
    J(h,w,:)=denoise(squeeze(J(h,w,:))',13);
   end
   h/size(J,1)*100
end
close
binVid = A;%(:,:,:,1+addedFirst:end-addedLast);
legTips = J;%(:,:,:,1+addedFirst:end-addedLast);
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top