RGB与XYZ HSV HSL之间转换公式大全

方便以后查看特意记录下来,获取详细转换公式请从此官方通道进入:http://www.easyrgb.com/en/math.php
可以转换的方式如下:
XYZ → Standard-RGB
Standard-RGB → XYZ
XYZ → Adobe-RGB
Adobe-RGB → XYZ
XYZ → Yxy
Yxy → XYZ
XYZ → Hunter-Lab
Hunter-Lab → XYZ
XYZ → CIE-Lab
CIE-L
ab → XYZ
CIE-Lab → CIE-LCH°
CIE-LCH° → CIE-Lab
XYZ → CIE-Luv
CIE-L
uv → XYZ
RGB → HSL
HSL → RGB
RGB → HSV
HSV → RGB
RGB → CMY
CMY → RGB
CMY → CMYK
CMYK → CMY

好的,以下是使用MATLAB语言定义将RGB转换为HSI颜色空间的函数rgb2hsi: ```matlab function [h,s,i] = rgb2hsi(r,g,b) %RGB2HSI Convert red-green-blue colors to hue-saturation-intensity. % HSI = RGB2HSI(RGB) converts the RGB image RGB (which is m-by-n-by-3) % to the HSI (hue-saturation-intensity) color space. RGB values are % assumed to be in the range of 0 to 1. % % The HSI color space, also known as HSL (hue-saturation-lightness), % separates color information (hue) from intensity information (saturation % and intensity). Hue is defined as the angle of the color on a color wheel, % saturation is the amount of color present, and intensity is the brightness % of the color. % % Class Support % ------------- % Input RGB can be of class uint8, uint16, single, or double. Output HSI % is double. % % Example % ------- % % Convert an RGB image to HSI color space % RGB = imread('peppers.png'); % HSI = rgb2hsi(RGB); % % See also HSI2RGB, RGB2LAB, RGB2NTSC, RGB2XYZ, RGB2YCBCR, RGB2GRAY. % Validate inputs validateattributes(r, {'uint8', 'uint16', 'double', 'single'}, {'real', 'nonsparse', 'nonempty', '>=', 0, '<=', 1}, mfilename, 'R', 1); validateattributes(g, {'uint8', 'uint16', 'double', 'single'}, {'real', 'nonsparse', 'nonempty', '>=', 0, '<=', 1}, mfilename, 'G', 2); validateattributes(b, {'uint8', 'uint16', 'double', 'single'}, {'real', 'nonsparse', 'nonempty', '>=', 0, '<=', 1}, mfilename, 'B', 3); % Initialize output variables h = zeros(size(r)); s = zeros(size(r)); i = zeros(size(r)); % Calculate hue theta = acos((2*r-g-b)./(2*sqrt((r-g).^2 + (r-b).*(g-b)))); h(b > g) = 2*pi - theta(b > g); h = h/(2*pi); % Calculate saturation minRGB = min(min(r,g),b); s(minRGB > 0) = 1 - minRGB(minRGB > 0)./i(minRGB > 0); % Calculate intensity i = (r + g + b)/3; end ``` 在这个函数中,我们首先验证输入的RGB值是否符合要求,然后初始化输出变量,并计算HSI颜色空间的三个分量:色调(hue)、饱和度(saturation)和亮度(intensity)。 注意,这个函数中的算法是从RGB转换到HSI的标准算法,但在某些情况下可能会产生不正确的结果。如果需要更准确的RGB到HSI转换算法,请参考相关文献。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值