【发布时间】:2016-12-27 22:00:33
【问题描述】:
我正在尝试实现一个简单的低通滤波器,使用“ones”函数作为滤波器和“conv2”来计算两个矩阵(原始图像和滤波器)的卷积,这是我想要的滤波图像得到,但是imshow(filteredImage)的结果只是一个空白的图像,而不是过滤后的图像。
我检查了过滤图像的矩阵,它是一个256x256的双精度,但我不知道它显示不正确的原因。
I = imread('cameraman.tif');
filteredImage = conv2(double(I), double(ones(3,3)), 'same');
figure; subplot(1,2,1); imshow(filteredImage);title('filtered');
subplot(1,2,2); imshow(I); title('original');
编辑: 我也尝试在计算卷积之前先将其转换为两倍,因为它超过了 1,但它没有给出低通滤波器效果,而是增加了图像的对比度。
I = imread('cameraman.tif');
I1 = im2double(I);
filteredImage = conv2(I1, ones(2,2), 'same');
figure; subplot(1,2,1); imshow(filteredImage);title('filtered');
subplot(1,2,2); imshow(I1); title('original');
【问题讨论】:
-
double类型的图像应具有从0到1的值。你的filteredImage可能超过了。 -
@beaker 是的,它超过了这个值,但我首先使用“im2double”将它转换为双倍,但它太白而不是变得模糊
-
好的,现在你遇到了第二个问题。
filteredImage的取值范围是多少?在您编辑的代码中,我愿意打赌它们介于0和4之间。 -
@beaker 是的,它们在 0 到 3 之间
-
尝试将内核除以它的大小:
double(ones(3,3))/9。
标签: matlab filter lowpass-filter