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'は整数を入力として扱うことに問題はなく、デフォルトでは' double'を返します。 –