image - 对于类型为 'conv2' 和属性为 'double' 的输入参数,未定义函数 'full 3d real'。 - Matlab

标签 image matlab

我正在尝试在空间域中过滤图像,因此我正在使用 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/

相关文章:

matlab - 如何用 100*5 矩阵的特定范围的随机数填充矩阵的列?

JavaScript 如何将鼠标光标更改为图像?

json - 如何将 json 文件从 labelme 界面转换为 png 或图像格式文件?

c++ - 如何从像 MATLAB 的 audioread 这样的 libsndfile 库中读取数组格式的音频文件

matlab - 在 Matlab 中生成 64 位随机整数

matlab - 是什么导致 MATLAB 中的文件标识符无效?

matlab - 在矩阵中查找比例列

php - 添加黑条以创建 16x9 图像

jquery - 图像 Z 索引,使框架位于图像前面

html - CSS图像调整大小问题