Finding correlation between two images

Can someone tell me why this program is not working..
Searching for an object in a bitmap image. The program runs without error, however, the x-mark and line plots are in completely random places on the image and not where the most correlation should be. Also, the x-mark is in a different location to the two maxRow and maxCol plots?
Cheers.
clear all; close all; clc; G1 = imread('searchSpace.bmp'); G1 = squeeze(G1(:,:,1)); G2 = imread('searchObject.bmp'); G2 = squeeze(G2(:,:,1)); G4 = G2;
M = size(G1,1); N = size(G1,2);
scaleFactor = 0.25;
while scaleFactor <= 4
maxCorr=0;maxRow=0;maxCol=0;
for rotateFactor = 0:90:360
G2 = imresize(G4, scaleFactor);
G2 = imrotate(G2, rotateFactor);
G3 = zeros(M,N);
maskW = size(G2,1);
for row=floor(maskW/2)+1:M-floor(maskW/2)
for col=floor(maskW/2)+1:N-floor(maskW/2)
G3(row,col) = corr2(G1(row-floor(maskW/2):row+floor(maskW/2), ...
col-floor(maskW/2):col+floor(maskW/2)),G2);
end
end
for row=1:size(G3,1)
for col=1:size(G3,2)
if(G3(row,col)>maxCorr)
maxCorr = G3(row,col);
maxRow = row;
maxCol = col;
end
end
end
end
scaleFactor = scaleFactor + 1;
end
imshow(G1);
hold on;
plot(maxRow, maxCol, 'cx');
hold on;
plot([0 size(G1,1)], [maxRow maxRow], 'c-');
plot([maxCol maxCol], [0 size(G1,2)], 'c-');

1 Kommentar

Image Analyst
Image Analyst am 20 Dez. 2014
I answered your last question (thanks for accepting it) but you edited it away - those kinds of behaviors don't really entice people to answer you anymore.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Interactions, Camera Views, and Lighting finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 17 Dez. 2014

Kommentiert:

am 20 Dez. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by