Skip to content
Snippets Groups Projects
Commit d6b861bd authored by ac_fx's avatar ac_fx
Browse files

added segRefine

parent f82a58d5
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,6 @@
% otherwise this mostly does it...
function ctcEraseAll(strTarget)
ljsLog(sprintf('nodejs not found -- falling back to ctcEraseAll :: %s\n',strTarget),0);
[conn,CONSTANTS]=openDB(strTarget);
if isfield(CONSTANTS,'processInfo')
CONSTANTS=rmfield(CONSTANTS,'processInfo');
......
expName='2d_Fluo-N2DL-HeLa_training_02 ';
ljsctc=get_ljsctc(expName);
strDB=ljsctc.strDB;
gtPath=fullfile('/g/gRaw/ctc2021/', expName(1:end-3), expName(4:end-length('_training_0X')),[expName(end-1:end) '_GT/SEG/man_seg*.tif']);
flist=dir(gtPath);
[conn,CONSTANTS]=openDB(strDB);
dice=[];
for ff=1:length(flist)
imgt=imread(fullfile(flist(ff).folder,flist(ff).name));
tgt=regexp(flist(ff).name,'man_seg_(\d+).*.tif','tokens');
if isempty(tgt)
tgt=regexp(flist(ff).name,'man_seg(\d+).*.tif','tokens');
end
tgt=str2double(tgt{1}{1});
tgt=tgt+1; % zero based
zgt=regexp(flist(ff).name,'man_seg_(\d+)_(\d+).*.tif','tokens');
if isempty(zgt)
zgt=0;
else
zgt=str2double(zgt{1}{2});
end
cx=Read.getCellsTime(conn,tgt);
cx=Read.setCellsIdxPts(cx,CONSTANTS);
gtMatch=[];
cxgt=unique(imgt(:));
cxgt(cxgt==0)=[];
for i=1:length(cxgt)
idxGT = find(imgt==cxgt(i));
for j=1:length(cx)
nMatch=length(find(intersect(idxGT,cx(j).idxPts)));
gtMatch(i,j) = nMatch / max(length(idxGT),length(cx(j).idxPts));
end
end
[~,idxMatch]=max(gtMatch,[],2);
if length(unique(idxMatch))~=length(cxgt)
fprintf(2,'gt mismatch\n')
end
% draw the gt seg and our seg
im = leversc.loadImage(strDB,tgt);
imagesc(imgt);hold on;%colormap gray
imSeg=0*im;
for i=1:length(idxMatch)
imSeg(cx(idxMatch(i)).idxPts)=idxMatch(i);
% plot(cx(idxMatch(i)).surface(:,1),cx(idxMatch(i)).surface(:,2),'-r','linewidth',2);
end
alpha=[0.05:0.05:0.8];
for ia=1:length(alpha)
imRefine = segRefine.segRefine(imSeg,strDB,tgt,alpha(ia));
imzr=imRefine(:,:,zgt+1);
dice(ff,ia) = length(find(imgt & imzr)) / length(find(imgt | imzr))
end
bounds=bwboundaries(imzr);
for i=1:length(bounds)
plot(bounds{i}(:,2),bounds{i}(:,1),'-g')
end
end
close(conn)
\ No newline at end of file
function im=segRefine(im,strDB,t,alpha)
if ~exist('alpha','var')
alpha=0.25;
end
imRaw = leversc.loadImage(strDB,t);
[conn, CONSTANTS] = openDB(strDB);
cx=Read.getCellsTime(conn,t);
cx=Read.setCellsIdxPts(cx,CONSTANTS);
for n=1:length(cx)
bw1=logical(0*im);
idx = cx(n).idxPts;
mapID=im(idx);
mapID=mapID(1);
bw1(idx)=1;
level = alpha*graythresh(imRaw(idx));
idxReset = idx(find(imRaw(idx)<level));
im(idxReset)=0;
% clean up any holes...
bw1(idxReset)=0;
bw1 = imfill(bw1,'holes');
im(bw1)=mapID; % fill in holes...
% [r,c]=find(bw1);
% plot(c,r,'.g');
%
end
4;
......@@ -59,7 +59,7 @@ ljsctc.rawImagePath = ['/g/gRaw/ctc2021/' expName(1:end-3) '/' baseName(4:end) '
% some of the pixel physical sizes are encoded in the supplied tiff
% metadata incorrectly! so, the ones we use are set manually from the ctc
% website
ljsctc.strDB=fullfile(ljsctc.outPath,[expName '.LEVER']);
% the preferred way to get segparams. if you set segParams, we use that
datasetSpecifier=baseName(4:end);
[sp,pixelSize]=getSegParams(datasetSpecifier); % from the manual tuned cache
......
ROOT='/g/leverjs/ctc2021_manual/2d';
flist=dir(fullfile(ROOT,'*training*.LEVER'));
tblRes=table();
for ff=1:length(flist)
[~,expName]=fileparts(flist(ff).name)
expName=['2d_' expName];
ljsctc=get_ljsctc(expName);
res=goCTC(ljsctc);
tblRes=[tblRes;res]
end
......@@ -22,20 +22,22 @@
% expName='2d_DIC-C2DH-HeLa_training_01';ljsctc=get_ljsctc(expName);goCTC(ljsctc)
% expName='2d_Fluo-N2DL-HeLa_training_02';ljsctc=get_ljsctc(expName);goCTC(ljsctc)
% expName='3d_Fluo-N3DH-CHO_training_01';ljsctc=get_ljsctc(expName);goCTC(ljsctc)
function goCTC(ljsctc)
function ctcResults=goCTC(ljsctc)
ctcResults=[];
if ~exist(ljsctc.outPath,'dir')
mkdir(ljsctc.outPath);
end
if ~exist(ljsctc.strDB,'file')
% convert from ctc to lever format
h5File=ImportExport.ctc2lever(ljsctc.rawImagePath,ljsctc.outPath,ljsctc.expName);
if isempty(h5File)
fprintf(2,'leverjs CTC auto :: unable to import movie %s -- failing\n',ljsctc.rawImagePath);
return;
end
end
% set pixel physical size
strDB=strrep(h5File,'.h5','.LEVER');
[conn,CONSTANTS]=openDB(strDB);
[conn,CONSTANTS]=openDB(ljsctc.strDB);
if ~isempty(ljsctc.pixelPhysicalSize)
CONSTANTS.imageData.PixelPhysicalSize=ljsctc.pixelPhysicalSize;
Write.updateConstants(conn,CONSTANTS);
......@@ -45,7 +47,7 @@ if isempty(ljsctc.segParams)
% NOTE -- for best results check out getSegParams()
% alternatively, you can use Supervised.autoParam to try to find these for
% you. we usually do better with a touch of manual tuning.
Supervised.autoParam(strDB,ljsctc.gtConfig,ljsctc.gtTrainingPath);
Supervised.autoParam(ljsctc.strDB,ljsctc.gtConfig,ljsctc.gtTrainingPath);
else
Write.setSegParams(conn,ljsctc.segParams);
end
......@@ -53,15 +55,15 @@ end
% process the movie
% call the ctc version of erase all so we don't need to install node.js
% just for ctc use
LJSCTC.ctcEraseAll(strDB);
Batch.processMovie(strDB);
LJSCTC.ctcEraseAll(ljsctc.strDB);
Batch.processMovie(ljsctc.strDB);
if ~isempty(ljsctc.gtEvalPath)
% if you want an eval, config must be [] since CTC SEG/TRA/DET programs
% do not accept the config subfolder
ctcEval(strDB,[],ljsctc.outPath,ljsctc.gtEvalPath,ljsctc.gtConstraintPath);
ctcResults=ctcEval(ljsctc.strDB,[],ljsctc.outPath,ljsctc.gtEvalPath,ljsctc.gtConstraintPath);
else
ctcEval(strDB,ljsctc.gtConfig,ljsctc.outPath,ljsctc.gtEvalPath,ljsctc.gtConstraintPath);
ctcResults=ctcEval(ljsctc.strDB,ljsctc.gtConfig,ljsctc.outPath,ljsctc.gtEvalPath,ljsctc.gtConstraintPath);
end
close(conn);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment