Commit c82440fa authored by actb's avatar actb

reworked thresholdImages

parent 6d9ba833
......@@ -12,7 +12,6 @@ else
end
if is3D(im)
nsz=2*floor(size(im)/16)+1;
T=adaptthresh(imLog,0.5,'NeighborhoodSize',nsz,'statistic','gaussian');
bwLog=imbinarize(imLog,T);
......@@ -32,37 +31,9 @@ bwLog=imbinarize(imLog,T);
bwLog=bwareaopen(bwLog,4*min_area_pixels);
if segParams.isPhase
se=strel('disk',1);
se2=strel('disk',ceil(min_radius_pixels/2));
if segParams.isPhase>0
T=adaptthresh(im,sensitivity,'foregroundpolarity','dark','statistic','gaussian');
else
T=adaptthresh(im,sensitivity,'foregroundpolarity','bright','statistic','gaussian');
end
bw=imbinarize(im,T);
if segParams.isPhase>0
bw=imcomplement(bw);
end
bw=imclose(bw,se2);
bw=imfill(bw,'holes');
if true==segParams.wellRadius
bwMask=imbinarize(medianMask,adaptthresh(medianMask,'statistic','gaussian'));
bw=bw&~bwMask;
bwh=imfill(bw,'holes');
nrep=0;
% if the mask forms a solid circle, the hole fill on bw will fill
% in the whole foreground. dilate mask until that doesn't happen...
while nrep<5 && length(find(bwh&~bw))/length(bw(:))>0.25
nrep=nrep+1;
bwMask=imdilate(bwMask,se);
bw=bw&~bwMask;
end
bw=imfill(bw,'holes');
bw=imopen(bw,se);
bwLog=bwLog&~bwMask;
bwLog=imclose(bwLog,se2);
end
bw=imfill(bw,'holes');
[bw,bwLog]=phaseThreshold(im,bwLog,min_radius_pixels,segParams,...
sensitivity,medianMask);
return;
else
% use 2x the default nhood size
T=adaptthresh(im,sensitivity,'NeighborhoodSize',4*floor(size(im)/16)+1,'statistic','gaussian');
......@@ -71,5 +42,43 @@ end
bw=bwareaopen(bw,min_area_pixels);
4;
function [bw,bwLog]=phaseThreshold(im,bwLog,min_radius_pixels,segParams,...
sensitivity,medianMask)
se=strel('disk',1);
se2=strel('disk',ceil(min_radius_pixels/2));
if segParams.isPhase>0
T=adaptthresh(im,sensitivity,'foregroundpolarity','dark','statistic','gaussian');
else
T=adaptthresh(im,sensitivity,'foregroundpolarity','bright','statistic','gaussian');
end
bw=imbinarize(im,T);
if segParams.isPhase>0
bw=imcomplement(bw);
end
bw=imclose(bw,se2);
bw=imfill(bw,'holes');
if true==segParams.wellRadius
[bw,bwLog]=thesholdMask(medianMask,bw,bwLog,se,se2);
end
function [bw,bwLog]=thesholdMask(medianMask,bw,bwLog,se,se2)
bwMask=imbinarize(medianMask,adaptthresh(medianMask,'statistic','gaussian'));
bw=bw&~bwMask;
bwh=imfill(bw,'holes');
nrep=0;
% if the mask forms a solid circle, the hole fill on bw will fill
% in the whole foreground. dilate mask until that doesn't happen...
while nrep<5 && length(find(bwh&~bw))/length(bw(:))>0.25
nrep=nrep+1;
bwMask=imdilate(bwMask,se);
bw=bw&~bwMask;
end
bw=imfill(bw,'holes');
bw=imopen(bw,se);
bwLog=bwLog&~bwMask;
bwLog=imclose(bwLog,se2);
No preview for this file type
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment