日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

matlab 二维高斯滤波 傅里叶_光电图像处理 | 傅里叶变换(二)

發(fā)布時(shí)間:2024/10/14 80 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab 二维高斯滤波 傅里叶_光电图像处理 | 傅里叶变换(二) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.頻域?yàn)V波與圖像增強(qiáng)

1.1 基本步驟

(1) zero padding
(2) Spectrum centralization
(3) DFT:
(4) Symmetry
(5)
(6) IDFT :
(7) from with size top-left part.

1.2 MATLAB代碼

clc,close?all;
I?=?imread('byh.jpg');%?MATLAB庫里面有圖源?cell.tif
I?=?rgb2gray(I);
[m,n]?=?size(I);?%?m為行,n為列
J?=?zeros(2*m,2*n);
%?進(jìn)行擴(kuò)展
for?i=1:m
????for?j=1:n
????????J(i,j)?=?I(i,j);
????end
end
%?中心化處理?Spectrum?ccentralization
K?=?J;
for?i=1:m
????for?j=1:n
????????K(i,j)?=?I(i,j)*(-1).^(i+j);
????end
end
%?傅里葉變換
F?=?log(1+fft2(im2double(K)));
%?H?函數(shù)
H?=?zeros(2*m,2*n);
square?=?70;?%?濾波函數(shù)?H?的邊長?
H(m-square:m+square,n-square:n+square)=1;
%?相乘
FF?=?F?.*?H;
%?反傅里葉變換
ff?=?ifft2(exp(FF)-1);
ff_r?=?real(ff);
ff_final?=?ff_r;
for?i=1:2*m
????for?j=1:2*n
????????ff_final(i,j)?=?ff_final(i,j)?*?(-1)^(i+j);
????end
end

subplot(241),imshow(I,[]),xlabel('(a)?原圖');
subplot(242),imshow(J,[]),xlabel('(b)?進(jìn)行擴(kuò)展操作后的圖片');
subplot(243),imshow(K,[]),xlabel('(c)?頻域中心化后的圖像');
subplot(244),imshow(F,[]),xlabel('(d)?傅里葉變換后的圖像');
subplot(245),imshow(H,[]),xlabel('(e)?自制的低通濾波器');
subplot(246),imshow(FF,[]),xlabel('(f)?低通濾波處理后的圖像');
subplot(247),imshow(ff_final,[]),xlabel('(g)?反傅里葉變換后的圖像');
subplot(248),imshow(ff_final(1:m,1:n),[]),xlabel('(h)?取(g)圖中的左上部分');

result:

如果不進(jìn)行擴(kuò)展,直接進(jìn)行(低通)濾波,結(jié)果如下:

clc,close?all;
I?=?imread('byh.jpg');%?MATLAB庫里面有圖源?cell.tif
I?=?rgb2gray(I);
[m,n]?=?size(I);?%?m為行,n為列
J?=?zeros(m,n);
%?進(jìn)行擴(kuò)展
for?i=1:m
????for?j=1:n
????????J(i,j)?=?I(i,j);
????end
end
%?中心化處理?Spectrum?ccentralization
K?=?J;
for?i=1:m
????for?j=1:n
????????K(i,j)?=?I(i,j)*(-1).^(i+j);
????end
end
%?傅里葉變換
F?=?log(1+fft2(im2double(K)));
%?H?函數(shù)
H?=?zeros(m,n);
square?=?35;?%?濾波函數(shù)?H?的邊長?
H(round(m/2)-square:round(m/2)+square,round(n/2)-square:round(n/2)+square)=1;
%?相乘
FF?=?F?.*?H;
%?反傅里葉變換
ff?=?ifft2(exp(FF)-1);
ff_r?=?real(ff);
ff_final?=?ff_r;
for?i=1:m
????for?j=1:n
????????ff_final(i,j)?=?ff_final(i,j)?*?(-1)^(i+j);
????end
end

