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

조회 수: 1 (최근 30일)
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

채택된 답변

Matt J
Matt J 2021년 7월 26일
results.area=nnz(imstd>90);

추가 답변 (0개)

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by