Wie berechnet man die Intensität jedes RGB-Farbkanals eines Bildes als Prozentsatz über Matlab? Der folgende Matlab-Code funktioniert nicht richtig:Wie berechnet man die Intensität jedes RGB-Farbkanals eines Bildes als Prozentsatz über Matlab?
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 ;
Ich kann die prozentuale Intensität jeden Kanals R, G, B. nicht sehen
Jede Idee, wie das Problem zu lösen?
Ein Beispiel hinzugefügt, danke für den Hinweis. –
Vergessen Sie nicht, vor dem Ausführen der Summen in Doppel zu konvertieren. – gnovice
@gnovice Warum würden Sie zuerst zu Double konvertieren? "sum" hat keine Probleme, ganze Zahlen als Eingabe zu verwenden und wird standardmäßig ein "double" zurückgeben. –