Commit d66867ea authored by actb's avatar actb

code refactoring, size threshold changes

parent f8bfb8cf
......@@ -39,7 +39,7 @@ resolution_um=CONSTANTS.imageData.PixelPhysicalSize; % um per pixel
min_radius_pixels = segParams.minimumRadius_um ./ resolution_um;
chan=segParams.channels(1); % default channel
[im,qLog,bwLog]=Segment.getImages(CONSTANTS,t,chan,segParams,medianMask);
[im,imLog]=Segment.getImages(CONSTANTS,t,chan,segParams,medianMask);
if all(im(:)==0)
ljsLog(sprintf('frameSegment_texture: empty image at time=%d -- skipping\n',t));
return;
......@@ -67,10 +67,8 @@ if DRAW
drawnow
end
T=adaptthresh(im,0.5,'NeighborhoodSize',4*floor(size(im)/16)+1,'statistic','gaussian');
% T=adaptthresh(im,0.5,'NeighborhoodSize',2*floor(size(im)/16)+1,'statistic','gaussian');
bw=imbinarize(im,T);
bw=bwareaopen(bw,min_area_pixels);
[bw,bwLog]=Segment.thresholdImages(im,imLog,segParams, min_radius_pixels,min_area_pixels,...
medianMask);
% bw2 is all the pixels in our foreground image. after we mask, some
% of those pixels will be discarded in resolving the underlying cells.
......@@ -109,7 +107,7 @@ end
% final CC pass
for n=1:num
idx=find(L==n);
if length(idx)<4*min_area_pixels
if length(idx)<2*min_area_pixels
continue
end
newCell=Segment.FrameSegment_texture_create(idx,size(bw),chan,t);
......
function [im,qLog,bwLog]=getImages(CONSTANTS,t,channel,segParams,medianMask)
function [im,imLog]=getImages(CONSTANTS,t,channel,segParams,medianMask)
if ~exist('bFilter','var')
bFilter=false;
......@@ -59,23 +59,6 @@ else
end
end
imLogRaw=imLog;
%
lm=multithresh(imLog,15);
qLog=imquantize(imLog,lm);
min_radius_pixels=min_radius_pixels(1);
min_area_pixels = min_radius_pixels^2 * pi;
min_area_pixels = max(1,round(min_area_pixels));
imLog(imLog<median(imLog(:)))=0;
imLog=mat2gray(imLog);
% bwLog=imbinarize(imLog,adaptthresh(imLog,0.5,'statistic','gaussian'));
T=adaptthresh(imLog,0.5,'NeighborhoodSize',4*floor(size(im)/16)+1,'statistic','gaussian');
bwLog=imbinarize(imLog,T);
bwLog=bwareaopen(bwLog,4*min_area_pixels);
% se=strel('disk',ceil(1.5*min_radius_pixels(1)));
% bwLog=imclose(bwLog,se);
4;
function im=denoise(im,segParams)
......
......@@ -4,13 +4,12 @@ function bw=segReduce(bw,bwLog,min_area_pixels,min_radius_pixels)
[origL,num]=bwlabeln(bw);
bwDilate=bwLog;
qL=[];
qL=origL;
% nDimension is 2 for 2-D, 3 for 3-D used for concat'ing
nDimension=length(size(bw));
minKernelArea=10; %floor(min_area_pixels/4)+1;
se=strel('disk',3);
for nDilate=1:2*min_radius_pixels
bwDilate=bwmorph(bwDilate,'dilate');
kernels=bwfill(bwDilate,'holes')&~bwDilate;
kernels=kernels&bw;
kernels=bwareaopen(kernels,minKernelArea);
......@@ -19,6 +18,7 @@ for nDilate=1:2*min_radius_pixels
end
L=bwlabeln(kernels);
qL=cat(nDimension+1,qL,L);
bwDilate=imdilate(bwDilate,se);
end
if nDimension==2
......
function [bw]=thresholdImages(im,imTexture,segParams,...
min_radius_pixels,min_area_pixels,medianMask)
function [bw,bwLog]=thresholdImagess(im,imLog,segParams, min_radius_pixels,min_area_pixels,...
medianMask)
bw=[];
nLevels=-1;
bwIntensity=thresholdIntensity(im,segParams,min_radius_pixels,...
min_area_pixels,medianMask);
% if no imTexture provided, just return bwIntensity
if isempty(imTexture)
return;
end
alpha=segParams.alpha(1);
T=adaptthresh(imLog,0.5,'NeighborhoodSize',4*floor(size(im)/16)+1,'statistic','gaussian');
bwLog=imbinarize(imLog,T);
bwLog=bwareaopen(bwLog,4*min_area_pixels);
if segParams.isPhase
bw=imbinarize(imTexture,adaptthresh(imTexture,0.5));
if medianMask
se=strel('disk',ceil(min_radius_pixels));
bwMask=imbinarize(medianMask,adaptthresh(medianMask));
bwMask=imdilate(bwMask,se);
se=strel('disk',1);
se2=strel('disk',ceil(min_radius_pixels/2));
T=adaptthresh(im,0.5,'foregroundpolarity','dark','statistic','gaussian');
bw=imbinarize(im,T);
bw=imcomplement(bw);
bw=imclose(bw,se2);
bw=imfill(bw,'holes');
if segParams.wellRadius
bwMask=imbinarize(medianMask,adaptthresh(medianMask,'statistic','gaussian'));
bwMask=imdilate(bwMask,se2);
bw=bw&~bwMask;
bwLog=bwLog&~bwMask;
end
se=strel('disk',ceil(min_radius_pixels/2));
bw=imopen(bw,se);
bw=imclose(bw,se);
else
if segParams.brightLevels>=0
n0=segParams.brightLevels;
else
n0=1;
end
if is3D(im)
ratioThresh=30;
else
ratioThresh=10;
end
for nLevels=n0:20
lm=alpha*multithresh(imTexture,nLevels);
q=imquantize(imTexture,lm);
bw=logical(q>nLevels);
if length(find(bw))/length(find(bwIntensity))<ratioThresh
break;
end
end
% use 2x the default nhood size
T=adaptthresh(im,0.5,'NeighborhoodSize',4*floor(size(im)/16)+1,'statistic','gaussian');
bw=imbinarize(im,T);
end
bw=bwareaopen(bw,min_area_pixels);
function bwIntensity=thresholdIntensity(im,segParams,min_radius_pixels,...
min_area_pixels,medianMask)
if length(segParams.alpha)>1
alpha=segParams.alpha(2);
else
alpha=segParams.alpha;
end
% first, threshold bwIntensity
if segParams.brightLevels>=0
nLevels=segParams.brightLevels;
else
nLevels=1;
end
if segParams.isPhase
bwIntensity=thresholdPhaseIntensity(im,alpha,min_radius_pixels,...
min_area_pixels,medianMask);
return;
end
% else not phase
if alpha>1 && alpha==round(alpha)
lm=multithresh(im,alpha);
bwIntensity=imquantize(im,lm);
bwIntensity=logical(bwIntensity>1);
else
lm=alpha*multithresh(im,nLevels);
bwIntensity=imquantize(im,lm);
bwIntensity=logical(bwIntensity>nLevels);
end
function bwIntensity=thresholdPhaseIntensity(im,alpha,min_radius_pixels,...
min_area_pixels,medianMask)
bwIntensity=imbinarize(im,adaptthresh(im));
bwIntensity=bwIntensity|imfill(bwIntensity,'holes');
se=strel('disk',ceil(min_radius_pixels/4));
bwIntensity=imopen(bwIntensity,se);
if medianMask
bwMask=imbinarize(medianMask,adaptthresh(medianMask));
se=strel('disk',ceil(min_radius_pixels));
bwMask=imdilate(bwMask,se);
bwIntensity=bwIntensity&~bwMask;
end
4;
function b3D=is3D(im)
if length(size(im))==3
b3D=true;
else
b3D=false;
end
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