本文介绍了类型为"double"的输入参数和属性为"full 3d real"的未定义函数"conv2". -Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在空间域中过滤图像,所以我正在使用conv2函数.
I'm trying to filter an image in the space domain so i'm using the conv2 function.
这是我的代码.
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通道图像,即彩色图像吗?
now i'm wondering, can't I use a 3 channel image, meaning color image.
推荐答案
彩色图像是3维数组(x,y,color). conv2
仅针对2维定义,因此它不能直接在3维数组上工作.
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.
三个选项:
-
使用n维卷积
convn()
使用rgb2gray()
转换为灰度图像,然后以2D过滤:
Convert to a grayscale image using rgb2gray()
, and filter in 2D:
filter_g = conv2(gauss,rgb2gray(img_double));
分别以2D过滤每种颜色(RGB):
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
这篇关于类型为"double"的输入参数和属性为"full 3d real"的未定义函数"conv2". -Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!