Counting Total Number of Pixels by Color in a Segmented Image

8 vues (au cours des 30 derniers jours)
Vance Blake
Vance Blake le 1 Juin 2020
Commenté : Vance Blake le 2 Juin 2020
Hello I have mutiple segmented images that I would like to count the number of white, red, and blue pixels in each image using a for loop. I would like to store the number of red, white, and blue pixels associated with each image in an array along with the filename of each image. I can do each image manually, but I would like to make the process faster. I count the black pixels to make sure that the sum total of pixels assigned is close to 90,000, since each image is 300x300 and some pixels might be hard to distguinsh. Any help would be greatly appreicated. Thanks
rgbImage = imread('BioM Edge 576 Gen 5 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 10 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 15 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 20 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 25 Infl Rnge Start Segmented.png');
%rgbImage = imread('BioM Edge 576 Gen 30 Infl Rnge Start Segmented.png');
%%
BluePixels = rgbImage(:,:,1) == 0 & rgbImage(:,:,2) == 0 & rgbImage(:,:,3) == 255;
numBluePixels = sum(BluePixels(:));
%%
RedPixels = rgbImage(:,:,1) == 255 & rgbImage(:,:,2) == 0 & rgbImage(:,:,3) == 0;
numRedPixels = sum(RedPixels(:));
%%
WhitePixels = rgbImage(:,:,1) == 255 & rgbImage(:,:,2) == 255 & rgbImage(:,:,3) == 255;
numWhitePixels = sum(WhitePixels(:));
%%
BlackPixels = rgbImage(:,:,1) == 0 & rgbImage(:,:,2) == 0 & rgbImage(:,:,3) == 0;
numBlackPixels = sum(BlackPixels(:));

Réponse acceptée

Image Analyst
Image Analyst le 1 Juin 2020
Modifié(e) : Image Analyst le 1 Juin 2020
In the for loop over all image files, just index the variables:
numBluePixels(k) = sum(BluePixels(:));
etc.
To check that the sum of blue, red, white, and black pixels is to within some tolerance of the total number of pixels, just sum them up at the bottom of the loop
tolerance = 0.05 * numel(BluePixels); % 5% of the total number of pixels.
if numBluePixels(k) + numWhitePixels(k) + numRedPixels(k) + numBlackPixels(k) > numel(BluePixels) - tolerance
% The sum is close enough to 90,000
else
% The sum is not close enough to 90,000 because some pixels were not classified as one of those colors.
end
  5 commentaires
Vance Blake
Vance Blake le 2 Juin 2020
Wow enhanced is a bit of an understatement this^ is why you're an MVP on here. I finished up manually counting them a couple of hours ago, but I am really glad to have this version for the next batch. Thank you so much for your help! A lot of your other codes have been instructive for me.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Red dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by