在图像matlab上执行均值滤波

时间:2013-12-01 17:28:00

标签: matlab image-processing

我正在尝试在Matlab中对图像执行均值滤波,我必须使其模块化,因此我有另一个函数用于平均,然后我的脚本调用该函数。我运行脚本并没有错误,但它似乎没有进行过滤,因为图像的输出与原始输出没有区别。谁能看到我哪里错了?

%input image
image1 = imread('moon.jpg');

%convert to grayscale


%mean filtering
mean = averagefilter2(image1);

image_grey = rgb2gray(mean);

figure;

imshow(image_grey);


%my average filter function%

function img=averagefilter2(image1)
    meanFilter = fspecial('average',[3 3]);
    img = imfilter (image1,meanFilter);
end

谢谢!

1 个答案:

答案 0 :(得分:1)

你能展示你的image1和image_grey的数字吗?您还可以尝试imagesc(abs(image1-image_grey))查看原始图像与平均图像之间的差异。我运行你的代码并没有看到问题。我可以在样本图像中观察到平滑效果。

请务必同时将rgb2gray应用于您的image1。