Counting cells in a sliding window

2 vues (au cours des 30 derniers jours)
tethys
tethys le 31 Mar 2016
I have a series of binary images (already background corrected + filtered for identification of cells), each of them consisting of circular cells. I would like to count the number of cells in a sliding 128 x 128 pixels in each image and do this for all images. As a result, I would like to plot (pcolor) cells distribution in each image. I would be glad if you could direct me.
base_dir = 'K:\images\';
cd(base_dir);
imagefiles = dir('*.jpg');
nfiles = length(imagefiles);
for ii=1:nfiles
currentfilename = imagefiles(ii).name;
currentimage = imread(currentfilename);
I(:,:, ii) = currentimage;
end
[M,N,~] = size(I);
rr = 128; cc = 128;
xx = 10; yy = 10; % if overlapping needed
numBlocksYY = numel(1:rr-xx:(M-(rr-1)));
numBlocksXX = numel(1:cc-yy:(N-(cc-1)));
counter = 1;
for ii=1:rr-xx:(M-(rr-1))
for jj=1:cc-yy:(N-(cc-1))
fprintf('[%d:%d, %d:%d]\n',ii,ii+rr-1,jj,jj+cc-1);
NN{counter} = bwconncomp(I(ii:(ii+rr-1), jj:(jj+cc-1), : ));
counter = counter + 1;
end
end
Here is one image:
  2 commentaires
Image Analyst
Image Analyst le 31 Mar 2016
tethys
tethys le 1 Avr 2016
Thank you for your suggestion Image Analyst. I have uploaded one example.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 1 Avr 2016
Modifié(e) : Image Analyst le 1 Avr 2016
Call bwulterode() to erode each blob down to a single point. Then use conv2() to count them in an overlapping window:
binaryImage = bwulterode(binaryImage);
countImage = conv2(double(binaryImage), ones(128));
No for loops needed. This has the window sliding along in steps of 1 pixel. If you want more than that, simply subsample the image or (much less simply) use blockproc().

Plus de réponses (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by