I have an RGB image and I need to find the area of black pixels in the image
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
RandomChikiBum
am 7 Okt. 2022
Kommentiert: Image Analyst
am 8 Okt. 2022
Pretty much the question, How do I find out the area of black pixels in an image?
1 Kommentar
DGM
am 8 Okt. 2022
You need to convert the image to a logical mask that describes the black regions. In order to do that, you need to define what "black" means in whatever context you're dealing with. There are existing examples of thresholding and color-based segmentation throughout the forum; otherwise, you'll have to provide an example image and a description of the expectations.
Once you have that logical mask, you can use bwarea(), nnz() or perhaps regionprops() to get the area in pixels. It depends if you want to find the total area or the area of each isolated region.
Akzeptierte Antwort
Image Analyst
am 8 Okt. 2022
Try this:
rgbImage = imread('coloredChips.png');
subplot(2, 1, 1);
imshow(rgbImage);
impixelinfo;
% Find black. Defined as where the gray scale is less than 40.
mask = rgb2gray(rgbImage) < 40;
subplot(2, 1, 2);
imshow(mask);
% Get the area (number of black pixels).
numBlackPixels = nnz(mask)
1 Kommentar
Image Analyst
am 8 Okt. 2022
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Explore and Edit Images with Image Viewer App finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!