我正在研究某人的代码,该代码会删除除所选颜色之外的所有颜色。如果要替换代码示例中的下一行,它将尝试将除红色之外的所有内容都涂成黑色
nonRedIndex = (hPlane > 20) & (hPlane < 340);
但是,我发现其他 diaposons 不起作用。你能告诉我为什么吗?
cdata = imread(path);
hsvImage1 = rgb2hsv(cdata); %# Convert the image to HSV space
hPlane = 360.*hsvImage1(:,:,1); %# Get the hue plane scaled from 0 to 360
sPlane = hsvImage1(:,:,2); %# Get the saturation plane
lPlane = hsvImage1(:,:,3);
nonRedIndex = (hPlane > 140) & ... %# Select "non-red" pixels
(hPlane < 120);
sPlane(nonRedIndex) = 0; %# Set the selected pixel saturations to 0
lPlane(nonRedIndex) = 0;
hsvImage1(:,:,2) = sPlane; %# Update the saturation plane
hsvImage1(:,:,3) = lPlane;
rgbImage1 = hsv2rgb(hsvImage1);