【问题标题】:MATLAB: Apply a low-pass filter to an imageMATLAB:对图像应用低通滤波器
【发布时间】: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 类型的图像应具有从01 的值。你的filteredImage 可能超过了。
  • @beaker 是的,它超过了这个值,但我首先使用“im2double”将它转换为双倍,但它太白而不是变得模糊
  • 好的,现在你遇到了第二个问题。 filteredImage 的取值范围是多少?在您编辑的代码中,我愿意打赌它们介于 04 之间。
  • @beaker 是的,它们在 0 到 3 之间
  • 尝试将内核除以它的大小:double(ones(3,3))/9

标签: matlab filter lowpass-filter


【解决方案1】:

以下解决方案已解决范围问题,给出的其他解决方案是关于特定类型的低通滤波器,即平均滤波器:

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, []),而不是按内核划分。

【讨论】:

    猜你喜欢
    • 2016-02-13
    • 1970-01-01
    • 2021-06-25
    • 1970-01-01
    • 2021-03-08
    • 2011-02-15
    • 2017-03-11
    • 2016-02-29
    • 2015-05-03
    相关资源
    最近更新 更多