MATLAB:对图像应用低通滤波器

MATLAB: Apply a low-pass filter to an image

我正在尝试实现一个简单的低通滤波器,使用 "ones" 函数作为滤波器,"conv2" 计算两个矩阵(原始图像和滤波器)的卷积,即我想要得到的过滤后的图像,但是 imshow(filteredImage) 的结果只是一个空白的白色图像,而不是过滤后的图像。

我查看了过滤后图片的矩阵,是一个256x256的double,不知道是什么原因显示不正常

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');

编辑: 我也试过先把它转成double再计算卷积,因为它超过了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');

以下解决方案解决了范围问题,给出的其他解决方案是关于特定类型的 low-pass 过滤器,即平均过滤器:

Img1 = imread('cameraman.tif');
Im=im2double(Img1);
filteredImage = conv2(Im, ones(3,3));
figure; subplot(1,2,1); imshow(filteredImage, []);title('filtered');
subplot(1,2,2); imshow(Im); title('original');

我没有除以内核,而是使用 imshow(filteredImage, []).