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
  • /
  • findCOM.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:3f517a252c312296925e8dddcc1e98db09e3dba3
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 ...
findCOM.m
%This code finds initial CoM position of the fly in the sideview and the
%bottomview, and also finds a bounding boxes around the CoM points where 
%feature points will be found in another separate function.
%If a body length is 1, we say that CoM is located 0.4 away from the head
%and 0.6 away from the tail. Since we are inputting the head and tail
%locations into this function, CoM position at the bottomview (x,y) and x
%position of CoM at the sideview are easy to get. However, z position of
%CoM is not straightforward. This is explained later in the code.
%
%@Chanwoo Chun <cc2465@cornell.edu>

function [comSide,comBottom, recSide, recBottom] = findCOM(objectFrame, endFrame, background,floorY,wallUpper,wallLower,bottomHead,bottomTail)
%objectFrame is an initial image frame.
%background is a background image.
%rest of the inputs are determined by user in another function that comes
%before this function.

%background subtract image, and then separate the bottomview and sideview.
subtracted=objectFrame - background;
sideBottom = subtracted;
sideMask = zeros(size(sideBottom));
sideMask(1:floorY,:) = 1;
bottomMask = zeros(size(sideBottom));
bottomMask(wallUpper:wallLower,:)=1;
sideView = sideBottom.*uint8(sideMask);
bottomView = sideBottom.*uint8(bottomMask);

%get binarized image
%If there are more than two blobs after binarization, the code will run
%into an error. Make sure that the threshold is appropriate for imbinarize.
sideView = imbinarize(sideView,0.04);
bottomView = imbinarize(bottomView,0.04);
bottomView = bwareaopen(bottomView,100,4);

sideView = imopen(sideView,strel('disk',8));%remove legs
bottomView = imopen(bottomView,strel('disk',8));

%check if there is only one blob in each plot.
figure
subplot(2,1,1)
imshow(sideView)
subplot(2,1,2)
imshow(bottomView)
drawnow

%get centroids, length of minor axes, and orientations of the blobs.
s  = regionprops(sideView ,'centroid','MinorAxisLength','Orientation');
b  = regionprops(bottomView ,'centroid','MinorAxisLength','Orientation');

%Two blocks of for-loops shown below are used to find the best rectangles
%centered at CoM that will ensure maximum number of feature points. The for
%loops iterate through different sizes of the rectangles and see how many
%feature points can be detected inside the rectangular region.
i=30;
rectangle('Position',[s.Centroid(:,1)-4*i/2,s.Centroid(:,2),4*i,i],'EdgeColor','r');
%%sideView
maxPoints = 1;
for i=2:8:round(s.MinorAxisLength)+15

    sideRegion=[s.Centroid(:,1)-2*i/2,s.Centroid(:,2)-i/2,2*i,i];
    rectangle('Position',[s.Centroid(:,1)-2*i/2,s.Centroid(:,2)-i/2,2*i,i],'EdgeColor','w');
    try
    points = detectMinEigenFeatures(subtracted,'ROI',sideRegion);
    catch
        continue
    end
    
    if size(points.Location,1)>maxPoints
        maxPoints = size(points.Location,1);
        recSide = sideRegion;
    end

end  

i=40;
rectangle('Position',[b.Centroid(:,1)-i/2,b.Centroid(:,2)-i/2,i,i],'EdgeColor','w');
%%bottomView
maxPoints = 1;
for i=2:8:round(b.MinorAxisLength)+15

    bottomRegion=[b.Centroid(:,1)-2*i/2,b.Centroid(:,2)-2*i/2,2*i,2*i];
    rectangle('Position',[b.Centroid(:,1)-2*i/2,b.Centroid(:,2)-2*i/2,2*i,2*i],'EdgeColor','w');
    %needs to be improved -> rectangle('Position',[bottomHead(1),bottomHead(2),abs(bottomHead(1) - bottomTail(1)),abs(bottomHead(2) - bottomTail(2))],'EdgeColor','w');
    try
    points = detectMinEigenFeatures(subtracted,'ROI',bottomRegion);
    catch
    end
    
    if size(points.Location,1)>maxPoints
        maxPoints = size(points.Location,1);
        recBottom = bottomRegion;
    end

end      


%%%%%%%%%%%%%%%%%%%%%%%%%%adjust COM%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
comBottom=(bottomHead - bottomTail)*0.6+bottomTail;
comSide(1) = comBottom(1);
%find z position of the CoM by referring to the slope of the fly in
%sideview.
comSide(2) = tan(deg2rad(-s.Orientation))*(comBottom(1)-s.Centroid(1))+s.Centroid(2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure
subplot(2,1,1)
imshow(sideView);
hold on
plot(comSide(1),comSide(2), 'b*')
hold off
subplot(2,1,2)
imshow(bottomView)
hold on
plot(comBottom(1),comBottom(2), 'b*')
hold off
drawnow
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