subplot(241),imshow(I,[]),xlabel('(a)?原圖');
subplot(242),imshow(J,[]),xlabel('(b)?進(jìn)行擴(kuò)展操作后的圖片');
subplot(243),imshow(K,[]),xlabel('(c)?頻域中心化后的圖像');
subplot(244),imshow(F,[]),xlabel('(d)?傅里葉變換后的圖像');
subplot(245),imshow(H,[]),xlabel('(e)?自制的低通濾波器');
subplot(246),imshow(FF,[]),xlabel('(f)?低通濾波處理后的圖像');
subplot(247),imshow(ff_final,[]),xlabel('(g)?反傅里葉變換后的圖像');
subplot(248),imshow(ff_final(1:m,1:n),[]),xlabel('(h)?取(g)圖中的左上部分');

只修改了部分代碼,表達(dá)清楚意思即可hhh ?;-)

result:

2 頻域?yàn)V波器分類

2.1 低通濾波器

理想低通濾波器(ILPF)特點(diǎn):物理上不可實(shí)現(xiàn);有抖動(dòng)現(xiàn)象;濾除高頻成分使圖像變模糊

其中,

D0為截止頻率;P = 2M,Q = 2N,M,N為待濾波圖像的尺寸。

clc,close?all;
I?=?imread('kobi.png');%?MATLAB庫里面有圖源?cell.tif?byh.jpg
I?=?rgb2gray(I);
[P,Q]?=?size(I);?%?m為行,n為列
F?=?log(1+fftshift(fft2(I)));?%?顯示頻譜
H?=?ILPF_ZH(P,Q,70);?%?濾波矩陣?/?系統(tǒng)傳遞函數(shù)
F_new?=?F?.*?H;?%?濾波后的頻譜
F_ishift?=?ifft2(exp(F_new)-1);
ff_r?=?real(F_ishift);
ff_final?=?ff_r;
for?i=1:P
????for?j=1:Q
????????ff_final(i,j)?=?ff_final(i,j)?*?(-1)^(i+j);
????end
end
imshow(ff_final,[])
subplot(231),imshow(I,[]),xlabel('(a)?原圖');????
subplot(232),imshow(F,[]),xlabel('(b)?原圖的頻譜');???
subplot(233),imshow(H,[]),xlabel('(c)?濾波器');????
subplot(234),x=1:1:P;y=1:1:Q;[X,Y]=meshgrid(x,y);mesh(X,Y,H');xlabel('(d)?濾波器三維展示');???
subplot(235),imshow(F_new,[]),xlabel('(e)?濾波后的頻譜');????
subplot(236),imshow(ff_final,[]),xlabel('(f)?濾波后的圖像')???
%%?理想低通濾波器
function?H?=?ILPF_ZH(P,Q,D0)
%?P?=?2551;Q?=?2551;%?P和Q均為奇數(shù)
H?=?zeros(P,Q);
%?D0?=?20;
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????if?D?????????????H(i,j)?=?1;
????????end
????end
end
end

RESULT

巴特沃思(Butterworth)低通濾波器 BLPF

其中,

clc,close?all;
I?=?imread('kobi.png');%?MATLAB庫里面有圖源?cell.tif?byh.jpg
I?=?rgb2gray(I);
[P,Q]?=?size(I);?%?m為行,n為列
F?=?log(1+fftshift(fft2(I)));?%?顯示頻譜
H?=?BLPF_ZH(P,Q,70,2);?%?巴特沃思(Butterworth)低通濾波矩陣?/?系統(tǒng)傳遞函數(shù)

F_new?=?F?.*?H;?%?濾波后的頻譜
F_ishift?=?ifft2(exp(F_new)-1);
ff_r?=?real(F_ishift);
ff_final?=?ff_r;
for?i=1:P
????for?j=1:Q
????????ff_final(i,j)?=?ff_final(i,j)?*?(-1)^(i+j);
????end
end
imshow(ff_final,[])
subplot(231),imshow(I,[]),xlabel('(a)?原圖');????
subplot(232),imshow(F,[]),xlabel('(b)?原圖的頻譜');???
subplot(233),imshow(H,[]),xlabel('(c)?濾波器');????
subplot(234),x=1:1:P;y=1:1:Q;[X,Y]=meshgrid(x,y);mesh(X,Y,H');xlabel('(d)?濾波器三維展示');???
subplot(235),imshow(F_new,[]),xlabel('(e)?濾波后的頻譜');????
subplot(236),imshow(ff_final,[]),xlabel('(f)?濾波后的圖像')???
%%?巴特沃思(Butterworth)低通濾波器
function?H?=?BLPF_ZH(P,Q,D0,n)
H?=?zeros(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????H(i,j)?=?1/(1+(D/D0)^(2*n));
????end
end
end

RESULT

高斯低通濾波器(GLPF)

其中,

clc,close?all;
I?=?imread('kobi.png');%?MATLAB庫里面有圖源?cell.tif?byh.jpg
I?=?rgb2gray(I);
[P,Q]?=?size(I);?%?m為行,n為列
F?=?log(1+fftshift(fft2(I)));?%?顯示頻譜
H?=?GLPF_ZH(P,Q,50);?????%?高斯低通濾波器(GLPF)

F_new?=?F?.*?H;?%?濾波后的頻譜
F_ishift?=?ifft2(exp(F_new)-1);
ff_r?=?real(F_ishift);
ff_final?=?ff_r;
for?i=1:P
????for?j=1:Q
????????ff_final(i,j)?=?ff_final(i,j)?*?(-1)^(i+j);
????end
end
imshow(ff_final,[])
subplot(231),imshow(I,[]),xlabel('(a)?原圖');????
subplot(232),imshow(F,[]),xlabel('(b)?原圖的頻譜');???
subplot(233),imshow(H,[]),xlabel('(c)?濾波器');????
subplot(234),x=1:1:P;y=1:1:Q;[X,Y]=meshgrid(x,y);mesh(X,Y,H');xlabel('(d)?濾波器三維展示');???
subplot(235),imshow(F_new,[]),xlabel('(e)?濾波后的頻譜');????
subplot(236),imshow(ff_final,[]),xlabel('(f)?濾波后的圖像')???
%%?高斯低通濾波器(GLPF)
function?H?=?GLPF_ZH(P,Q,D0)
H?=?zeros(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????H(i,j)?=?exp(-(D)^2?/?(2?*?D0^2));
????end
end
end

RESULT

2.2 高通濾波器

通常,頻域高通濾波器可以看成是頻域低通濾波器的反操作,即

理想高通濾波器(IHPF)

clc,close?all;
I?=?imread('kobi.png');%?MATLAB庫里面有圖源?cell.tif?byh.jpg
I?=?rgb2gray(I);
[P,Q]?=?size(I);?%?m為行,n為列
F?=?log(1+fftshift(fft2(I)));?%?顯示頻譜
H?=?IHPF_ZH(P,Q,15);???%?理想高通濾波矩陣?/?系統(tǒng)傳遞函數(shù)

F_new?=?F?.*?H;?%?濾波后的頻譜
F_ishift?=?ifft2(exp(F_new)-1);
ff_r?=?real(F_ishift);
ff_final?=?ff_r;
for?i=1:P
????for?j=1:Q
????????ff_final(i,j)?=?ff_final(i,j)?*?(-1)^(i+j);
????end
end
imshow(ff_final,[])
subplot(231),imshow(I,[]),xlabel('(a)?原圖');????
subplot(232),imshow(F,[]),xlabel('(b)?原圖的頻譜');???
subplot(233),imshow(H,[]),xlabel('(c)?濾波器');????
subplot(234),x=1:1:P;y=1:1:Q;[X,Y]=meshgrid(x,y);mesh(X,Y,H');xlabel('(d)?濾波器三維展示');???
subplot(235),imshow(F_new,[]),xlabel('(e)?濾波后的頻譜');????
subplot(236),imshow(ff_final,[]),xlabel('(f)?濾波后的圖像')??
%%?理想高通濾波器
function?H?=?IHPF_ZH(P,Q,D0)
H?=?ones(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????if?D?????????????H(i,j)?=?0;
????????end
????end
end
end

RESULT

巴特沃思(Butterworth)高通濾波器

clc,close?all;
I?=?imread('kobi.png');%?MATLAB庫里面有圖源?cell.tif?byh.jpg
I?=?rgb2gray(I);
[P,Q]?=?size(I);?%?m為行,n為列
F?=?log(1+fftshift(fft2(I)));?%?顯示頻譜
H?=?BHPF_ZH(P,Q,8,2);?%?巴特沃思(Butterworth)高通濾波矩陣?/?系統(tǒng)傳遞函數(shù)

F_new?=?F?.*?H;?%?濾波后的頻譜
F_ishift?=?ifft2(exp(F_new)-1);
ff_r?=?real(F_ishift);
ff_final?=?ff_r;
for?i=1:P
????for?j=1:Q
????????ff_final(i,j)?=?ff_final(i,j)?*?(-1)^(i+j);
????end
end
imshow(ff_final,[])
subplot(231),imshow(I,[]),xlabel('(a)?原圖');????
subplot(232),imshow(F,[]),xlabel('(b)?原圖的頻譜');???
subplot(233),imshow(H,[]),xlabel('(c)?濾波器');????
subplot(234),x=1:1:P;y=1:1:Q;[X,Y]=meshgrid(x,y);mesh(X,Y,H');xlabel('(d)?濾波器三維展示');???
subplot(235),imshow(F_new,[]),xlabel('(e)?濾波后的頻譜');????
subplot(236),imshow(ff_final,[]),xlabel('(f)?濾波后的圖像')???
%%?巴特沃思(Butterworth)高通濾波器
function?H?=?BHPF_ZH(P,Q,D0,n)
H?=?zeros(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????H(i,j)?=?1/(1+(D0/D)^(2*n));
????end
end
end

RESULT

高斯高通濾波器(GLPF)

clc,close?all;
I?=?imread('kobi.png');%?MATLAB庫里面有圖源?cell.tif?byh.jpg
I?=?rgb2gray(I);
[P,Q]?=?size(I);?%?m為行,n為列
F?=?log(1+fftshift(fft2(I)));?%?顯示頻譜
H?=?GHPF_ZH(P,Q,8);???%?高斯高通濾波器(GLPF)

F_new?=?F?.*?H;?%?濾波后的頻譜
F_ishift?=?ifft2(exp(F_new)-1);
ff_r?=?real(F_ishift);
ff_final?=?ff_r;
for?i=1:P
????for?j=1:Q
????????ff_final(i,j)?=?ff_final(i,j)?*?(-1)^(i+j);
????end
end
imshow(ff_final,[])
subplot(231),imshow(I,[]),xlabel('(a)?原圖');????
subplot(232),imshow(F,[]),xlabel('(b)?原圖的頻譜');???
subplot(233),imshow(H,[]),xlabel('(c)?濾波器');????
subplot(234),x=1:1:P;y=1:1:Q;[X,Y]=meshgrid(x,y);mesh(X,Y,H');xlabel('(d)?濾波器三維展示');???
subplot(235),imshow(F_new,[]),xlabel('(e)?濾波后的頻譜');????
subplot(236),imshow(ff_final,[]),xlabel('(f)?濾波后的圖像')?
%%?高斯高通濾波器(GHPF)
function?H?=?GHPF_ZH(P,Q,D0)
H?=?zeros(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????H(i,j)?=?1?-?exp(-(D)^2?/?(2?*?D0^2));
????end
end
end

RESULT

匯合在一起的代碼如下:

clc,close?all;
I?=?imread('kobi.png');%?MATLAB庫里面有圖源?cell.tif?byh.jpg
I?=?rgb2gray(I);
[P,Q]?=?size(I);?%?m為行,n為列
F?=?log(1+fftshift(fft2(I)));?%?顯示頻譜
%?H?=?ILPF_ZH(P,Q,70);???%?理想低通濾波矩陣?/?系統(tǒng)傳遞函數(shù)
%?H?=?BLPF_ZH(P,Q,70,2);?%?巴特沃思(Butterworth)低通濾波矩陣?/?系統(tǒng)傳遞函數(shù)
%?H?=?GLPF_ZH(P,Q,50);?????%?高斯低通濾波器(GLPF)
%?H?=?IHPF_ZH(P,Q,15);???%?理想高通濾波矩陣?/?系統(tǒng)傳遞函數(shù)
%?H?=?BHPF_ZH(P,Q,8,2);?%?巴特沃思(Butterworth)高通濾波矩陣?/?系統(tǒng)傳遞函數(shù)
H?=?GHPF_ZH(P,Q,8);???%?高斯高通濾波器(GLPF)

F_new?=?F?.*?H;?%?濾波后的頻譜
F_ishift?=?ifft2(exp(F_new)-1);
ff_r?=?real(F_ishift);
ff_final?=?ff_r;
for?i=1:P
????for?j=1:Q
????????ff_final(i,j)?=?ff_final(i,j)?*?(-1)^(i+j);
????end
end
imshow(ff_final,[])
subplot(231),imshow(I,[]),xlabel('(a)?原圖');????
subplot(232),imshow(F,[]),xlabel('(b)?原圖的頻譜');???
subplot(233),imshow(H,[]),xlabel('(c)?濾波器');????
subplot(234),x=1:1:P;y=1:1:Q;[X,Y]=meshgrid(x,y);mesh(X,Y,H');xlabel('(d)?濾波器三維展示');???
subplot(235),imshow(F_new,[]),xlabel('(e)?濾波后的頻譜');????
subplot(236),imshow(ff_final,[]),xlabel('(f)?濾波后的圖像')???
%%?理想低通濾波器
function?H?=?ILPF_ZH(P,Q,D0)
H?=?zeros(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????if?D?????????????H(i,j)?=?1;
????????end
????end
end
end
%%?巴特沃思(Butterworth)低通濾波器
function?H?=?BLPF_ZH(P,Q,D0,n)
H?=?zeros(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????H(i,j)?=?1/(1+(D/D0)^(2*n));
????end
end
end
%%?高斯低通濾波器(GLPF)
function?H?=?GLPF_ZH(P,Q,D0)
H?=?zeros(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????H(i,j)?=?exp(-(D)^2?/?(2?*?D0^2));
????end
end
end

%%?理想高通濾波器
function?H?=?IHPF_ZH(P,Q,D0)
H?=?ones(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????if?D?????????????H(i,j)?=?0;
????????end
????end
end
end

%%?巴特沃思(Butterworth)高通濾波器
function?H?=?BHPF_ZH(P,Q,D0,n)
H?=?zeros(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????H(i,j)?=?1/(1+(D0/D)^(2*n));
????end
end
end
%%?高斯高通濾波器(GHPF)
function?H?=?GHPF_ZH(P,Q,D0)
H?=?zeros(P,Q);
for?i=1:P
????for?j=1:Q
????????D?=?((i?-?round((P+1)/2))^2?+?(j?-?round((Q+1)/2))^2)^0.5;
????????H(i,j)?=?1?-?exp(-(D)^2?/?(2?*?D0^2));
????end
end
end

END

與50位技術(shù)專家面對面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的matlab 二维高斯滤波 傅里叶_光电图像处理 | 傅里叶变换(二)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。