数字图像处理实验(9):PROJECT 04-05,Correlation in the Frequency Domain
實(shí)驗(yàn)要求:
Objective:
To know how to implement correlation of 2 functions in the frequency domain and, using the fast algorithms.
Main requirements:
Ability of programming with C, C++, or Matlab.
Instruction manual:
Download Figs. 4.41(a) and (b) and duplicate Example 4.11 to obtain Fig. 4.41(e). Give the (x,y) coordinates of the location of the maximum value in the 2D correlation function. There is no need to plot the profile in Fig. 4.41(f).
實(shí)驗(yàn)只是要求給出二維相關(guān)函數(shù)中最大值位置的(x,y)坐標(biāo),沒(méi)有必要繪制圖中的輪廓。
程序?qū)崿F(xiàn)步驟:
1、將兩幅圖像的大小都拓展298×298;
2、兩幅圖像的每個(gè)像素都乘以(-1)^(x+y),使其在頻域位于中心位置;
3、做傅里葉變換,轉(zhuǎn)換到頻域;
4、在頻域兩幅圖像,一個(gè)與另一個(gè)的共軛相乘計(jì)算相關(guān)函數(shù);
5、作傅里葉逆變換轉(zhuǎn)換回空間域;
6、乘以(-1)^(x+y),得到最終結(jié)果。
要求使用的兩幅圖:
Figs. 4.41(a):
Figs. 4.41(b):
實(shí)驗(yàn)代碼:
% Correlation in the Frequency Domain close all; clc; clear all;% img_f1 = imread('Fig4.41(a).jpg'); img_f2 = imread('Fig4.41(b).jpg');[M1, N1] = size(img_f1); [M2, N2] = size(img_f2);P = 298; Q = 298; img_fp1 = zeros(P, Q); img_fp2 = zeros(P, Q); img_fp1(1:M1, 1:N1) = img_f1(1:M1, 1:N1); img_fp2(1:M2, 1:N2) = img_f2(1:M2, 1:N2);for x = 1:Pfor y = 1:Qimg_fp1(x, y) = img_fp1(x, y) .* (-1)^(x+y);img_fp2(x, y) = img_fp2(x, y) .* (-1)^(x+y);end end% 傅里葉變換 img_Fp1 = fft2(img_fp1); img_Fp2 = fft2(img_fp2);% 求共軛 img_Fp = img_Fp2 .* conj(img_Fp1);% 傅里葉變換 img_fp = ifft2(img_Fp);% 乘以(-1)^(x+y) for x = 1:Pfor y = 1:Qimg_fp(x, y) = img_fp(x, y) .* (-1)^(x+y);end endimg_fp = real(img_fp); img_fp = mat2gray(img_fp);% 顯示結(jié)果 imshow(img_fp);max_value = max(max(img_fp)); [row col] = find(img_fp == max_value);disp(['max value is : ', num2str(max_value)]); disp(['row: ', num2str(row), ' col: ', num2str(col)]);實(shí)驗(yàn)結(jié)果:
這是輸出結(jié)果的圖片,實(shí)驗(yàn)要求沒(méi)必要顯示出來(lái)。
最后求出的(x,y)位置的坐標(biāo)。
總結(jié)
以上是生活随笔為你收集整理的数字图像处理实验(9):PROJECT 04-05,Correlation in the Frequency Domain的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 数字图像处理实验(8):PROJECT
- 下一篇: 数字图像处理实验(10):PROJECT