資源簡介
利用傅里葉變換和反傅里葉變換,實現兩個圖像之間相位相關性比較,從而得到平移量,用于圖像防抖和簡單的配準算法,matlab實現。
代碼片段和文件信息
function?[diracSignal_2DtranslationVector_PixtranslationVector_SubpeakValue]?=?PhaseCorrelationRegistration(imageInput_PreimageInput_Cur)
%?%?This?function?estimates?the?(pixel?and?subpixel?level)?motion?vector?using?the?phase?correlation?method;
%?%?The?frame?which?will?be?interpolated?matches?the?first?variable
%?%?Compare?the?size?of?two?images
[row_Precol_Predimen_Pre]?=?size(imageInput_Pre);
%?[row_Curcol_Curdimen_Cur]?=?size(imageInput_Cur);
%?if?(row_Pre~=row_Cur)|(col_Pre~=col_Cur)|(dimen_Pre~=dimen_Cur)
%?????error(‘The?two?images?input?should?be?of?the?same?size!‘);
%?????return;
%?end
%?%?Convert?the?RGB?images?to?gray?images
if?dimen_Pre==3
????gray_Pre?=?rgb2gray(imageInput_Pre);
????gray_Cur?=?rgb2gray(imageInput_Cur);
elseif?dimen_Pre==1
????gray_Pre?=?imageInput_Pre;
????gray_Cur?=?imageInput_Cur;
else
????error(‘Not?the?proper?image?format!‘);
????return;
end
%?%?To?reduce?the?computational?cost
%截取圖象大小128*128
?%???gray_Pre?=?gray_Pre(51:178101:228);
?%???gray_Cur?=?gray_Cur(51:178101:228);
?%???row_Pre?=?128;
?%???col_Pre?=?128;
?
?%下采樣圖象大小256*256
%??for?u=1:256
%??????for?v=1:256
%??????????gray_Pre1(uv)?=?gray_Pre(u*2v*2);
%??????????gray_Cur1(uv)?=?gray_Cur(u*2v*2);
%??????end
%??end
?
%???gray_Pre?=?gray_Pre1;
%???gray_Cur?=?gray_Cur1;
????
%???row_Pre?=?256;
%???col_Pre?=?256;
?%chipping?is?end.???
%?%?Fourier?transform?of?the?two?images?
spectrum_Pre?=?fft2(double(gray_Pre));
spectrum_Cur?=?fft2(double(gray_Cur));
%?%?Acquire?the?CPS(Cross?Power?Spectrum)
%?CPS?=?ones(row_Precol_Pre);
CPS?=?spectrum_Cur./spectrum_Pre;?
%?Shift?the?spectrum?centre?so?the?(00)?vector?will?be?at?(N/2N/2)
for?u=1:row_Pre
????for?v=1:col_Pre
????????CPS(uv)?=?CPS(uv)*power(-1u+v);?%?MATLAB?offers?fftshift?function?
%?%?-----------------------------------------------------------------------
%?Experiment?of?new?method?which?is?used?to?remove?the?content?varying?effect
%?????????if?abs(spectrum_Pre(uv))<50
%?????????????CPS(uv)?=?0*CPS(uv);
%?????????end
%?%?---------
- 上一篇:指靜脈處理代碼
- 下一篇:基線解算的matlab源碼
評論
共有 條評論