2013-03-04 83 views
0

我正在学习某些代码,删除所有颜色exept选择一个。 如果至代码示例中替换下一行它将尝试漆黑色一切eccept红色图像处理过滤器不适用

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); 
+2

我不知道这是否是一个打字错误,但你正在努力获得大于140的像素,同时小于120.这可能是一个问题。 – 2013-03-04 22:07:37

+0

是的,这是一个错字,谢谢你)你可以发布它作为你的answaer – Yarh 2013-03-05 15:05:37

回答

1

有一个错误的逻辑连词 - hPlane元素必须大于140,并在同一时间超过120小大。这应该工作:

nonRedIndex = (hPlane < 140) & (hPlane > 120);