Commit fd5147f6 authored by ac_22's avatar ac_22

use adaptthresh/imbinarize for phase images

parent d79f7ab8
......@@ -88,16 +88,18 @@ if DRAW
end
% hold off;imagesc([imc imq]);hold on
hold off;imagesc([imc]);colormap(gray);brighten(0.5);hold on
hold off;imagesc([imc]);colormap(gray);axis image;brighten(0.5);hold on
drawnow
end
[bw,bwIntensity,nLevels]=Segment.thresholdImages(im,imTexture,segParams,...
min_radius_pixels,min_area_pixels);
min_radius_pixels,min_area_pixels,medianMask);
sz=sprintf('frameSegmentTexture: min_radius_pixels=%s nLevels detected at %d\n',mat2str(min_radius_pixels,3),nLevels);
ljsLog(sz,3);
bw=bw|imfill(bw,'holes');
if ~segParams.isPhase
bw=bw|imfill(bw,'holes');
end
if segParams.wellRadius>1
% mask all points at r>radius
......@@ -199,7 +201,7 @@ for n=1:num
nc=newCell(i);
cmap=hsv(255);
cidx=1+round(rand()*254);
plot(nc.surface(:,1),nc.surface(:,2),'color',cmap(cidx,:),'linewidth',2);
plot(nc.surface(:,1),nc.surface(:,2),'color',cmap(cidx,:),'linewidth',1);
% drawnow
end
end
......@@ -227,7 +229,7 @@ for i=1:length(Cells)
Cells(i).pfg=length(find(bwIntensity(idx)))/size(Cells(i).pts,1);
% less then 5% foreground are parasites
if DRAW
text(Cells(i).centroid(1),Cells(i).centroid(2),num2str(Cells(i).pfg,2),'color','w');
% text(Cells(i).centroid(1),Cells(i).centroid(2),num2str(Cells(i).pfg,2),'color','w');
if Cells(i).pfg<fgRatio
plot(Cells(i).surface(:,1),Cells(i).surface(:,2),'color','k','linewidth',3);
end
......
function [bw,bwIntensity,nLevels]=thresholdImages(im,imTexture,segParams,...
min_radius_pixels,min_area_pixels)
min_radius_pixels,min_area_pixels,medianMask)
bw=[];
nLevels=-1;
bwIntensity=thresholdIntensity(im,segParams,min_radius_pixels,min_area_pixels);
bwIntensity=thresholdIntensity(im,segParams,min_radius_pixels,...
min_area_pixels,medianMask);
% if no imTexture provided, just return bwIntensity
if isempty(imTexture)
return;
......@@ -14,14 +15,17 @@ end
alpha=segParams.alpha(1);
if segParams.isPhase
if segParams.brightLevels>=0
nLevels=segParams.brightLevels;
else
nLevels=2;
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);
bw=bw&~bwMask;
end
lm=alpha*multithresh(imTexture,nLevels);
q=imquantize(imTexture,lm);
bw=logical(q>nLevels);
se=strel('disk',ceil(min_radius_pixels/2));
bw=imopen(bw,se);
bw=imclose(bw,se);
else
if segParams.brightLevels>=0
n0=segParams.brightLevels;
......@@ -43,7 +47,8 @@ else
end
end
function bwIntensity=thresholdIntensity(im,segParams,min_radius_pixels,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
......@@ -57,7 +62,8 @@ else
end
if segParams.isPhase
bwIntensity=thresholdPhaseIntensity(im,alpha,min_radius_pixels,min_area_pixels);
bwIntensity=thresholdPhaseIntensity(im,alpha,min_radius_pixels,...
min_area_pixels,medianMask);
return;
end
% else not phase
......@@ -71,16 +77,19 @@ else
bwIntensity=logical(bwIntensity>nLevels);
end
function bwIntensity=thresholdPhaseIntensity(im,alpha,min_radius_pixels,min_area_pixels)
% qThresh=prctile(im(:),[1,99]);
qThresh=multithresh(im,2);
% use dark boundaries. seems to work for both dark and bright interior...
qThresh=multithresh(im,2);
bwIntensity=logical(im<qThresh(1));
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)
......
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