2013-07-29 5 views
2

아래의 색상 필터로 피망을 찾지 못하는 이유는 무엇입니까? 색조 별 색상 통과 필터

코드 :

function [ outhsv ] = ColorFilter(hsv, h, s) 
%COLORFILTER Summary of this function goes here 
% Detailed explanation goes here 

    if nargin < 2 
     h = []; 
    end 
    if nargin < 3 
     s = []; 
    end 

    if size(h,2)==1 
     h = padarray(h, [0 1], 1/100, 'post'); 
    end 

    if size(s,2)==1 
     s = padarray(s, [0 1], 1/100, 'post'); 
    end 

    if isempty(h) 
     v_of_h = ones(size(hsv,1), size(hsv,2)); 
    else 
     v_of_h = WeightFunction(hsv(:,:,1), h(:,1), h(:,2)); 
    end 

    if isempty(s) 
     v_of_s = ones(size(hsv,1), size(hsv,2)); 
    else 
     v_of_s = WeightFunctionOnce(hsv(:,:,2), s(:,1), s(:,2)); 
    end 

    outhsv = hsv; 
    outhsv(:,:,3) = hsv(:,:,3) .* v_of_h .* v_of_s; 



function y = WeightFunction(x, mu, sigma) 

    %y = WeightFunctionOnce(x,mu,sigma) + WeightFunctionOnce(x-1,mu,sigma); 
    y = 1 - (1-WeightFunctionOnce(x,mu,sigma)) .* (1-WeightFunctionOnce(x-1,mu,sigma)); 

function y = WeightFunctionOnce(x, mu, sigma) 

    if nargin<2 
     mu=0; 
    elseif nargin<3 
     sigma=1./100.; 
    end 


    if any(size(mu) ~= size(sigma)) 
     error('mu and sigma should be of the same size'); 
    end 

    y = zeros([size(x) numel(mu)]); 

    for i=1:numel(mu) 
     y(:,:,i) = exp(-((x - mu(i)) .^ 2 ./ (2 .* sigma(i) .^ 2))); 
    end 

    %y = sum(y,3)/size(y,3); 
    y = 1-prod(1-y,3); 

디스플레이 코드 : 규모

hue = 120; 
h = [hue/360 0.05]; 
s = []; 

rgb1 = imread('huescale.png'); 
%rgb1 = imread('peppers.png'); 
hsv1 = rgb2hsv(rgb1); 
hsv2 = ColorFilter(hsv1, h, s); 
rgb2 = hsv2rgb(hsv2); 
bitmask = hsv1(:,:,1)>(h(1)-h(2)) & hsv1(:,:,1)<(h(1)+h(2)); 


figure; 
subplot(3,1,1); imshow(rgb1); 
subplot(3,1,2); imshow(rgb2); 
subplot(3,1,3); imshow(bitmask); 

결과

enter image description here

(작품)

재 고추 sult :

enter image description here

(하지 않습니다)

이유는 무엇입니까?

+1

받아야하지만, 내 사진 작가의 눈에 그 고추는 노란색을 많이하고, 거의 순수한 녹색 있습니다. Photoshop으로 peppers.png 이미지를 가져 와서 [색조/채도] 패널에서 이미지를 조정하면이 사실이 확인됩니다. – horchler

답변

4

H 값을 더 가까이에서 보면 노란색 피 같은 것입니다. 따라서 규칙을 조금 넓히고 싶을 수도 있습니다. enter image description here

나는 0.15와 0.5 사이에 뭔가를 제안합니다. 또한 채도 채널과 결합하여 생생한 이미지 부분 만 고려해 볼 수 있습니다. 즉 양파를 없애고 싶습니다. 미리보기를 얻으려면 다음 코드를 사용해보십시오.

hsv_dat = rgb2hsv(imread('peppers.png')); 
imagesc(hsv_dat(:,:,1) > 0.15 & hsv_dat(:,:,1) < 0.5 & hsv_dat(:,:,2) > 0.3) 
colormap(gray) 

당신은 내가 어떤 영상 처리 전문가는 아니지만

enter image description here