2016-10-30 8 views
2

이미지에 가우스 필터 (저역 통과 필터)를 수행하는 코드가 있습니다. 그러나이 필터는 그레이 스케일 이미지에서만 작동합니다. 컬러 이미지에서 작동하도록 어떻게 향상시킬 수 있습니까? 내장 된 함수가 많이 있지만 이미지 처리가 처음인데 기본을 배우려고합니다.RGB 이미지 용 Matlab 저역 통과 필터

%Read an Image 
Img = imread('peppers.png'); 
Im = rgb2gray(Img); 
I = double(Im); 

%Design the Gaussian Kernel 
%Standard Deviation 
sigma = 1.76; 

%Window size 
sz = 4; 
[x,y]=meshgrid(-sz:sz,-sz:sz); 

M = size(x,1)-1; 
N = size(y,1)-1; 
Exp_comp = -(x.^2+y.^2)/(2*sigma*sigma); 
Kernel= exp(Exp_comp)/(2*pi*sigma*sigma); 

%Initialize 
Output=zeros(size(I)); 
%Pad the vector with zeros 
I = padarray(I,[sz sz]); 

%Convolution 
for i = 1:size(I,1)-M 
    for j =1:size(I,2)-N 
     Temp = I(i:i+M,j:j+M).*Kernel; 
     Output(i,j)=sum(Temp(:)); 
    end 
end 
%Image without Noise after Gaussian blur 
Output = uint8(Output); 
figure,imshow(Output); 

답변

0

RGB 이미지는 빨강, 녹색, 파랑 색 채널로 구성됩니다. 된 이미지

  • 프로세스 각 성분 화상 reconstuct
  • 한번 수정 R, G 행 (B R, G)의 세 성분들을 분리 할 RGB 이미지

    1. 를 화상 처리를 수행하도록 더 많은 정보를 원하시면 B

      img = imread('peppers.png'); 
      R = img(:,:,1); %get the Red part 
      G = img(:,:,2); %get the Blue part 
      B = img(:,:,3); %get the Green part 
      R_gaussian = gaussianFilter(R); %write your own function name 
      G_gaussian = gaussianFilter(G); %or repeat the code by REPLACING I as 
      B_gaussian = gaussianFilter(B); %Red Green Blue components 
      RGB_gaussian = cat(3,R_gaussian, G_gaussian, B_gaussian); %merging the components 
      %since you are learning you can do this for better unedrstanding 
      RGB_gaussian = zeros(size(img)); %make a matrix of size of original image 
      RGB_gaussian(:,:,1)=R_gaussian; % Replace the values 
      RGB_gaussian(:,:,2)=G_gaussian; 
      RGB_gaussian(:,:,3)=B_gaussian; 
      

    이 도움이 될 수 있습니다 http://www.bogotobogo.com/Matlab/Matlab_Tutorial_Digital_Image_Processing_6_Filter_Smoothing_Low_Pass_fspecial_filter2.php

    +0

    코드의 마지막 두 줄을 수정해야합니다. 다른 두 채널에 쓰는 대신 출력의 첫 번째 채널을 덮어 쓰는 것입니다. 모든 명령문의 끝에 세미콜론을 추가하거나 명령 프롬프트에 에코를 많이 표시 할 것을 제안합니다. – rayryeng