数字图像处理实验(9):PROJECT 04-05,Correlation in the Frequency Domain
實驗要求:
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ù)中最大值位置的(x,y)坐標,沒有必要繪制圖中的輪廓。
程序實現(xiàn)步驟:
1、將兩幅圖像的大小都拓展298×298;
2、兩幅圖像的每個像素都乘以(-1)^(x+y),使其在頻域位于中心位置;
3、做傅里葉變換,轉換到頻域;
4、在頻域兩幅圖像,一個與另一個的共軛相乘計算相關函數(shù);
5、作傅里葉逆變換轉換回空間域;
6、乘以(-1)^(x+y),得到最終結果。
要求使用的兩幅圖:
Figs. 4.41(a):
Figs. 4.41(b):
實驗代碼:
% 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);% 顯示結果 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)]);實驗結果:
這是輸出結果的圖片,實驗要求沒必要顯示出來。
最后求出的(x,y)位置的坐標。
總結
以上是生活随笔為你收集整理的数字图像处理实验(9):PROJECT 04-05,Correlation in the Frequency Domain的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数字图像处理实验(8):PROJECT
- 下一篇: 数字图像处理实验(10):PROJECT