필터 지우기
필터 지우기

I have tried the coding. But i don't understand what does mean idx = Igray == 0? Can someone explain it to me.

조회 수: 1 (최근 30일)
if true
% code
endSeparate to RGB channel
Ir = imgcrop(:,:,1);
Ig = imgcrop(:,:,2);
Ib = imgcrop(:,:,3);
% Extract the background (black) region
Igray = rgb2gray(imgcrop);
idx = Igray == 0;
% Calculate average RGB of the region
Rave = uint8(mean(Ir(~idx)));
Gave = uint8(mean(Ig(~idx)));
Bave = uint8(mean(Ib(~idx)));

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 5월 12일
This code is calculating the average of RGB channels while excluding the pixels where the intensity level is zero.
The line
idx = Igray == 0;
find all the pixels in grayscale image Igray, where the intensity is 0. It will return a logical matrix idx. Since only those pixels are required where intensity level is not 0, therefore we invert the logical matrix using ~idx,
Ir(~idx)
will return all the required pixels and then using mean() find the average. See Logical Indexing here.
  댓글 수: 4
Ameer Hamza
Ameer Hamza 2018년 5월 12일
편집: Ameer Hamza 2018년 5월 12일
As @Walter mentioned, mean() will do average along first nonscalar dimensions. In case of 2D matrix, it will average all the columns. Either use mean2() or convert to a single column before taking average like this
Rave = uint8(mean(Ir(:)));
Gave = uint8(mean(Ig(:)));
Bave = uint8(mean(Ib(:)));
disp([Rave,Gave,Bave]);
or take mean() twice
Rave = uint8(mean(mean(Ir)));
Gave = uint8(mean(mean(Ig)));
Bave = uint8(mean(mean(Ib)));
disp([Rave,Gave,Bave]);
all will produce same output.

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

추가 답변 (1개)

KSSV
KSSV 2018년 5월 12일
편집: KSSV 2018년 5월 12일
You need to read about logical indexing in MATLAB.
idx = Igray == 0;
The above line gives the indices of pixel zero's in the matrix data Igray.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by