未定义函数'conv2'用于'double'类型的输入参数和属性'full 3d real'. - Matlab

Sam*_*NLP 7 matlab image

我正在尝试过滤空间域中的图像,所以我正在使用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);
Run Code Online (Sandbox Code Playgroud)

我收到了错误:

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);
Run Code Online (Sandbox Code Playgroud)

现在我想知道,我不能使用3通道图像,这意味着彩色图像.

sup*_*pyo 10

彩色图像是三维阵列(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
    
    Run Code Online (Sandbox Code Playgroud)