Calculate mean of gray Value

조회 수: 10 (최근 30일)
arame sotudegan
arame sotudegan 2021년 3월 31일
답변: Chad Greene 2021년 3월 31일
Hello, In this picture I want to calculate mean of the circle. but when I use mean( ) it calculates all the pixels including the black ones, so the mean value decreases. Is there a way to calculate only the gray value?
Thank you in advance.

채택된 답변

DGM
DGM 2021년 3월 31일
편집: DGM 2021년 3월 31일
Something like this:
% mean of non-black regions
mean(mypicture(mypicture>0))
This assumes that the image background is actually zero; otherwise, you can test that it's above some threshold value

추가 답변 (1개)

Chad Greene
Chad Greene 2021년 3월 31일
Try this. Below I'm creating an example matrix M, and calculate the mean of only the values that exceed zero:
M = peaks(100); % example matrix
M(M<=0) = 0;
figure
imagesc(M)
colormap(gray)
colorbar
mask = M>0; % logical mask corresponding to all values greater than zero
figure
imagesc(mask)
mean(M(mask),'all') % mean of all values of M that exceed zero.
ans = 1.1528

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by