필터 지우기
필터 지우기

How to find the number of pixels with intensity

조회 수: 4 (최근 30일)
Davidson Bock
Davidson Bock 2018년 1월 23일
댓글: Matt J 2018년 1월 23일
I'm trying to find the histogram of an image. I'm supposed to use loops to calculate it. So far, my code is
histogram = = zeros(256,1,'int16');
for j = 0 : 255
histogram(j + 1) = number of pixels with intensity j
end
The problem I'm having is that I'm not sure how to find the number of pixels with intensity j. I know that I should use either the find() or sum() function, but I don't know how to format that part of the code

채택된 답변

Matt J
Matt J 2018년 1월 23일
편집: Matt J 2018년 1월 23일
One way,
histogram(j + 1) = nnz(yourImage==j);
Or,
histogram(j + 1) = sum(yourImage(:)==j);
  댓글 수: 2
Davidson Bock
Davidson Bock 2018년 1월 23일
ok thanks! I'm very new to MatLab, when I want to save the part where I did the coding, do I click "Save Workspace"?
Matt J
Matt J 2018년 1월 23일
You're welcome, but please Accept-click the answer to confirm that it resolved your issue.
As for saving, you should write the code in the Editor Window and use the file save button on the toolbar

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by