Matlab을 통해 이미지의 각 RGB 색상 채널의 강도를 백분율로 계산하는 방법은 무엇입니까? 다음 MATLAB 코드가 제대로 작동하지 않습니다Matlab을 통해 이미지의 각 RGB 색상 채널의 강도를 백분율로 계산하는 방법은 무엇입니까?
I = imread('3.png'); % read image
Ir=I(:,:,1); % read red chanel
Ig=I(:,:,2); % read green chanel
Ib=I(:,:,3); % bule chanel
% figure, imshow(I), title('Original image')
% figure, imshow(Ir), title('Red channel')
% figure, imshow(Ig), title('Green channel')
% figure, imshow(Ib), title('Blue channel')
%% read the size of the
m = size(I,1);
n = size(I,2);
R_total= 0;
G_total= 0;
B_total= 0;
for i = 1:m
for j = 1:n
rVal= int64(Ir(i,j));
gVal= int64(Ig(i,j));
bVal= int64(Ib(i,j));
R_total= R_total+rVal;
G_total= G_total+gVal;
B_total= B_total+bVal;
end
end
disp (R_total)
disp (G_total)
disp (B_total)
%% Calcualte the image total intensity
I_total = R_total + G_total + B_total;
disp(I_total)
%% Calculate the percentage of each Channel
R_precentag = R_total/I_total * 100 ; %% Red Channel Precentage
G_precentag = G_total/I_total * 100 ; %% Green Channel Precentage
B_precentag = B_total/I_total * 100 ;
나는 B.
어떻게 문제를 해결하기 위해 어떤 생각을 각 채널 R, G의 강도 비율을 볼 수 있을까?
예제를 추가하여 조언을 제공해 주셨습니다. –
합계를하기 전에 double로 변환하는 것을 잊지 마십시오. – gnovice
@gnovice 왜 두 번 먼저 변환 하시겠습니까? 'sum'은 정수를 입력으로 사용하는 데 문제가 없으며 기본적으로 정수를 반환합니다. –