Onload="dp.SyntaxHighlighter.HighlightAll('code');"

티스토리 툴바

matlab 을 이용하여
Target image 에서 template image 의 NCC (normalized cross correlation) 분석

normxcorr2  명령을 사용하여 NCC의 수행이 가능하다.


ex)

clear all; clc; close all;

%% 이미지가 너무 크므로 작게 자르고 template 과 scene image 를 분리
template = rgb2gray(imread('onion.png'));
scene = rgb2gray(imread('peppers.png'));

rect_template = [111 33 65 58];
rect_scene = [163 47 143 151];
template = imcrop(template,rect_template);
scene = imcrop(scene,rect_scene);

figure, imshow(template)
figure, imshow(scene)
%% NCC
c = normxcorr2(template,scene);
figure, surf(c), shading flat
%%
[max_c, imax] = max(abs(c(:)));
[row_peak, column_peak] = ind2sub(size(c),imax);

row_begin = row_peak-size(template,1)+1;
row_end   = row_peak;
column_begin = column_peak-size(template,2)+1;
column_end   = column_peak;

recovered_template = scene;
recovered_template(row_begin:row_end,column_begin:column_end) = template;

recovered_template(row_begin:row_end ,column_begin)=0;
recovered_template(row_end           ,column_begin:column_end)=0;
recovered_template(row_begin:row_end ,column_end)=0;
recovered_template(row_begin,column_begin:column_end)=0;


figure, imshow(recovered_template)




 

 

Posted by 청곰

Trackback Address :: http://bluebearworld.tistory.com/trackback/47 관련글 쓰기

댓글을 달아 주세요