Has anyone implemented MACH (maximum average correlation height filter) on MATLAB?

2 views (last 30 days)
Hi, I am implemented MACH filter which is implemented when you are implementing automatic target recognitions which starts with
  1. taking composite of image
  2. Applying log polar mapping
  3. then taking its FFT
  4. then multiplying
(all steps apply for both image and template)
Objective: I need peaks the same as when correlation of the template and image is taken
Problem: I am not getting all of the peaks only 2 of them. What am I doing wrong?
I want four peaks like in the correlation
Here I am getting two peaks whereas I want more than 2 like in norm correlation
My template
My image
Here is my code
Basically for every airplane I want a define peak in the MACH
Other results are
composite image of airplane and it's log polar
clc;
clear;
img = im2double(imread('E:\Data Set MACH\test2.jpg'));
gray1 = rgb2gray(img);
% img = imresize(gray1, [400 400]);
temp = im2double(imread('E:\Data Set MACH\test.jpg'));
img1 = rgb2gray(temp);
img2 = imrotate(img1,5);
img3 = imrotate(img1,10);
img4 = imrotate(img1,15);
img5 = imrotate(img1,20);
img6 = imrotate(img1,25);
img7 = imrotate(img1,30);
img8 = imrotate(img1,200);
row = 50; col = 50;
img1 = imresize(img1,[row col]);
img2 = imresize(img2,[row col]);
img3 = imresize(img3,[row col]);
img4 = imresize(img4,[row col]);
img5 = imresize(img5,[row col]);
img6 = imresize(img6,[row col]);
img7 = imresize(img7,[row col]);
img8 = imresize(img8,[row col]);
imshow(img8);
sum_image = im2double(img1)+im2double(img2)+im2double(img3)+im2double(img4)+im2double(img5)+im2double(img6)+im2double(img7)+im2double(img8);
gray2 = sum_image/8;
imshow(gray2);
xc1 = size(gray1,2)/2+0.5;
yc1 = size(gray1,1)/2+0.5;
rmin1 = 1;
rmax1 = 400;
nw1 = 400;
xc2 = size(gray2,2)/2+0.5;
yc2 = size(gray2,1)/2+0.5;
nw2 = 150;
rmin2 = 0.1;
rmax2 = 90;
% rmin2 = 1;
% rmax2 = 255;
% nw2 = 255;
% nr = min(min(gray2));
% xc2 = (size(gray2, 2)/2)+0.5;
% yc2 = (size(gray2, 1)/2)+0.5;
log_polar1 = logsample(gray1,rmin1,rmax1,xc1,yc1,[],nw1);
log_polar2 = logsample(gray2,rmin2,rmax2,xc2,yc2,[],nw2);
figure();
imshow(log_polar1);
figure();
imshow(log_polar2);
corr = abs(normxcorr2(img1,gray1));
figure();
surf(corr);
% corr1 = normxcorr2(gray2,gray1);
% figure();
% surf(corr1);
% PQ1 = paddedsize(size(log_polar1));
% PQ2 = paddedsize(size(log_polar2));
% THETA_F1 = abs(fftshift(fft2(log_polar1,PQ1(1),PQ1(2))));
% THETA_F2 = abs(fftshift(fft2(log_polar2,PQ2(1),PQ2(2))));
THETA_F1 = abs(fftshift(fft2(log_polar1)));
THETA_F2 = abs(fftshift(fft2(log_polar2)));
THETA_F2 = padarray(THETA_F2,[250,219],1,'post');
% THETA_F1 = padarray(THETA_F1,[1000,1000],1,'post');
corr1 = abs(THETA_F2).*abs(THETA_F1);
corr1 = real(corr1);
figure();
surf(corr1);

Answers (1)

Shahab Ahmed
Shahab Ahmed on 2 Jan 2020
Hey There, I've got through your code. The issue was that you used "gray1" instead of "gray2" (mean of the template images)in "normxcorr" function.
I have modified the code and it's working now. Test this and provide your feedback.
Thanks
Regards
clc;
clear;
img = im2double(imread('H:\Semester Data\FYP\MATLAB Example\test2.jpg'));
subplot(3,3,1)
imshow(img)
title('Testing')
gray1 = rgb2gray(img);
% img = imresize(gray1, [400 400]);
temp = im2double(imread('H:\Semester Data\FYP\MATLAB Example\test.jpg'));
subplot(3,3,2)
imshow(temp)
title('Template')
img1 = rgb2gray(temp);
img2 = imrotate(img1,5);
img3 = imrotate(img1,10);
img4 = imrotate(img1,15);
img5 = imrotate(img1,20);
img6 = imrotate(img1,25);
img7 = imrotate(img1,30);
img8 = imrotate(img1,200);
subplot(3,3,3)
imshow(img8)
title('Rotated Image')
row = 50; col = 50;
img1 = imresize(img1,[row col]);
img2 = imresize(img2,[row col]);
img3 = imresize(img3,[row col]);
img4 = imresize(img4,[row col]);
img5 = imresize(img5,[row col]);
img6 = imresize(img6,[row col]);
img7 = imresize(img7,[row col]);
img8 = imresize(img8,[row col]);
sum_image = im2double(img1)+im2double(img2)+im2double(img3)+im2double(img4)+im2double(img5)+im2double(img6)+im2double(img7)+im2double(img8);
gray2 = sum_image/8;
subplot(3,3,4)
imshow(gray2)
title('Mean')
xc1 = size(gray1,2)/2+0.5;
yc1 = size(gray1,1)/2+0.5;
rmin1 = 1;
rmax1 = 400;
nw1 = 400;
xc2 = size(gray2,2)/2+0.5;
yc2 = size(gray2,1)/2+0.5;
nw2 = 150;
rmin2 = 0.1;
rmax2 = 90;
log_polar1 = logsample(gray1,rmin1,rmax1,xc1,yc1,[],nw1);
log_polar2 = logsample(gray2,rmin2,rmax2,xc2,yc2,[],nw2);
subplot(3,3,5)
imshow(log_polar1)
title('Log 1')
subplot(3,3,6)
imshow(log_polar2)
title('Log 2')
corr11 = abs(normxcorr2(img1,gray2));
figure
surf(corr11)
title('correlation')
THETA_F1 = abs(fftshift(fft2(log_polar1)));
THETA_F2 = abs(fftshift(fft2(log_polar2)));
THETA_F2 = padarray(THETA_F2,[250,219],1,'post');
corr1 = abs(THETA_F2).*abs(THETA_F1);
corr1 = real(corr1);
figure
surf(corr1);
title('Peak')
  5 Comments
Shahab Ahmed
Shahab Ahmed on 3 Jan 2020
Sure. Would you help me with some guiding material? I shall be very grateful to you.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!