2013-03-04 77 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);