Commit 39eb4a3f authored by actb's avatar actb

segreduce on thresholded bwlog

parent 671ca2b7
......@@ -64,28 +64,16 @@ if DRAW
end
bw=imbinarize(im,adaptthresh(im,0.5,'statistic','gaussian'));
if segParams.wellRadius>1
% mask all points at r>radius
center=size(im)/2;
rMask=ones(size(im));
[r,c]=find(rMask);
radius= sqrt( (r-center(1)).^2+(c-center(2)).^2 );
rMask=reshape(radius,size(im));
bwMask=logical(rMask<segParams.wellRadius);
bw(~bwMask)=0;
end
%
% if ~segParams.bCytoplasmic
% bw=removeOuterRadius(bw,CONSTANTS,min_radius_pixels);
% end
% bw2 is all the pixels in our foreground image. after we mask, some
% of those pixels will be discarded in resolving the underlying cells.
% allocateShake (below) assigns each discarded pixel to it's closest
% touching segmentation using a morphological region fill
bw=bwareaopen(bw,min_area_pixels);
bw2=bw;
bw(bwLog)=0;
bw=Segment.segReduce(bw,bwLog,min_area_pixels,min_radius_pixels);
if ~segParams.isPhase
bw=bw|imfill(bw,'holes');
end
......
......@@ -69,8 +69,9 @@ imLog(imLog<median(imLog(:)))=0;
imLog=mat2gray(imLog);
bwLog=imbinarize(imLog,adaptthresh(imLog,0.5,'statistic','gaussian'));
bwLog=bwareaopen(bwLog,2*min_area_pixels);
se=strel('disk',ceil(min_radius_pixels(1)));
bwLog=imclose(bwLog,se);
% se=strel('disk',ceil(1.5*min_radius_pixels(1)));
% bwLog=imclose(bwLog,se);
4;
function im=denoise(im,segParams)
......
function bw=segReduce(bw,qLog,min_area_pixels,min_radius_pixels)
function bw=segReduce(bw,bwLog,min_area_pixels,min_radius_pixels)
[origL,num]=bwlabeln(bw);
% firstDiscovery is the gradient level at which a given connected component
% first finds a cell. We use this to constrain so that a very strong group
% of cells doesn't 'spawn' artifact cells from their intersection at lower
% gradient levels
firstDiscovery=zeros(1,num);
qMax=max(qLog(:));
% qMax=12;
bwErode=bw;
bwDilate=bwLog;
qL=[];
% nDimension is 2 for 2-D, 3 for 3-D used for concat'ing
nDimension=length(size(bw));
for iq=qMax:-1:1
bwErode(qLog>=iq)=0;
ccErode=bwconncomp(bwErode);
cellSizes=cellfun(@length,ccErode.PixelIdxList);
% if is3D(bw)
% check that each CC achieves a distance of at least 0.5 * min_radius
% maybe bad idea -- holes in bwErode make distance unreliable?
% bwd=bwdist(~bwErode);
% rpdist=cellfun(@(x) max(bwd(x)),ccErode.PixelIdxList);
% idx=cellSizes<min_area_pixels | rpdist<1.5*min(min_radius_pixels);
% else
% rp=regionprops(ccErode,'MinorAxisLength');
% idx=cellSizes<min_area_pixels | [rp.MinorAxisLength]<2*min_radius_pixels;
% end
idx=cellSizes<min_area_pixels;
resetPixels=cell2mat(ccErode.PixelIdxList(idx)');
bwErode(resetPixels)=0;
if isempty(find(bwErode, 1))
for nDilate=1:2*min_radius_pixels
bwDilate=bwmorph(bwDilate,'dilate');
kernels=bwfill(bwDilate,'holes')&~bwDilate;
kernels=bwareaopen(kernels,min_area_pixels);
if isempty(find(kernels, 1))
break;
end
L=bwlabeln(bwErode);
L=bwlabeln(kernels);
qL=cat(nDimension+1,qL,L);
end
......@@ -64,21 +45,8 @@ for iq=niq:-1:1
continue
end
idx=find(n==newL);
discoverL=unique(origL(idx));
discoverL(0==discoverL)=[];
if ~isempty(discoverL)
qDiscover=min(firstDiscovery(discoverL));
% if qDiscover-iq>2
% continue
% end
end
nc=numComponents(L,idx);
if nc<=1
if 0==nc
firstDiscovery(discoverL)=iq;
end
% keep this component from newL -- there are 0 or 1 children
bw(idx)=1;
else
......
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