summaryrefslogtreecommitdiff
path: root/macros/bagOfFeatures.sci
blob: 480d775c1a29334f34f57cc94cb3846d21b7ffad (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
function [bag]=bagOfFeatures(imageSet,varargin)
// This function is used to create a Bag-of-Words model (BoW model).
//
// Calling Sequence
//   bag = bagOfFeatures(imgSet);
//   bag = bagOfFeatures(imgSet, Name, Value, ...);
//
// Parameters
// bag: Bag of visual words
// imgSet: An imageSet structure
// VocabularySize: (Optional) Number of visual words (Default- 500)
// StrongestFeatures: (Optional) Fraction of strongest features (Default- 1.0)
// Upright: (Optional) Orientation of SURF feature vector (Default- true)
// Verbose: (Optional) Enable progress display to screen (Default- true)
//
// Description
// BoW model is applied to classify images by treating image features as words. The bagOfFeatures object contains a bag of visual words that help in image classification.
//
// Examples
// imgSet = imageSet(directory,'recursive');
// [trainingSet testSet] = partition(imgSet,[0.8]);
// bag = bagOfFeatures(trainingSet);
//
// Authors
//  Rohit Suri
//  Umang Agrawal

    [lhs rhs]=argn(0);
    if lhs>1
         error(msprintf(" Too many output arguments"));
    elseif rhs<1
        error(msprintf("At least one argument is required"));
    elseif rhs>9
        error(msprintf(" Too many input arguments"));
    end
    imageSetList=imageSetToList(imageSet);
    select rhs
        case 1 then
            bagList=opencv_bagOfFeatures(imageSetList);
        case 3 then
            bagList=opencv_bagOfFeatures(imageSetList,varargin(1),varargin(2));
        case 5 then
            bagList=opencv_bagOfFeatures(imageSetList,varargin(1),varargin(2),varargin(3),varargin(4));
        case 7 then
            bagList=opencv_bagOfFeatures(imageSetList,varargin(1),varargin(2),varargin(3),varargin(4),varargin(5),varargin(6));
        case 9 then
            bagList=opencv_bagOfFeatures(imageSetList,varargin(1),varargin(2),varargin(3),varargin(4),varargin(5),varargin(6),varargin(7),varargin(8));
    end
    bag=struct('FilePath',bagList(2)(1,1),'VocabularySize',bagList(3)(1,1),'StrongestFeatures',bagList(4)(1,1),'Upright',bagList(5)(1,1));
endfunction