我正在尝试在空间域中过滤图像,因此我正在使用 conv2 函数。
这是我的代码。
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);
我得到了错误:
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);
现在我想知道,我不能使用 3 channel 图像,即彩色图像。
最佳答案
彩色图像是 3 维数组(x、y、颜色)。 conv2
仅针对 2 维定义,因此它不能直接作用于 3 维数组。
三个选项:
使用n维卷积,
convn()
使用
rgb2gray()
转换为灰度图像,并在 2D 中进行过滤:filter_g = conv2(gauss,rgb2gray(img_double));
在 2D 中分别过滤每种颜色 (RGB):
filter_g = zeros(size(im_double)); for i = 1:3 filter_g(:,:,i) = conv2(gauss, im_double(:,:,i); end
关于image - 对于类型为 'conv2' 和属性为 'double' 的输入参数,未定义函数 'full 3d real'。 - Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13888185/