圖像處理--從頻率角度分析均值濾波

1.均值濾波

對於均值濾波器,就是設定一定大小的核,計算核包含的像素點對應的平均值。其中核A定義每個元素對應的值都爲1:
[a11a12a1na21a22a2nam1am2amn]\begin{bmatrix} {a_{11}}&{a_{12}}&{\cdots}&{a_{1n}}\\ {a_{21}}&{a_{22}}&{\cdots}&{a_{2n}}\\ {\vdots}&{\vdots}&{\ddots}&{\vdots}\\ {a_{m1}}&{a_{m2}}&{\cdots}&{a_{mn}}\\ \end{bmatrix}
那麼對應的均值濾波核如下所示:
Filter=1M×N×AFilter=\frac{1}{M\times N}\times A

2.Kernel 大小分析

不同大小的核對圖像進行濾波得到的圖像信息不同,隨着核的大小的增大,計算的像素點越多,也就意味着濾波後的圖像包含了更多的信息,這樣,隨着核大小的增大,高頻信息丟失。
以下是不同大小的核均值濾波後的圖像:
均值濾波的核越大得到的圖像越模糊。

3.頻率分析

對圖像進行均值濾波,分析濾波後的圖像頻譜分佈。利用傅里葉變換進行圖像的頻譜分析。分析不同大小覈對應的頻率分佈。
對不同大小的核濾波後的圖像進行頻譜分析,可以發現,核越大,剩下的都是低頻信息。
傅里葉變換

4.MATLAB實現

原圖

CODE TEST
對圖像進行均值濾波。不添加任何噪聲。

clc;
clear all;
I = imread('C:\1_WORKSHOP\Work_Notes\Matlab\1.jpg');
I = I(1:500,1:1080,:);
I = im2double(I);
h = fspecial('average', [5,5]);
h1 = fspecial('average', [15,15]);
h2 = fspecial('average', [25,25]);
h3 = fspecial('average', [35, 35]);
di1 = imfilter(I, h);
di2 = imfilter(I, h1);
di3 = imfilter(I, h2);
di4 = imfilter(I, h3);
err1 = I - di1;
err2 = I - di2;
err3 = I - di3;
err4 = I - di4;
f1 = fft2(di1);
f11 = abs(fftshift(f1));
f2 = fft2(di2);
f21 = abs(fftshift(f2));
f3 = fft2(di3);
f31 = abs(fftshift(f3));
f4 = fft2(di4);
f41 = abs(fftshift(f4));
figure;
subplot(431),image(I);
subplot(432),image(di1);
subplot(433),image((I-di1));
subplot(434),image(I);
subplot(435),image(di2);
subplot(436),image((I-di2));
subplot(437),image(I);
subplot(438),image(di3);
subplot(439),image((I-di3));
subplot(4,3,10),image(I);
subplot(4,3,11),image(di4);
subplot(4,3,12),image((I-di4));
figure;
subplot(221),image(err1);
subplot(222),image(err2);
subplot(223),image(err3);
subplot(224),image(err4);
figure;
subplot(221),image(f11);
subplot(222),image(f21);
subplot(223),image(f31);
subplot(224),image(f41);

5.Opencv實現

過段時間再寫這部分代碼。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章