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
对于nD输入,您需要使用convn
。
If you have R2015a or newer, the IPT function imgaussfilt handles multi-plane 2-d convolution problems like this, just pass in your RGB image.
http://www.mathworks.com/help/images/ref/imgaussfilt.html
If you don't, imfilter also performs multiplane 2-d convolution.
Both will be faster for a Gaussian filter, they both know how to do the separable trick for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.