Take the 2-minute tour ×
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It's 100% free, no registration required.
  I = imread('13.jpg');
  Ir = I(:,:,1);
  Ig = I(:,:,2);
  Ib = I(:,:,3);

   %# Create the gaussian filter with hsize = [5 5] and sigma = 2
   G = fspecial('gaussian',[10 10],1);
  %# Filter it
  Ig = imfilter(I,G,'same');
  %# Display
  imshow(Ig);

  PSF = fspecial('gaussian',7,10);

  Irc = conv2(Ir,PSF,'same');
  Igc = conv2(Ig,PSF,'same');
  Ibc = conv2(Ib,PSF,'same');

Why am I getting this error?

       Warning: CONV2 on values of class UINT8 is obsolete.
       Use CONV2(DOUBLE(A),DOUBLE(B)) or
       CONV2(SINGLE(A),SINGLE(B)) instead. 
       In uint8.conv2 at 11
       In Gaussian_Filter_image at 19 
      Warning: CONV2 on values of class UINT8 is obsolete.
       Use CONV2(DOUBLE(A),DOUBLE(B)) or
       CONV2(SINGLE(A),SINGLE(B)) instead. 
    In uint8.conv2 at 11
       In Gaussian_Filter_image at 20 
       Undefined function 'conv2' for input arguments of type 'double'
       and attributes 'full 3d real'.
      Error in uint8/conv2 (line 18)
       y = conv2(varargin{:});

       Error in Gaussian_Filter_image (line 20)
       Igc = conv2(Ig,PSF,'same');

Here I want to perform convolution of image and gaussian filter but I am unable to do that ?

I have even tried the modification after using

   Ir = double(:,:,1);
   Ig = double(:,:,2);
   Ib = double(:,:,3);

then also I am getting the same error?

share|improve this question
1  
It should be Ir = double(I(:,:,1)); ..., not Ir = double(:,:,1); ... –  Paul R Jan 15 '13 at 12:04
3  
This is a programming question (or debugging question) about MATLAB, not a question about signa processing, and should be closed as off-topic. –  Dilip Sarwate Jan 15 '13 at 12:38
add comment

closed as off topic by Dilip Sarwate, Andrey, penelope, Paul R, jonsca Jan 16 '13 at 0:07

Questions on Signal Processing Stack Exchange are expected to relate to signal processing within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

You are getting the error because image I is of class (data type) 'uint8', and the arguments to conv2 must be of class 'single' or 'double', i. e. floating point. You can get rid of the error by converting I to double. The best way to do that is to call I = im2double(I), which will re-scale the pixel values to be between 0 and 1.

But looking at the big picture, you should not use conv2 at all, and use imfilter instead, which does take 'uint8' images. Look at the help for it. By default it does correlation, but it can also do convolution.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.