MATLAB中 H(b > g) = 2*pi - H(b > g); 作何解
初学MATLAB,这一句代码是什么意思有点看不太懂,求解释一下。附完整代码:functionhsi=rgb2hsi(rgb)%RGB2HSIConvertsanRGBim...
初学MATLAB,这一句代码是什么意思有点看不太懂,求解释一下。
附完整代码:
function hsi = rgb2hsi(rgb)
%RGB2HSI Converts an RGB image to HSI.
% THIS FUNCTION DOWNLOAD FROM http://www.pudn.com/downloads103/sourcecode/graph/detail423625.html
% HSI = RGB2HSI(RGB) converts an RGB image to HSI. The input image
% is assumed to be of size M-by-N-by-3, where the third dimension
% accounts for three image planes :red, green,and blue, in that
% order.If all RGB component images are equal, the HSI conversion
% is underfined.The input image can be of class double (with values
% in the range[0,1]), unit8, or unit16.
%
% The output image, is of class double,where:
% hsi(:, :, 1) = hue image normalized to the range [0,1] by
% dividing all angle values by 2*pi.
% hsi(:, :, 2) = saturation image, in the range [0,1].
% hsi(:, :, 3) = intensity image, in the range [0, 1].
% Extract the individual component immages.
rgb = im2double(rgb);
r = rgb(:, :, 1);
g= rgb(:, :, 2);
b = rgb(:, :, 3);
% Implement the conversion equations.
num = 0.5*((r - g) + (r - b));
den = sqrt((r - g).^2 + (r -b ).* (g-b));
theta = acos(num./(den + eps));
H = theta;
H(b > g) = 2*pi - H(b > g);
H = H/(2*pi);
num = min(min(r,g), b);
den = r + g + b;
den(den == 0) = eps;
S = 1 -3.* num./den;
H(S ==0) = 0;
I = (r + g + b)/3;
% Combine all three results into an hsi image.
%hsi = cat( 3, H, S, I);
hsi=cat(3,H*359,S*255,I*255);
hsi=round(hsi); 展开
附完整代码:
function hsi = rgb2hsi(rgb)
%RGB2HSI Converts an RGB image to HSI.
% THIS FUNCTION DOWNLOAD FROM http://www.pudn.com/downloads103/sourcecode/graph/detail423625.html
% HSI = RGB2HSI(RGB) converts an RGB image to HSI. The input image
% is assumed to be of size M-by-N-by-3, where the third dimension
% accounts for three image planes :red, green,and blue, in that
% order.If all RGB component images are equal, the HSI conversion
% is underfined.The input image can be of class double (with values
% in the range[0,1]), unit8, or unit16.
%
% The output image, is of class double,where:
% hsi(:, :, 1) = hue image normalized to the range [0,1] by
% dividing all angle values by 2*pi.
% hsi(:, :, 2) = saturation image, in the range [0,1].
% hsi(:, :, 3) = intensity image, in the range [0, 1].
% Extract the individual component immages.
rgb = im2double(rgb);
r = rgb(:, :, 1);
g= rgb(:, :, 2);
b = rgb(:, :, 3);
% Implement the conversion equations.
num = 0.5*((r - g) + (r - b));
den = sqrt((r - g).^2 + (r -b ).* (g-b));
theta = acos(num./(den + eps));
H = theta;
H(b > g) = 2*pi - H(b > g);
H = H/(2*pi);
num = min(min(r,g), b);
den = r + g + b;
den(den == 0) = eps;
S = 1 -3.* num./den;
H(S ==0) = 0;
I = (r + g + b)/3;
% Combine all three results into an hsi image.
%hsi = cat( 3, H, S, I);
hsi=cat(3,H*359,S*255,I*255);
hsi=round(hsi); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询