Trying to count the number of pixels in an image over a specific RBG value

1 vue (au cours des 30 derniers jours)
Nicholas Arnold
Nicholas Arnold le 26 Juil 2021
Commenté : Matt J le 26 Juil 2021
I am trying to count the number of pixels in an image over a specific RBG value by going pixel by pixel and sorting the desired pixels in a varaibale (z). My goal is to then print the number of pixels in the image.
My main issue, however, seems to be that sorting all 1.92 million pixels in a JPG image is too much for my computer to handle.
I am wondering if there is a better way to do / think about his problem / something I'm missing that would make this code work.
function results = darkArea(im)
im = rgb2gray(im);
imstd = stdfilt(im,ones(27));
z = zeros(1,numel(imstd));
for i = 1:numel(imstd)
if im(i) <= 90
z(i) = [];
end
area = numel(z);
results.area = area;
end

Réponse acceptée

Matt J
Matt J le 26 Juil 2021
results.area=nnz(imstd>90);
  2 commentaires
Matt J
Matt J le 26 Juil 2021
You're welcome, but please Accept-click the answer to indicate that it did what you need.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by