Count Black pixels in regions of rgb image
3 views (last 30 days)
Show older comments
hey all,
I am trying to count the number of black pixels in a region of a segmented skin cancer image, but I don't want to account for the black pixels surrounding the image. Any idea how I can do it in a simple way?
Attached is an example of the images I am working on.
Thank you !
Chris
0 Comments
Answers (1)
Vidip
on 24 Dec 2024
To count the number of black pixels in a region, you can begin by loading your image and if your image is not already in grayscale, convert it using 'rgb2gray'. Next, you will need to define the Region of Interest (ROI) using a binary mask. This mask can be created using segmentation techniques, such as thresholding, to differentiate it fom the background. Ensure that this mask accurately represents the area of interest by applying a suitable threshold. Please refer to the following documentation link for more information: https://www.mathworks.com/help/images/create-binary-mask-using-an-roi-object.html
Once you have your ROI mask, apply it to the grayscale image to isolate the region you want to analyze. Set non-ROI areas to a non-black value to avoid counting them. Finally, use logical indexing to count the number of black pixels (those with a pixel value of 0) within the masked region. This approach ensures that only the black pixels within the defined area are counted, excluding those surrounding the image.
For more information, please refer to the following MATLAB Answers post, where 'numel' is used to compute pixel counts in specific regions: https://in.mathworks.com/matlabcentral/answers/350623-how-to-compute-number-of-pixels-in-images.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!