Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
876db5d0ce
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 70 lines (42 sloc) 1.23 KB
% Extracts the biggest blob out of a binary image
%
%
function [bwmouse, o] = blobTrackExtractMouse(bw,varargin);
o =mbparse.output();
p = inputParser();
p.addParamValue('maxPixels',5000);
p.addParamValue('minPixels',200);
p.addParamValue('backgroundMask',[]);
p.parse(varargin{:});
q = p.Results();
cc = bwconncomp(bw);
bwe = [];
neededMany = false;
if neededMany
while cc.NumObjects == 1
se = strel('diamond',4); % structuring element
if isempty(bwe)
bwe = bw;
end
% erode a little bit more
bwe = imerode(bwe,se);
cc = bwconncomp(bwe);
disp('eroding a little bit');
end
end
% check the size of secon componet
indexSecondBest = 1;
for i=1:length(cc.PixelIdxList)
myArea(i) = length(cc.PixelIdxList{i});
end
[nestArea,orderedIndices] = sort(myArea,'descend');
indexSecondBest = orderedIndices(1);
mousePixelIndices = cc.PixelIdxList{indexSecondBest};
N = length(cc.PixelIdxList{indexSecondBest});
io = bw(cc.PixelIdxList{indexSecondBest});
bwmouse = false(size(bw));
bwmouse(mousePixelIndices) = true;
s = regionprops(bwmouse, 'centroid');
o.assignprop('Centroid',s.Centroid);
o.assignprop('Area',N);
%o.echo('mouse has %d pixels ',N);