Automatic Nuclei Count tif stacks
I am using this borrowed code to automatically count DAPI stained nuclei:
Hs.dirPath = pwd;
[Hs.dataFiles,Hs.dataNums] = getDataFiles(Hs.dirPath);
[Hs.foundChannels,Hs.fileNums,Hs.imgExts] = getImageFiles(Hs.dirPath);
for i = 1:length(Hs.fileNums)
Hs.fileNum = Hs.fileNums(i);
fileName = [‘dapi’ sprintf(‘%03d’,Hs.fileNum) ‘.tif’];
Hs.DI = readmm(fileName);
Hs.DI = Hs.DI.imagedata;
Hs.DI = scale(max(Hs.DI(:,:,round(linspace(10,size(Hs.DI,10),50))),[],3));
binDapi = Hs.DI>adaptthresh(Hs.DI);
masktmp = imclearborder(binDapi | ~Hs.DI);
masktmp = bwareaopen(masktmp,50);
if any(masktmp(:))
binDapi = masktmp;
end
L = bwlabel(binDapi);
numObjects = max(L,[],1:2);
Hs.currObjs = [];
Hs.allMasks = [];
for j = 1:numObjects
fnumStr = sprintf(‘%03d’,Hs.fileNum);
objMask = L == j;
newObj = improc2.buildImageObject(objMask, fnumStr, Hs.dirPath);
Hs.currObjs = [Hs.currObjs, newObj];
Hs.allMasks = cat(3,Hs.allMasks,objMask);
end
objects = Hs.currObjs;
save(sprintf(‘%s%sdata%03d.mat’,Hs.dirPath,filesep,Hs.fileNum),’objects’);
[Hs.dataFiles,Hs.dataNums] = getDataFiles(Hs.dirPath);
clear objects;
Hs.currObjs = [];
end
It ends up fusing nuclei that are on different planes. In the image shown here (Matlab Output on the left and original on the right)there should be 14 nuclei but 1 and 6, 2 and 5 and 3 and 7 end up being counted as the same.
I have tried changing the threshold etc. but it does not help with the stacks.
Any suggestions to modify the code? Thanks.I am using this borrowed code to automatically count DAPI stained nuclei:
Hs.dirPath = pwd;
[Hs.dataFiles,Hs.dataNums] = getDataFiles(Hs.dirPath);
[Hs.foundChannels,Hs.fileNums,Hs.imgExts] = getImageFiles(Hs.dirPath);
for i = 1:length(Hs.fileNums)
Hs.fileNum = Hs.fileNums(i);
fileName = [‘dapi’ sprintf(‘%03d’,Hs.fileNum) ‘.tif’];
Hs.DI = readmm(fileName);
Hs.DI = Hs.DI.imagedata;
Hs.DI = scale(max(Hs.DI(:,:,round(linspace(10,size(Hs.DI,10),50))),[],3));
binDapi = Hs.DI>adaptthresh(Hs.DI);
masktmp = imclearborder(binDapi | ~Hs.DI);
masktmp = bwareaopen(masktmp,50);
if any(masktmp(:))
binDapi = masktmp;
end
L = bwlabel(binDapi);
numObjects = max(L,[],1:2);
Hs.currObjs = [];
Hs.allMasks = [];
for j = 1:numObjects
fnumStr = sprintf(‘%03d’,Hs.fileNum);
objMask = L == j;
newObj = improc2.buildImageObject(objMask, fnumStr, Hs.dirPath);
Hs.currObjs = [Hs.currObjs, newObj];
Hs.allMasks = cat(3,Hs.allMasks,objMask);
end
objects = Hs.currObjs;
save(sprintf(‘%s%sdata%03d.mat’,Hs.dirPath,filesep,Hs.fileNum),’objects’);
[Hs.dataFiles,Hs.dataNums] = getDataFiles(Hs.dirPath);
clear objects;
Hs.currObjs = [];
end
It ends up fusing nuclei that are on different planes. In the image shown here (Matlab Output on the left and original on the right)there should be 14 nuclei but 1 and 6, 2 and 5 and 3 and 7 end up being counted as the same.
I have tried changing the threshold etc. but it does not help with the stacks.
Any suggestions to modify the code? Thanks. I am using this borrowed code to automatically count DAPI stained nuclei:
Hs.dirPath = pwd;
[Hs.dataFiles,Hs.dataNums] = getDataFiles(Hs.dirPath);
[Hs.foundChannels,Hs.fileNums,Hs.imgExts] = getImageFiles(Hs.dirPath);
for i = 1:length(Hs.fileNums)
Hs.fileNum = Hs.fileNums(i);
fileName = [‘dapi’ sprintf(‘%03d’,Hs.fileNum) ‘.tif’];
Hs.DI = readmm(fileName);
Hs.DI = Hs.DI.imagedata;
Hs.DI = scale(max(Hs.DI(:,:,round(linspace(10,size(Hs.DI,10),50))),[],3));
binDapi = Hs.DI>adaptthresh(Hs.DI);
masktmp = imclearborder(binDapi | ~Hs.DI);
masktmp = bwareaopen(masktmp,50);
if any(masktmp(:))
binDapi = masktmp;
end
L = bwlabel(binDapi);
numObjects = max(L,[],1:2);
Hs.currObjs = [];
Hs.allMasks = [];
for j = 1:numObjects
fnumStr = sprintf(‘%03d’,Hs.fileNum);
objMask = L == j;
newObj = improc2.buildImageObject(objMask, fnumStr, Hs.dirPath);
Hs.currObjs = [Hs.currObjs, newObj];
Hs.allMasks = cat(3,Hs.allMasks,objMask);
end
objects = Hs.currObjs;
save(sprintf(‘%s%sdata%03d.mat’,Hs.dirPath,filesep,Hs.fileNum),’objects’);
[Hs.dataFiles,Hs.dataNums] = getDataFiles(Hs.dirPath);
clear objects;
Hs.currObjs = [];
end
It ends up fusing nuclei that are on different planes. In the image shown here (Matlab Output on the left and original on the right)there should be 14 nuclei but 1 and 6, 2 and 5 and 3 and 7 end up being counted as the same.
I have tried changing the threshold etc. but it does not help with the stacks.
Any suggestions to modify the code? Thanks. image processing, image analysis MATLAB Answers — New Questions