summaryrefslogtreecommitdiff
path: root/macros/retrieveImages.sci
blob: 0c8f8a2fd86ba2a78f824fd05f2d8730b31200a1 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function [varargout] = retrieveImages(QueryImage, IndexImage, varargin)
// This function searches for similar image in a given image set
//
// Calling Sequence
// [imageID Score ImageWord] = retrieveImage(QueryImage, IndexImage, Name, Value... )
//
// Parameters
// 	QueryImage: The query image, for which the similar image has to be found. Can be a grayscale or a RGB image
//	IndexImage: imageIndex object that contains the data set of all the images to be compared
//	NumResults [Optional Input Argument]: Maximum number of results to be returned. Value: any integer (20 default)
//	ROI [Optional Input Argument]: Query Image search region. Format [ x y width height ]. Default: [1 1 size(Image,2) size(Image,1)]
//	imageID: M-by-1 vector consisting of Ranked Index of retrieved Images
//	Score: M-by-1 vector containing the similarity metric in the range 0 to 1
//	ImageWord: Visual Word mapped object for the Query Image
//
// Description
// Returns the indices corresponding to Images within imageIndex that are visually similar to the query Image
//
// Examples
// 		imgSet = imageSet(directory,'recursive');
//    [trainingSet testSet] = partition(imgSet,[0.8]);
//    bag = bagOfFeatures(trainingSet);
//    imageindex = indexImages(trainingSet, bag);
//		queryImage = imread('sample.jpg');
//		imageIDs = retrieveImages(queryImage, imageindex);
//
//	With Optional Arguments:
// 		imageIDs = retrieveImages(queryImage, imageindex, "NumResults", 10);
//
// Authors
//  Umang Agrawal
//	Rohit Suri

	/// varargout(1) = index
	/// varargout(2) = score
	/// varargout(3) = Imageword

	[ lhs rhs ] = argn(0)

	if rhs > 6 then
		error(msprintf("Too many input arguments"))
	end

	if lhs > 3 then
		error(msprintf("Too many output arguments"))
	end

	QueryImage_list = mattolist(QueryImage)

	if lhs == 1 then
		select rhs
			case 2 then

				index = opencv_retrieveImages(QueryImage_list, IndexImage)

			case 4 then

				index = opencv_retrieveImages(QueryImage_list, IndexImage, varargin(1), varargin(2))

			case 6 then
				index = opencv_retrieveImages(QueryImage_list, IndexImage, varargin(1), varargin(2), varagin(3), varargin(4))
		end

		varargout(1) = index

	elseif lhs == 2 then
		select rhs
			case 2 then

				[index, score] = opencv_retrieveImages(QueryImage_list, IndexImage)

			case 4 then

				[index, score] = opencv_retrieveImages(QueryImage_list, IndexImage, varargin(1), varargin(2))

			case 6 then
				[index, score] = opencv_retrieveImages(QueryImage_list, IndexImage, varargin(1), varargin(2), varagin(3), varargin(4))
		end

		varargout(1) = temp
		varargout(2) = score

	elseif lhs == 3 then
		select rhs
			case 2 then

				[index, score, Imageword] = opencv_retrieveImages(QueryImage_list, IndexImage)

			case 4 then

				[index, score, Imageword] = opencv_retrieveImages(QueryImage_list, IndexImage, varargin(1), varargin(2))

			case 6 then
				[index, score, Imageword] = opencv_retrieveImages(QueryImage_list, IndexImage, varargin(1), varargin(2), varagin(3), varargin(4))
		end

		varargout(1) = index
		varargout(2) = score
		del = struct("WordIndex", Imageword(1), "Location", Imageword(2), "Vocab_size", Imageword(3), "Count", Imageword(4))
		varargout(3) = del
	end

endfunction