Represent a cross correlation as a mesh using imagesc() and mesh()

조회 수: 1 (최근 30일)
Aaron Elliott
Aaron Elliott 2020년 11월 1일
Hi all,
I am doing template matching and trying to represent the cross correlaiton as a mesh using mesh() and imagesc(). The current code I have displays a mesh for a breif second but I don't think its correct. Any help/pointers would be much appreciated!
function BB = templateMatching(I,template)
I = im2gray(I);
template = im2gray(template);
[Ix, Iy] = size(I);
[Tx, Ty] = size(template);
map = normxcorr2(template, I)
map = imcrop(map,[Ty Tx Iy Ix]);
mesh(map)
max_num = max(max(map));
[r, c, v] = find(map==max_num);
BB = insertShape(I, 'rectangle', [c r Ty Tx], 'LineWidth', 3);
end
% task file is below
clear all
close all
letters = imread('letters.JPG');
k = imread('K.JPG');
im1 = imread('image1.jpg');
im2 = imread('image2.jpg');
match1 = templateMatching(letters, k);
match2 = templateMatching(im1, im2);
figure(1)
subplot(1,3,1), imshow(letters), title('Image')
subplot(1,3,2), imshow(k), title('Template')
subplot(1,3,3), imshow(match1), title('BB')
figure(2)
subplot(1,3,1), imshow(im1), title('Image')
subplot(1,3,2), imshow(im2), title('Template')
subplot(1,3,3), imshow(match2), title('BB')

답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by