[英]Undefined function 'conv2' for input arguments of type 'double' and attributes 'full 3d real'. - 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通道圖像,即彩色圖像。
彩色圖像是3維數組(x,y,color)。 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
對於nD輸入,您需要使用convn
。
如果您具有R2015a或更高版本,則IPT函數imgaussfilt可以處理像這樣的多平面二維卷積問題,只需傳入RGB圖像即可。
http://www.mathworks.com/help/images/ref/imgaussfilt.html
如果您不這樣做,則imfilter還會執行多平面二維卷積。
兩者對於高斯濾波器都會更快,它們都知道如何為您做可分離的技巧。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.