Commit 7c96ad7f authored by actb's avatar actb

phase segmentation

median mask on wellRadius==1, isPhase>1 for bright interior phase, isPhase<1 for dark interior phase
parent 3b825073
......@@ -701,6 +701,8 @@ function getLineageMap(rowsFamilies,rowsTracks,rowsPhenotypes)
// the phenotypes are indexed into constants.phenotypes (TBD). phenotype 0 is death.
for (i=0;i<rowsPhenotypes.length;i++) {
node=gLineageMap.get(rowsPhenotypes[i].trackID);
if (undefined==node)
continue;
if (undefined==node.phenotypes)
node.phenotypes=[];
if (undefined==node.phenotypes[rowsPhenotypes[i].time])
......
function [Cells,nestedCells]=ensembleSegment(conn, t,CONSTANTS,segParams)
function [Cells,nestedCells]=ensembleSegment(conn, t,CONSTANTS,segParams,medianMask)
ensembleDraw=false;
if segParams.draw==true
......@@ -37,7 +37,7 @@ parfor i=1:length(rgRadius)
% note as of matlab2019b, we pass [] for the conn (1st) argument as the
% param is unused as long as CONSTANTS are provided, and even passing
% it around in a parfor generates a warning
cx=Segment.FrameSegment_texture([],t,CONSTANTS,args);
cx=Segment.FrameSegment_texture([],t,CONSTANTS,args,medianMask);
ensembleCells{i}=cx;
end
segParams.draw=ensembleDraw;
......
function [Cells,nestedCells]=FrameSegment_texture(conn, t,CONSTANTS,args)
function [Cells,nestedCells]=FrameSegment_texture(conn, t,CONSTANTS,args, medianMask)
Cells=[];
nestedCells=[];
......@@ -6,17 +6,24 @@ if nargin<3
CONSTANTS=Read.getConstants(conn);
end
segParams=Segment.getDefaultSegParams();
if nargin==4
if exist('args','var')
segParams=Segment.getParams(segParams,args);
end
global DRAW
DRAW=segParams.draw;
if (1==segParams.wellRadius) && ~exist('medianMask','var')
medianMask=Segment.getMedianMask(conn,CONSTANTS,segParams);
else
if ~exist('medianMask','var')
medianMask=[];
end
end
% ensemble segmentations
if 3==length(segParams.minimumRadius_um)
segParams.ensemble_minimumRadius_um=segParams.minimumRadius_um;
[Cells,nestedCells]=Ensemble.ensembleSegment(conn, t,CONSTANTS,segParams);
[Cells,nestedCells]=Ensemble.ensembleSegment(conn, t,CONSTANTS,segParams,medianMask);
return;
end
bEnsemble=isfield(args,'ensemble_minimumRadius_um');
......@@ -30,13 +37,13 @@ min_radius_pixels = segParams.minimumRadius_um ./ resolution_um;
chan=segParams.channels(1); % default channel
[im,qLog,imLog]=Segment.getImages(CONSTANTS,t,chan,segParams);
[im,qLog,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;
end
for idChannel=2:length(segParams.channels)
[~,channel_qLog]=Segment.getImages(CONSTANTS,t,segParams.channels(idChannel),segParams);
[~,channel_qLog]=Segment.getImages(CONSTANTS,t,segParams.channels(idChannel),segParams,medianMask);
qLog=qLog+channel_qLog;
end
......@@ -89,9 +96,10 @@ end
min_radius_pixels,min_area_pixels);
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.wellRadius>0
if segParams.wellRadius>1
% mask all points at r>radius
center=size(im)/2;
rMask=ones(size(im));
......@@ -102,7 +110,7 @@ if segParams.wellRadius>0
bw(~bwMask)=0;
end
if ~segParams.bCytoplasmic
if ~segParams.bCytoplasmic
bw=removeOuterRadius(bw,CONSTANTS,min_radius_pixels);
end
......@@ -197,6 +205,14 @@ for n=1:num
end
Cells=[Cells newCell];
end
if segParams.isPhase>0
fgRatio=0.95; % intensity model needed to keep phase parasites down
elseif segParams.isPhase<0
fgRatio=0.05; % less intensity driven
else
fgRatio=0.05; % less intensity driven
end
% set features for parasite test
for i=1:length(Cells)
if is3D(bwIntensity)
......@@ -206,14 +222,17 @@ for i=1:length(Cells)
end
Cells(i).pfg=length(find(bwIntensity(idx)))/size(Cells(i).pts,1);
% less then 5% foreground are parasites
if DRAW && Cells(i).pfg<0.05
plot(Cells(i).surface(:,1),Cells(i).surface(:,2),'color','k','linewidth',3);
if DRAW
% 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
end
end
if ~isempty(Cells)
% if 5% or less of pixels are foreground, delete
idxParasite=find( [Cells.pfg]<0.05 );
idxParasite=find( [Cells.pfg]<fgRatio );
Cells(idxParasite)=[];
end
......
function [im,qLog,imLogRaw]=getImages(CONSTANTS,t,channel,segParams)
function [im,qLog,imLogRaw]=getImages(CONSTANTS,t,channel,segParams,medianMask)
if ~exist('bFilter','var')
bFilter=false;
......@@ -8,7 +8,13 @@ resolution_um=CONSTANTS.imageData.PixelPhysicalSize; % um per pixel
min_radius_pixels = segParams.minimumRadius_um ./ resolution_um;
global USE_CUDA
im = MicroscopeData.Reader('imageData',CONSTANTS.imageData, 'chanList',channel,'timeRange',[t t], 'outType','single','prompt',false);
if 1==segParams.wellRadius && exist('medianMask','var') && ~isempty(medianMask)
im=im-medianMask;
im=mat2gray(im);
end
if isempty(im)
qLog=[];
imLogRaw=[];
......@@ -52,17 +58,20 @@ else
imLog=imfilter(im,h,'replicate');
end
end
imLogRaw=imLog;
imLog=mat2gray(imLog);
lm=multithresh(imLog,15);
qLog=imquantize(imLog,lm);
if segParams.isPhase
if segParams.isPhase<0
% dark center phase -- need log to be small inside, large outside, so
% reverse
qLog=max(qLog(:))+1-qLog;
end
function im=denoise(im,segParams)
if false==segParams.denoise
im=mat2gray(im);
return
......
function medianMask=getMedianMask(conn,CONSTANTS,segParams)
global medianMask
global datasetName
if isempty(datasetName) || isempty(medianMask) || ...
~strcmp(datasetName,fullfile(CONSTANTS.imageData.imageDir,CONSTANTS.imageData.DatasetName))
imMask = MicroscopeData.Reader('imageData',CONSTANTS.imageData, 'chanList',segParams.channels(1),'timeRange',[1 CONSTANTS.imageData.NumberOfFrames], 'outType','single','prompt',false);
medianMask=median(imMask,5);
datasetName=fullfile(CONSTANTS.imageData.imageDir,CONSTANTS.imageData.DatasetName);
end
......@@ -72,21 +72,14 @@ else
end
function bwIntensity=thresholdPhaseIntensity(im,alpha,min_radius_pixels,min_area_pixels)
% dark centers
lm=alpha*multithresh(im,16);
bwIntensity=imquantize(im,lm);
bwIntensity=logical(bwIntensity<=2);
% bright blobs
lm=alpha*multithresh(im,3);
bwBright=imquantize(im,lm);
se=strel('disk',ceil(min_radius_pixels/2));
bwBright=logical(bwBright>=3);
bwBright=imerode(bwBright,se); % erode? or open?
bwIntensity=bwIntensity|bwBright;
%clean up and done
qThresh=prctile(im(:),[1,99]);
% use dark boundaries. seems to work for both dark and bright interior...
bwIntensity=logical(im<qThresh(1));
bwIntensity=bwIntensity|imfill(bwIntensity,'holes');
% bwIntensity=bwareaopen(bwIntensity,round(min_area_pixels/4));
se=strel('disk',ceil(min_radius_pixels/2));
bwIntensity=imopen(bwIntensity,se);
4;
function b3D=is3D(im)
......
function [conn,CONSTANTS]=openDB(strDB)
function [conn,CONSTANTS,segParams]=openDB(strDB)
conn = database(strDB, '','', 'org.sqlite.JDBC', 'jdbc:sqlite:');
CONSTANTS=Read.getConstants(conn);
\ No newline at end of file
CONSTANTS=Read.getConstants(conn);
segParams=Read.getSegmentationParams(conn);
\ No newline at end of file
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