I'm trying to filter an image in the space domain so i'm using the conv2 function.
here's my code.
cd /home/samuelpedro/Desktop/APIProject/
close all
clear all
clc
img = imread('coimbra_aerea.jpg');
%figure, imshow(img);
size_img = size(img);
gauss = fspecial('gaussian', [size_img(1) size_img(2)], 50);
%figure, surf(gauss), shading interp
img_double = im2double(img);
filter_g = conv2(gauss,img_double);
I got the error:
Undefined function 'conv2' for input arguments of type 'double' and attributes 'full 3d
real'.
Error in test (line 18)
filter_g = conv2(gauss,img_double);
now i'm wondering, can't I use a 3 channel image, meaning color image.
Color images are 3 dimensional arrays (x,y,color). conv2
is only defined for 2-dimensions, so it won't work directly on a 3-dimensional array.
Three options:
Use an n-dimensional convolution, convn()
Convert to a grayscale image using rgb2gray()
, and filter in 2D:
filter_g = conv2(gauss,rgb2gray(img_double));
Filter each color (RGB) separately in 2D:
filter_g = zeros(size(im_double));
for i = 1:3
filter_g(:,:,i) = conv2(gauss, im_double(:,:,i);
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With