%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Matching an image using naive exhaustive search% % % %Hao Jiang, Oct 2007 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% im = imread('spider1.bmp'); im = im2double(im); figure(1); imshow(im); % extracts the top-left and bottom-right corner of the template [x,y] = ginput(2); x = floor(x); y = floor(y); imb = zeros(max(y)-min(y)+1, max(x)-min(x)+1, 3); imb(:,:,1) = im(min(y):max(y), min(x):max(x), 1); imb(:,:,2) = im(min(y):max(y), min(x):max(x), 2); imb(:,:,3) = im(min(y):max(y), min(x):max(x), 3); im_template = imb; [tph, tpw, tpd] = size(im_template); pp = [x(1), y(1); x(1) + tpw - 1, y(1);... x(1) + tpw - 1, y(1) + tph - 1;... x(1), y(1) + tph - 1]; hold on; plot([pp(:,1); pp(1,1)], [pp(:,2); pp(1,2)], 'LineWidth', 3, 'Color', [1,0,0]); hold off; im_target = imread('spider2.bmp'); im_target = im2double(im_target); figure(2); imshow(im_target); hold on; tic % Exhaustive search. pp is the bounding box of the match result. pp = locate_imageblock(im_template, im_target); toc plot([pp(:,1); pp(1,1)], [pp(:,2); pp(1,2)], 'LineWidth', 3); hold off;