How to count the number of pixels in each section of an image set?

8 次查看(过去 30 天)
Hello:)
I have a set of 80 dicom images of lungs and I was wondering if there is an automatic way or a simple way to count the number of pixels belonging to the lung in each section.
Could anyone help me?
I've searched everywhere and I can't find a way to calculate the pixels of each image at the same time, I only got the total number of pixels in the set but thats not what i wanted..
Any kind of help is welcome.
Thank you :)
  4 个评论

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2022-5-12
A = imread('toyobjects.png');
A = A<100 | A>150; % some binary image
% get total number of pixels across all objects
pixtotal = regionprops('table',A,'Area')
pixtotal = 4×1 table
Area _____ 10871 11922 8797 1644
  7 个评论
Matt J
Matt J 2022-5-12
Perhaps you are accidentally feeding the code the same image every time. Whatever the problem is, it's coming from parts of the code you haven't shown us. But you can see from the simplified examples we've given you that regionprops will work.

请先登录,再进行评论。

更多回答(1 个)

DGM
DGM 2022-5-11
编辑:DGM 2022-5-11
Depending on what your images are like and what you need, this may be a start. You can calculate the number of true (nonzero) pixels in an image using nnz(). If your image has more than one object, then it will include them all. If you have more than one object and you want the pixel count for each object, you can do that using bwconncomp()
A = imread('toyobjects.png');
A = A<100 | A>150; % some binary image
imshow(A)
% get total number of pixels across all objects
pixtotal = nnz(A)
pixtotal = 33234
% get number of pixels in each object
CC = bwconncomp(A);
pixperobj = cellfun(@numel,CC.PixelIdxList)
pixperobj = 1×4
10871 11922 8797 1644
  1 个评论
Gabriela Almeida
Gabriela Almeida 2022-5-12
@DGM Thanks for the help but I think something is not right because the number of pixels is increasing with the number of images but there are images where the lung part decreases and the number of pixels increases.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by