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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Matt J
Matt J el 26 de Jul. de 2021
results.area=nnz(imstd>90);

Más respuestas (0)

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by