summaryrefslogtreecommitdiff
path: root/macros/TemplateMatcher.sci
blob: d5e60d8a09183eaf2333f1531f992e8b9dae20b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function new_image = TemplateMatcher(image, template_image, varargin)
// Compares a template in overlapped image regions
//
// Calling Sequence
// newimage = TemplateMatcher(image, template_image)
// 
// Parameters
// image : 8-bit or 32-bit floating image
// template_image : Searched template. It must not be greater than the source image and have the same data type of input image.
// newimage : Map of comparison results. It must be single channel 32-bit floating-point. Its size is (W-w+1) * (H-h+1) if image is W * H and template_image is w * h
//
// Description
// The function compares the w * h sized images of the original image against the template image and stores the result in the new_image.
//
// Examples
// I = imread('cameraman.tif');
// Igray = rgb2gray(I);
// T = Igray(20:75, 90:135);
// J = TemplateImage(I, T);
// imshow(J);
//
// Authors
// Suraj Prakash


		[ lhs rhs ] = argn(0)
		if lhs > 1 then
			error(msprintf("Too many output argument"))
		end
		
		if rhs > 2 then
			error(msprintf("Too many input arguments"))
		end	
		
		[imagerows imagecols imagechannel] = size(image)
		[t_rows t_cols t_channel] = size(template_image)
		if t_rows > imagerows | t_cols > imagecols then
			error(msprintf("Template image is greater than image\n"))
		end
		
		image_list = mattolist(image)
		template_image_list = mattolist(template_image)
		
		if rhs == 2 then
			
			temp = opencv_TemplateMatcher(image_list, template_image_list)
		
		elseif rhs == 3 then
			
			temp = opencv_TemplateMatcher(image_list, template_image_list, varargin(1))
		
		end
		
		sz = size(temp)
		
		for i=1 : sz
			new_image(:, :, i) = temp(i)
		end
		
endfunction