Counting cells in a sliding window

2 ビュー (過去 30 日間)
tethys
tethys 2016 年 3 月 31 日
編集済み: Image Analyst 2016 年 4 月 1 日
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 件のコメント
Image Analyst
Image Analyst 2016 年 3 月 31 日
tethys
tethys 2016 年 4 月 1 日
Thank you for your suggestion Image Analyst. I have uploaded one example.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2016 年 4 月 1 日
編集済み: Image Analyst 2016 年 4 月 1 日
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().

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by