MATLAB Answers

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

2 views (last 30 days)
Nicholas Arnold
Nicholas Arnold on 26 Jul 2021
Commented: Matt J on 26 Jul 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

Accepted Answer

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

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by