Pattern Recognition in Matlab

2.6k views Asked by At

first I am not sure here is the right place to ask this question yet I have a question about image processing. I am trying to write a pattern recognition code in Matlab. I have an object input which is 256x256 pixels raw data includes "ABCD" capital letter in it and a filter which is also 256x256 pixels raw data includes "A" capital letter and the whole letters are in same dimensions. My code is going to be:

  1. First read this these two raw data files in matlab, show these images
  2. Take 2 dimensional fourier trasnform of object and filter, show these images
  3. Take the conjugate of the filter,
  4. Multiply them
  5. Take 2 dimensional fourier trasnform of 4,
  6. show the out put of 5.

This code aims to find the autocorrelation of A in the input and in the output. While doing these, crosscorrelations among B,C,D and A in the filter are going to be in the output but their intensities are going to be less than the autocorrelation of A. In briefly in this code we try to use convolution approach rather than correlation and do this in frequency domain. I wrote a code but it does not work accurately especially the output image is not correct. I also look for the correct function to load the raw files into Matlab. My code:

%%%EE 520 HW 3
%%%Problem # 2
clear all; close all; clc;
load fA258.mat;
load fO.mat;
figure(1)
subplot(211)
imshow(o)
title('Image of the OBJECT');
subplot(212)
imshow(fa)
title('Image of the FILTER');
F=fft2(fa,256,256);
F1=fftshift(F);
F2=log(abs(F));
O=fft2(o,256,256);
O1=fftshift(O);
O2=log(abs(O));
f1=ifft2(F);
o1=ifft2(O);
figure(2)
subplot(211);
imshow(o1);
title('Check for Object');
subplot(212)
imshow(f1);
title('Check for Filter');
figure(3)
subplot(211)
imshow(log(abs(fftshift(O)) + 1), [])
title('FT of Object'); 
subplot(212)
imshow(log(abs(fftshift(F)) + 1), []) 
title('FT of Filter');
Fc=conj(F1);
Y=O1.*Fc;
y=fft2(Y);
figure(4)
subplot(211)
imshow(log(abs(fftshift(y)) + 1), [])
title('Output');
subplot(212)
imshow(y)

Thanks.

1

There are 1 answers

0
Pablo On

You want to take the inverse Fourier transform in step 5.