How to count the number of pixels in each section of an image set?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Gabriela Almeida
il 11 Mag 2022
Commentato: Gabriela Almeida
il 12 Mag 2022
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 Commenti
Image Analyst
il 12 Mag 2022
@Gabriela Almeida then you must not have discovered my Image Segmentation Tutorial in my File Exchange
Risposta accettata
Matt J
il 12 Mag 2022
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')
7 Commenti
Matt J
il 12 Mag 2022
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.
Più risposte (1)
DGM
il 11 Mag 2022
Modificato: DGM
il 11 Mag 2022
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)
% get number of pixels in each object
CC = bwconncomp(A);
pixperobj = cellfun(@numel,CC.PixelIdxList)
Vedere anche
Categorie
Scopri di più su Explore and Edit Images with Image Viewer App in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!