因此,我需要在该作业中取图像在 x 方向的导数,目的是获得某种形式的梯度。我的想法是在图像的每一行上使用 diff(命令),然后应用高斯滤波器。我还没有开始第二部分,因为第一部分给我带来了麻烦。在尝试获得 x 导数时,我有:
origImage = imread('TightRope.png');
for h = 1:3 %%h represents color channel
for i = size(origImage,1)
newImage(i,:,h) = diff(origImage(i,:,h)); %%take derivative of row and translate to new row
end
end
问题出在我收到错误“下标分配维度不匹配”的过程中。。
Error in Untitled2 (line 14)
newImage(i,:,h) = diff(origImage(i,:,h));
有谁知道为什么会发生这种情况以及我的方法是否正确获取梯度/高斯导数?
最佳答案
figure;
I = imread('cameraman.tif');
subplot 131; imshow(I); title('original')
h = fspecial('prewitt');
derivative = imfilter(I,h','replicate'); %'
subplot 132; imshow(derivative); title('derivative')
hsize = 5;
sigma = 1;
h = fspecial('gaussian', hsize, sigma) ;
gaussian = imfilter(derivative,h','replicate'); %'
subplot 133; imshow(gaussian); title('derivative + gaussian')
结果如下:
关于Matlab:对图像求导有困难吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35738528/