相位相關算法:
1.相位相關簡介:相位相關算法的理論基礎是傅里葉變換,目前在傅里葉變換領域有了快速算法fft,比較成熟的庫有fftw開源庫,因此相位相關法有極大的速度優勢,相位相關在圖像融合、模式識別特徵匹配等有着廣泛應用。
下面我就圖像融合裏的應用做個簡要介紹:
針對有平移失配、旋轉的圖像融合分別作介紹。
1)圖像間有平移變換。
圖像f2(x,y)是圖像f1(x,y)經平移(x0,y0)後得到的圖像,即
{
int i, j, k;
double tmp;
int width = ref->width;
int height = ref->height;
int step = ref->widthStep;
int fft_size = width * height;
uchar *ref_data = ( uchar* ) ref->imageData;
uchar *tpl_data = ( uchar* ) tpl->imageData;
double *poc_data = ( double* )poc->imageData;
fftw_complex *img1 = ( fftw_complex* )fftw_malloc( sizeof( fftw_complex ) * width * height );
fftw_complex *img2 = ( fftw_complex* )fftw_malloc( sizeof( fftw_complex ) * width * height );
fftw_complex *res = ( fftw_complex* )fftw_malloc( sizeof( fftw_complex ) * width * height );
fftw_plan fft_img1 = fftw_plan_dft_1d( width * height, img1, img1, FFTW_FORWARD, FFTW_ESTIMATE );
fftw_plan fft_img2 = fftw_plan_dft_1d( width * height, img2, img2, FFTW_FORWARD, FFTW_ESTIMATE );
fftw_plan ifft_res = fftw_plan_dft_1d( width * height, res, res, FFTW_BACKWARD, FFTW_ESTIMATE );
for( i = 0, k = 0 ; i < height ; i++ ) {
for( j = 0 ; j < width ; j++, k++ ) {
img1[k][0] = ( double )ref_data[i * step + j];
img1[k][1] = 0.0;
img2[k][1] = 0.0;
}
}
fftw_execute( fft_img1 );
fftw_execute( fft_img2 );
for( i = 0; i < fft_size ; i++ )
{
res[i][0] = ( img2[i][0] * img1[i][0] ) - ( img2[i][1] * ( -img1[i][1] ) );
res[i][1] = ( img2[i][0] * ( -img1[i][1] ) ) + ( img2[i][1] * img1[i][0] );
res[i][1] /= tmp;
}
fftw_execute(ifft_res);
for( i = 0 ; i < fft_size ; i++ ) {
poc_data[i] = res[i][0] / ( double )fft_size;
}
fftw_destroy_plan( fft_img1 );
fftw_destroy_plan( fft_img2 );
fftw_destroy_plan( ifft_res );
fftw_free( img1 );
fftw_free( img2 );
fftw_free( res );
}