2013-03-04 9 views
0

나는 선택한 색상을 제외한 모든 색상을 제거하는 someones 코드를 연구하고 있습니다. 코드 샘플에서 다음 줄을 교체 경우 검은 색 모든 페인트하려고합니다 빨간색 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

을 그가있는 경우 typo이지만 140보다 크고 동시에 120보다 작은 픽셀을 얻으려고합니다. 이것은 문제가 될 수 있습니다. –

+0

오타되었습니다. 감사합니다.) 답변자로 게시 할 수 있습니다. – Yarh

답변

1

는 잘못된 논리 곱 있습니다 - hPlane 요소가이 작동합니다 (140)보다는과 (120)보다 작은 동시에 더 큰해야 : 몰라요

nonRedIndex = (hPlane < 140) & (hPlane > 120); 
관련 문제