Object Detection using Template

- Main Page
- Packages
- Classes
- Files

- File List

All Classes Namespaces Files Functions Variables
SimpleHogPropertyExtractor.java
Go to the documentation of this file.
1 package cz.vutbr.feec.novak68.extractors;
2
3 import ij.ImagePlus;
4
5 import java.io.BufferedWriter;
6 import java.io.IOException;
7
8 import cz.vutbr.feec.novak68.HOG;
9 import cz.vutbr.feec.novak68.hogcomparators.AllElementComparator;
10 import cz.vutbr.feec.novak68.hogcomparators.HorizontalElementComparator;
11 import cz.vutbr.feec.novak68.hogcomparators.OtherElementComparator;
12 import cz.vutbr.feec.novak68.hogcomparators.SimpleHogComparator;
13 import cz.vutbr.feec.novak68.hogcomparators.SimpleSthrenghtHOGComparator;
14 import cz.vutbr.feec.novak68.hogcomparators.SimpleSymetryComparator;
15 import cz.vutbr.feec.novak68.hogcomparators.SimpleXSymetryComparator;
16 import cz.vutbr.feec.novak68.hogcomparators.SimpleYSymetryComparator;
17 import cz.vutbr.feec.novak68.hogcomparators.VerticalElementComparator;
18 import cz.vutbr.feec.novak68.hogfilters.HOGFilter;
19 import cz.vutbr.feec.novak68.hogfilters.StrengthElementFilter;
20 import cz.vutbr.feec.novak68.rapidminer.MyProcess;
21 import cz.vutbr.feec.novak68.tools.VarianceComputer;
22
27 public class SimpleHogPropertyExtractor extends HOGbaseExtractor{
28
29 // comparators
30 private SimpleHogComparator simpleC;
31 private SimpleSthrenghtHOGComparator strenghtC;
32 private SimpleSymetryComparator symetryC;
33 private SimpleXSymetryComparator xSymetryC;
34 private SimpleYSymetryComparator ySymetryC;
35 private AllElementComparator allElementC;
36 private HorizontalElementComparator hElementC;
37 private VerticalElementComparator vElementC;
38 private OtherElementComparator otherElementC;
39 private SimpleHOGbinExtractor binExtractor;
40 private SimpleHOGcellExtractor cellExtractor;
41 private VarianceComputer variance;
42
46 public SimpleHogPropertyExtractor(BufferedWriter writer) {
47 this(120, 12, 12, 6, 1000, writer);
48 }
49 public SimpleHogPropertyExtractor() {
50 this(120, 12, 12, 6, 1000, null);
51 }
52
61 public SimpleHogPropertyExtractor(int width, int cellSizeX, int cellSizeY,
62 int numOfBins, int threshold, BufferedWriter writer) {
63 this.width = width;
64 this.cellSizeX = cellSizeX;
65 this.cellSizeY = cellSizeY;
66 this.numOfBins = numOfBins;
67 this.output = writer;
68
69 ImagePlus img = new ImagePlus("data/pedestrian/train/images2.jpg");
70 img = new ImagePlus("Resized", img.getProcessor().resize(width));
71
72 // apply HOG
73 hogTemplate = new HOG(img, cellSizeX, cellSizeY, numOfBins);
74 hogTemplate.compute();
75
76 simpleC = new SimpleHogComparator();
77 // strenghtC = new SimpleSthrenghtHOGComparator();
78 symetryC = new SimpleSymetryComparator(threshold);
79 xSymetryC = new SimpleXSymetryComparator(threshold);
80 ySymetryC = new SimpleYSymetryComparator(threshold);
81 allElementC = new AllElementComparator(threshold);
82 hElementC = new HorizontalElementComparator(threshold);
83 vElementC = new VerticalElementComparator(threshold);
84 otherElementC = new OtherElementComparator(threshold);
85 binExtractor = new SimpleHOGbinExtractor(threshold);
86 cellExtractor = new SimpleHOGcellExtractor(threshold);
87
88 //XXX
89 variance = new VarianceComputer();
90 }
91
92 public void extractProperies(ImagePlus img) throws IOException{
93 extractProperies(img, 't');
94 }
95 public void extractProperies(ImagePlus img, char folder)
96 throws IOException {
97
98 hogTest = new HOG(new ImagePlus("Resized", img.getProcessor().resize(
99 width)), cellSizeX, cellSizeY, numOfBins);
100 hogTest.compute(false);
101 HOGFilter filter = new StrengthElementFilter();
102 // hogTrain.showGradientX();
103 // hogTrain.showOrientation();
104 // hogTrain.showMagnification();
105 // hogTest.showGradientX();
106 // hogTest.showOrientation();
107 // hogTest.showMagnification();
108
109 StringBuilder finStr = new StringBuilder();
110 finStr.append("\"" + folder + "\"");
111 finStr.append(", ");
112 finStr.append("\"" + img.getTitle() + "\"");
113 finStr.append(", ");
114 // finStr.append(binExtractor.extractProperies(hogTest));
115 // finStr.append(", ");
116 // finStr.append(cellExtractor.extractProperies(hogTest));
117 // finStr.append(", ");
118 finStr.append(simpleC.getDistance(hogTemplate, hogTest));
119 finStr.append(", ");
120 // finStr.append(strenghtC.getDistance(hogTrain, hogTest));
121 // finStr.append(", ");
122 finStr.append(symetryC.getDistance(hogTemplate, hogTest));
123 finStr.append(", ");
124 finStr.append(xSymetryC.getDistance(hogTemplate, hogTest));
125 finStr.append(", ");
126 finStr.append(ySymetryC.getDistance(hogTemplate, hogTest));
127 finStr.append(", ");
128 finStr.append(allElementC.getDistance(hogTemplate, hogTest));
129 finStr.append(", ");
130 finStr.append(hElementC.getDistance(hogTemplate, hogTest));
131 finStr.append(", ");
132 finStr.append(vElementC.getDistance(hogTemplate, hogTest));
133 finStr.append(", ");
134 finStr.append(otherElementC.getDistance(hogTemplate, hogTest));
135 //XXX compute variance
136 finStr.append(", ");
137 finStr.append(variance.variance(img));
138 // pridan filter
139 // hogTest.useFilter(filter);
140 // hogTrain.useFilter(filter);
141 // finStr.append(", ");
142 // finStr.append(simpleC.getDistance(hogTrain, hogTest));
143 // finStr.append(", ");
144 // finStr.append(strenghtC.getDistance(hogTrain, hogTest));
145 // finStr.append(", ");
146 // finStr.append(symetryC.getDistance(hogTrain, hogTest));
147 // finStr.append(", ");
148 // finStr.append(xSymetryC.getDistance(hogTrain, hogTest));
149 // finStr.append(", ");
150 // finStr.append(ySymetryC.getDistance(hogTrain, hogTest));
151 // finStr.append(", ");
152 // finStr.append(allElementC.getDistance(hogTrain, hogTest));
153 // finStr.append(", ");
154 // finStr.append(hElementC.getDistance(hogTrain, hogTest));
155 // finStr.append(", ");
156 // finStr.append(vElementC.getDistance(hogTrain, hogTest));
157 // finStr.append(", ");
158 // finStr.append(otherElementC.getDistance(hogTrain, hogTest));
159 // finStr.append("; "); // na konci nema byt strednik
160
161 output.write(finStr.toString());
162 output.newLine();
163 output.flush();
164 }
165
166 @Override
167 public void extractProperies(ImagePlus img, MyProcess process, String coordinates, boolean useVariance)
168 throws IOException {
169
170 hogTest = new HOG(new ImagePlus("Resized", img.getProcessor().resize(
171 width)), cellSizeX, cellSizeY, numOfBins);
172 hogTest.compute(false);
173 HOGFilter filter = new StrengthElementFilter();
174 if (useVariance){
175 process.addValues("", coordinates, simpleC.getDistance(hogTemplate, hogTest),
176 symetryC.getDistance(hogTemplate, hogTest), (int)xSymetryC.getDistance(hogTemplate, hogTest),
177 (int)ySymetryC.getDistance(hogTemplate, hogTest), (int)allElementC.getDistance(hogTemplate, hogTest),
178 (int)hElementC.getDistance(hogTemplate, hogTest), (int)vElementC.getDistance(hogTemplate, hogTest),
179 (int)otherElementC.getDistance(hogTemplate, hogTest), variance.variance(img));
180 }
181 else{
182 process.addValues("", coordinates, simpleC.getDistance(hogTemplate, hogTest),
183 symetryC.getDistance(hogTemplate, hogTest), (int)xSymetryC.getDistance(hogTemplate, hogTest),
184 (int)ySymetryC.getDistance(hogTemplate, hogTest), (int)allElementC.getDistance(hogTemplate, hogTest),
185 (int)hElementC.getDistance(hogTemplate, hogTest), (int)vElementC.getDistance(hogTemplate, hogTest),
186 (int)otherElementC.getDistance(hogTemplate, hogTest));
187 }
188 }
189 }
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.cellExtractor
SimpleHOGcellExtractor cellExtractor
Definition: SimpleHogPropertyExtractor.java:40
cz.vutbr.feec.novak68.hogcomparators.SimpleXSymetryComparator
Definition: SimpleXSymetryComparator.java:10
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.SimpleHogPropertyExtractor
SimpleHogPropertyExtractor()
Definition: SimpleHogPropertyExtractor.java:49
cz.vutbr.feec.novak68.hogcomparators.SimpleSymetryComparator
Definition: SimpleSymetryComparator.java:10
cz.vutbr.feec.novak68.extractors.SimpleHOGbinExtractor
Definition: SimpleHOGbinExtractor.java:9
cz.vutbr.feec.novak68.hogcomparators.SimpleSymetryComparator.getDistance
double getDistance(HOG hog1, HOG hog2)
Definition: SimpleSymetryComparator.java:23
cz.vutbr.feec.novak68.rapidminer.MyProcess
Definition: MyProcess.java:30
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.allElementC
AllElementComparator allElementC
Definition: SimpleHogPropertyExtractor.java:35
cz.vutbr.feec.novak68.hogcomparators.SimpleXSymetryComparator.getDistance
double getDistance(HOG hog1, HOG hog2)
Definition: SimpleXSymetryComparator.java:20
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.vElementC
VerticalElementComparator vElementC
Definition: SimpleHogPropertyExtractor.java:37
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.binExtractor
SimpleHOGbinExtractor binExtractor
Definition: SimpleHogPropertyExtractor.java:39
cz.vutbr.feec.novak68.extractors.HOGbaseExtractor.hogTemplate
HOG hogTemplate
Definition: HOGbaseExtractor.java:12
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.symetryC
SimpleSymetryComparator symetryC
Definition: SimpleHogPropertyExtractor.java:32
cz.vutbr.feec.novak68.hogfilters.StrengthElementFilter
Definition: StrengthElementFilter.java:9
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.variance
VarianceComputer variance
Definition: SimpleHogPropertyExtractor.java:41
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor
Definition: SimpleHogPropertyExtractor.java:27
cz.vutbr.feec.novak68.extractors.HOGbaseExtractor.width
int width
Definition: HOGbaseExtractor.java:15
cz.vutbr.feec.novak68.extractors.SimpleHOGcellExtractor
Definition: SimpleHOGcellExtractor.java:8
cz.vutbr.feec.novak68.hogcomparators.AllElementComparator
Definition: AllElementComparator.java:9
cz.vutbr.feec.novak68.hogcomparators.HorizontalElementComparator
Definition: HorizontalElementComparator.java:10
cz.vutbr.feec.novak68.hogcomparators.OtherElementComparator.getDistance
double getDistance(HOG hog1, HOG hog2)
Definition: OtherElementComparator.java:18
cz.vutbr.feec.novak68.extractors.HOGbaseExtractor
Definition: HOGbaseExtractor.java:11
cz.vutbr.feec.novak68.extractors.HOGbaseExtractor.cellSizeY
int cellSizeY
Definition: HOGbaseExtractor.java:17
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.extractProperies
void extractProperies(ImagePlus img, char folder)
Definition: SimpleHogPropertyExtractor.java:95
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.ySymetryC
SimpleYSymetryComparator ySymetryC
Definition: SimpleHogPropertyExtractor.java:34
cz.vutbr.feec.novak68.hogcomparators.SimpleYSymetryComparator.getDistance
double getDistance(HOG hog1, HOG hog2)
Definition: SimpleYSymetryComparator.java:20
cz.vutbr.feec.novak68.extractors.HOGbaseExtractor.hogTest
HOG hogTest
Definition: HOGbaseExtractor.java:13
cz.vutbr.feec.novak68.tools.VarianceComputer
Definition: VarianceComputer.java:9
cz.vutbr.feec.novak68.hogcomparators.OtherElementComparator
Definition: OtherElementComparator.java:9
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.extractProperies
void extractProperies(ImagePlus img, MyProcess process, String coordinates, boolean useVariance)
Definition: SimpleHogPropertyExtractor.java:167
cz.vutbr.feec.novak68.extractors.HOGbaseExtractor.numOfBins
int numOfBins
Definition: HOGbaseExtractor.java:18
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.simpleC
SimpleHogComparator simpleC
Definition: SimpleHogPropertyExtractor.java:30
cz.vutbr.feec.novak68.hogcomparators.VerticalElementComparator
Definition: VerticalElementComparator.java:10
cz.vutbr.feec.novak68.hogcomparators.SimpleYSymetryComparator
Definition: SimpleYSymetryComparator.java:10
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.SimpleHogPropertyExtractor
SimpleHogPropertyExtractor(BufferedWriter writer)
Definition: SimpleHogPropertyExtractor.java:46
cz.vutbr.feec.novak68.hogcomparators.VerticalElementComparator.getDistance
double getDistance(HOG hog1, HOG hog2)
Definition: VerticalElementComparator.java:19
cz.vutbr.feec.novak68.hogcomparators.SimpleSthrenghtHOGComparator
Definition: SimpleSthrenghtHOGComparator.java:11
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.xSymetryC
SimpleXSymetryComparator xSymetryC
Definition: SimpleHogPropertyExtractor.java:33
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.otherElementC
OtherElementComparator otherElementC
Definition: SimpleHogPropertyExtractor.java:38
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.SimpleHogPropertyExtractor
SimpleHogPropertyExtractor(int width, int cellSizeX, int cellSizeY, int numOfBins, int threshold, BufferedWriter writer)
Definition: SimpleHogPropertyExtractor.java:61
cz.vutbr.feec.novak68.extractors.HOGbaseExtractor.cellSizeX
int cellSizeX
Definition: HOGbaseExtractor.java:16
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.extractProperies
void extractProperies(ImagePlus img)
Definition: SimpleHogPropertyExtractor.java:92
cz.vutbr.feec.novak68.hogfilters.HOGFilter
Definition: HOGFilter.java:8
cz.vutbr.feec.novak68.hogcomparators.SimpleHogComparator
Definition: SimpleHogComparator.java:8
cz.vutbr.feec.novak68.HOG
Definition: HOG.java:19
cz.vutbr.feec.novak68.hogcomparators.HorizontalElementComparator.getDistance
double getDistance(HOG hog1, HOG hog2)
Definition: HorizontalElementComparator.java:19
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.strenghtC
SimpleSthrenghtHOGComparator strenghtC
Definition: SimpleHogPropertyExtractor.java:31
cz.vutbr.feec.novak68.hogcomparators.AllElementComparator.getDistance
double getDistance(HOG hog1, HOG hog2)
Definition: AllElementComparator.java:18
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor.hElementC
HorizontalElementComparator hElementC
Definition: SimpleHogPropertyExtractor.java:36