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 137 lines (96 sloc) 2.12 KB
%
% binarization
%
function [bw,u,uceroded] = blobTrackBinarize(g2,i,maskInside,q);
background = q.background;
useEnhancement = q.useEnhancement;
% i = 5600;
try
u= g2.read(i);
catch
disp(sprintf('Skipping frame %d for reading problems.',i));
% sometimes the video reader marks frames tha do not actually exist!
bw = [];
u = [];
return
end
u = rgb2gray(u);
if ~isempty(background)
ub = double(u)-background;
else
ub = u;
end
ubReversed = imcomplement((ub));
if useEnhancement
ucg = imadjust(ubReversed);
else
ucg = ubReversed;
end
% smarts
if ~isempty(maskInside)
% ucg = ucg./max(ucg(:));
ucg = mbimg.mask.applyMask(ucg,maskInside);
end
useSingleErosion = true;
if useSingleErosion
% ucgi = (imerode(ucg,strel('diamond',20)));
% ucgi = ucgi./max(ucgi(:));
%
% t = graythresh(ucgi);
% t = 0.8;
%
uceroded = imerode(ucg,strel('diamond',q.erosion));
%bw = im2bw(mbimg.binarize(mbimg.normalize(uceroded),q.binarizationThreshold));
bw = mbimg.binarize(mbimg.normalize(uceroded),q.binarizationThreshold);
return
end
if useEnhancement
% direct
ucgi = imerode(ucg,strel('diamond',5));
t = graythresh(ucgi);
bw = im2bw(ucgi,t);
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% elliminates ears
%
elliminateEars = true;
if elliminateEars
sec = strel('diamond',9); % structuring element
uh = imclose(ucg,sec);
else
uh = ucg;
end
%
% erode tails
%
see = strel('diamond',12); % structuring element
ue = imerode(uh,see);
ue = mat2gray(ue);
% gets blobs
%t = graythresh(ue);
%ue = mat2gray(ucg);
try
thresh = multithresh(ue,3);
catch
thresh = multithresh(ue,2);
end
t = thresh(end);
%ue = mbimg.mask.applyMask(ue,maskInside);
bwn = im2bw(ue,t);
%
%
% erode tails
%
%
seo = strel('diamond',12); % structuring element
bw = imopen(bwn,seo);
if length(find(bw))<30
bw = bwn;
%error('Norl! the mouse disapeared!');
end
if length(find(bw))<30
%error('Norl! the mouse disapeared!');
bw = [];
end