Commit d1d95335 authored by Andrew Cohen's avatar Andrew Cohen

updated cytoToNuclearRatio to use ensemble radii

parent 1dfbe06b
......@@ -11,9 +11,11 @@ algs=Read.getAlgorithms(conn,'segment');
args=algs.params;
segParams=Segment.getDefaultSegParams();
segParams=Segment.getParams(segParams,args);
rgRadius=Segment.getEnsembleRadius(segParams.minimumRadius_um);
resolution_um=CONSTANTS.imageData.PixelPhysicalSize; % um per pixel
min_radius_pixels = segParams.minimumRadius_um(1) ./ resolution_um;
min_radius_pixels=min_radius_pixels(1);
min_radius_pixels = rgRadius ./ resolution_um(1);
% todo -- handle anistropy in 3d!
cmd=['select cellID from tblCells where time=' num2str(t)];
......@@ -24,6 +26,7 @@ im = MicroscopeData.Reader('imageData',CONSTANTS.imageData, 'chanList',...
params.channel,'timeRange',[t t], 'outType','single','prompt',false);
is3d=size(im,3)>1;
labelCells=0*im;
dInterior=labelCells;
for i=1:length(cellIDs)
if is3d
c=Read.getCell3D(conn,cellIDs(i));
......@@ -32,20 +35,28 @@ for i=1:length(cellIDs)
c=Read.getCell(conn,cellIDs(i));
idx=sub2ind(size(im),c.pts(:,2),c.pts(:,1));
end
bwInterior=logical(0*im);
bwInterior(idx)=1;
bwd=bwdist(~bwInterior);
dInterior=dInterior+bwd;
labelCells(idx)=c.cellID;
end
% find region surrounding segmentation
dInterior=bwdist(~labelCells);
labelInner=labelCells;
[dExterior,idxd]=bwdist(labelCells);
labelOuter=labelCells(idxd);
% should this be 5 or min_radius_pixels? outside region?
labelOuter(dExterior>5)=0;
% should this be 0, or min_radius_pixels? i.e. buffer between?
labelOuter(dInterior>=min_radius_pixels)=0;
labelInner(dInterior<min_radius_pixels)=0;
for i=1:length(rgRadius)
li=labelCells;
lo=labelCells(idxd);
radius=rgRadius(i);
lo(dExterior>radius)=0;
% should this be 0, or min_radius_pixels? i.e. buffer between?
lo(dInterior>=radius)=0;
li(dInterior<radius)=0;
labelOuter(:,:,:,i)=lo;
labelInner(:,:,:,i)=li;
end
for i=1:length(cellIDs)
if is3d
......@@ -53,8 +64,17 @@ for i=1:length(cellIDs)
else
c=Read.getCell(conn,cellIDs(i));
end
idxInner=find(labelInner==c.cellID);
idxOuter=find(labelOuter==c.cellID);
iRadius=c.segCC-floor(c.segCC);
if 0==iRadius
iRadius=1;
else
prec=ceil(log10(length(rgRadius)+1));% # of digits in the radius tag
iRadius=iRadius*10^prec;
iRadius=int32(iRadius);
end
idxInner=find(labelInner(:,:,:,iRadius)==c.cellID);
idxOuter=find(labelOuter(:,:,:,iRadius)==c.cellID);
ratio=getErkRatio(im,idxOuter,idxInner);
if isnan(ratio)
cmd=['delete from tblCellFeatures where cellID=' num2str(cellIDs(i))];
......
......@@ -18,24 +18,7 @@ if length(segParams.minimumRadius_um)~=3
return
end
rStart=segParams.minimumRadius_um(1);
rEnd=segParams.minimumRadius_um(3);
rStep=segParams.minimumRadius_um(2);
% rEnd should be larger radius than rStart
if rStart>rEnd
% swap them -- want to go from big to small...
temp=rStart;
rStart=rEnd;
rEnd=temp;
end
if rStep>0
rStep=-1*rStep;
end
rgRadius=[rEnd:rStep:rStart];
resolution_um=CONSTANTS.imageData.PixelPhysicalSize; % um per pixel
rgRadius=Segment.getEnsembleRadius(segParams.minimumRadius_um);
% ask for a parpool somewhere between 2 and nCores
p=getPool(segParams.nCores);
......
function rgRadius=getEnsembleRadius(minimumRadius_um)
if length(minimumRadius_um)~=3
rgRadius=minimumRadius_um(1);
return;
end
rStart=minimumRadius_um(1);
rEnd=minimumRadius_um(3);
rStep=minimumRadius_um(2);
% rEnd should be larger radius than rStart
if rStart>rEnd
% swap them -- want to go from big to small...
temp=rStart;
rStart=rEnd;
rEnd=temp;
end
if rStep>0
rStep=-1*rStep;
end
rgRadius=[rEnd:rStep:rStart];
% strDB='C:\z\leverjs\Olivier\set2 MR.LEVER'
% conn = database(strDB, '','', 'org.sqlite.JDBC', 'jdbc:sqlite:');
% CONSTANTS=Read.getConstants(conn)
algs=Read.getAlgorithms(conn,'segment');
args=algs.params;
segParams=Segment.getDefaultSegParams();
segParams=Segment.getParams(segParams,args);
t=1
params.channel=1
im = MicroscopeData.Reader('imageData',CONSTANTS.imageData, 'chanList',...
segParams.channels,'timeRange',[t t], 'outType','single','prompt',false);
[~,bw,~]=Segment.thresholdImages(im,[],segParams);
rgRadius=Segment.getEnsembleRadius(segParams.minimumRadius_um);
resolution_um=CONSTANTS.imageData.PixelPhysicalSize; % um per pixel
min_radius_pixels = rgRadius ./ resolution_um(1);
cmd=['select cellID from tblCells where time=' num2str(t)];
q=ljsFetch(conn,cmd);
cellIDs=cell2mat(q);
% labelled cell Image
labelCells=0*im;
dInterior=im*0;
for i=1:length(cellIDs)
c=Read.getCell(conn,cellIDs(i));
idx=sub2ind(size(im),c.pts(:,2),c.pts(:,1));
bwInterior=logical(0*im);
bwInterior(idx)=1;
bwd=bwdist(~bwInterior);
dInterior=dInterior+bwd;
labelCells(idx)=c.cellID;
end
% find region surrounding segmentation
[dExterior,idxd]=bwdist(labelCells);
for i=1:length(rgRadius)
li=labelCells;
lo=labelCells(idxd);
radius=rgRadius(i);
lo(dExterior>radius)=0;
% should this be 0, or min_radius_pixels? i.e. buffer between?
lo(dInterior>=radius)=0;
li(dInterior<radius)=0;
labelOuter(:,:,:,i)=lo;
labelInner(:,:,:,i)=li;
end
% draw it
clf;imagesc(im);hold on
for i=1:length(cellIDs)
c=Read.getCell(conn,cellIDs(i));
iRadius=c.segCC-floor(c.segCC);
if 0==iRadius
iRadius=1;
else
prec=ceil(log10(length(rgRadius)+1));% # of digits in the radius tag
iRadius=iRadius*10^prec;
iRadius=int32(iRadius);
end
% outer
cOuter=0*im;
idxOuter=find(labelOuter(:,:,:,iRadius)==c.cellID);
cOuter(idxOuter)=1;
bounds=bwboundaries(cOuter);
plot(bounds{1}(:,2),bounds{1}(:,1),'-r');
% inner label
cInner = logical(labelInner(:,:,:,iRadius)==c.cellID);
bounds=bwboundaries(cInner );
if isempty(bounds)
continue
end
plot(bounds{1}(:,2),bounds{1}(:,1),'-g');
ratio=length(idxOuter)/length(find(cInner));
text(c.centroid(1),c.centroid(2),num2str(ratio,2),'color','w');
drawnow
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