。如何在Matlab 2016b中设置hsv彩色图像的色相和饱和度值
答案 0 :(得分:0)
这里的主要问题是您的范围是在uint8
范围(范围[0,255])中定义的,而rgb2hsv
的结果是范围[0,1]的两倍。
您可以将255乘以将范围[0,1]转换为[0,255]。
使用min
和max
函数限制范围很简单。
这是一个有效的范例:
RGB_Color = imread('peppers.png'); %Read sample image.
hsvImage = rgb2hsv(RGB_Color);
%Convert HSV from range [0, 1] to range [0, 255]
hsvImage = hsvImage*255;
H = hsvImage(:,:,1);
S = hsvImage(:,:,2);
V = hsvImage(:,:,3);
%1. Hue value must be in the range between 10 to 40
H = max(min(H, 40), 10);
%2. saturation value(100–255)
S = max(min(S, 255), 100);
%Convert back to RGB
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hsvImage = cat(3, H, S, V);
%Convert HSV from range [0, 255] to range [0, 1].
hsvImage = hsvImage / 255;
rgbImage = hsv2rgb(hsvImage);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Display result
figure;imshow(RGB_Color);title('Original RGB image');
figure;imshow(rgbImage);title('RGB after HSV thresholding');
HSV阈值处理后的