【发布时间】:2017-07-12 15:19:12
【问题描述】:
如何通过 Matlab 将图像的每个 RGB 颜色通道的强度计算为百分比? 以下 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 ;
我看不到每个通道 R、G、B 的强度百分比。
知道如何解决这个问题吗?
【问题讨论】: