Object Detection using Template

- Main Page
- Packages
- Classes
- Files

- File List

All Classes Namespaces Files Functions Variables
ImageFacade.java
Go to the documentation of this file.
1 package cz.vutbr.feec.novak68.imageProcessor;
2
3 import ij.ImagePlus;
4 import ij.gui.NewImage;
5
6 import java.awt.Dimension;
7 import java.io.BufferedWriter;
8 import java.io.FileWriter;
9 import java.io.IOException;
10 import java.util.ArrayList;
11
12 import cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor;
13 import cz.vutbr.feec.novak68.rapidminer.MyProcess;
14 import cz.vutbr.feec.novak68.tools.Coordinate;
15
21 public class ImageFacade {
22 public static final Dimension IMAGE_BASE_SIZE = new Dimension(78,149);
23 private ImagePlus tempImage;
24 private Dimension rescaledSize = new Dimension();
25 private SimpleHogPropertyExtractor extractor;
26 private ImagePlus sourceImage;
27 private ArrayList<int []> possitions = new ArrayList<int []>();
28 private int posIndex = 0;
29 private BufferedWriter writer;
30 private BufferedWriter list;
31 private double scale;
32 private double step;
33 public double getStep() {
34 return step;
35 }
36 public void setStep(double step) {
37 this.step = rescaledSize.getWidth() * step;
38 }
39
40 public double getScale() {
41 return scale;
42 }
43 public void setScale(double scale) {
44 this.scale = scale;
45 rescaleSize();
46 }
47
48 // private FileSaver saver; //TODO smazat
49 //TODO (pretvorit HOG aby bral pouze cisla a z nich pocital HOG) ? Jak to udelat s ruznyma velikostma obrazku?
50
51 public ImageFacade (String pathToImage) throws IOException{
52 this(new ImagePlus(pathToImage));
53 }
54 public ImageFacade (ImagePlus sourceImage) throws IOException{
55 this(sourceImage,"separed.txt","list.txt");
56 }
57
58 public ImageFacade (ImagePlus sourceImage, String separedPath, String separedPathList) throws IOException{
59 this(sourceImage,new BufferedWriter(new FileWriter(separedPath)),new BufferedWriter(new FileWriter(separedPathList)),1.0,0.3);
60 }
66 public ImageFacade (ImagePlus sourceImage,double zoomOfHeight, double step){
67 double scale = sourceImage.getHeight() * zoomOfHeight;
68 scale = scale / IMAGE_BASE_SIZE.height;
69 this.sourceImage = sourceImage;
70 setScale(scale);
71 setStep(step);
72 extractor = new SimpleHogPropertyExtractor();
73 computePossitions();
74 tempImage = NewImage.createRGBImage("", IMAGE_BASE_SIZE.width, IMAGE_BASE_SIZE.height, 1, 0);
75
76 }
84 public ImageFacade (ImagePlus sourceImage, BufferedWriter separed, BufferedWriter separedList,double scale, double step){
85 this.sourceImage = sourceImage;
86 // this.writer = separed;
87 // this.list = separedList;
88 setScale(scale);
89 setStep(step);
90 extractor = new SimpleHogPropertyExtractor();
91 computePossitions();
92 tempImage = NewImage.createRGBImage("", IMAGE_BASE_SIZE.width, IMAGE_BASE_SIZE.height, 1, 0);
93 }
94
95 public void extractAll() throws IOException{
96 for (int [] position : possitions) {
97 extractor.extractProperies(getImage(position));
98 list.append("possition: " + position[0] +", " + position[1] + "\r\n");
99 list.flush();
100 }
101 }
102 public void extractAll(MyProcess process, boolean useVariance) throws IOException{
103 for (int [] item : possitions) {
104 // x_y_scale_step
105 String temp = String.format("%s_%s_%s", item[0],item[1],scale);
106 extractor.extractProperies(getImage(item),process,temp, useVariance);
107 }
108 }
109
110 public ImagePlus getImage (int [] position){
111 sourceImage.setRoi(position[0], position[1], rescaledSize.width, rescaledSize.height);
112 sourceImage.copy(false);
113 tempImage.setTitle(Integer.toString(position[0]) +"_"+ Integer.toString(position[1]) + "_S" + Double.toString(scale) );
114 tempImage.paste();
115 tempImage.saveRoi();
116 if (scale != 1)
117 tempImage.setImage(tempImage.getProcessor().resize(IMAGE_BASE_SIZE.width, IMAGE_BASE_SIZE.height).createImage());
118 tempImage.killRoi();
119 return tempImage;
120 }
124 public ImagePlus getNextImage(){
125 return hasNextImage()?getImage(possitions.get(posIndex++)) : null; //null? nebo vrátit prvni?
126 }
127 public boolean hasNextImage(){
128 if (posIndex+1 < possitions.size())
129 return true;
130 else{
131 clearPosIndex();
132 return false;
133 }
134 }
135
136 public void clearPosIndex(){posIndex = 0;}
137
138 private void rescaleSize () {
139 rescaledSize.setSize(IMAGE_BASE_SIZE.width * scale, IMAGE_BASE_SIZE.height * scale);
140 posIndex = 0;
141 }
142
143 private void computePossitions(){
144 Dimension imageDimension = new Dimension(sourceImage.getWidth(), sourceImage.getHeight());
145 //from left top
146 for (int x = 0; x < (imageDimension.width - rescaledSize.width); x += step)
147 for (int y = 0; y < (imageDimension.height - rescaledSize.height); y += step){
148 possitions.add(new int[]{x,y});
149 if (((x + rescaledSize.width * 0.5) < (imageDimension.width - rescaledSize.width)) && ((y + rescaledSize.height * 0.5) < (imageDimension.height - rescaledSize.height))){
150 possitions.add(new int[] {(int) Math.ceil(x + rescaledSize.width * 0.5), (int) Math.ceil(y + rescaledSize.height * 0.5)});
151 }
152 }
153 //from right bottom
154 for (int x = (imageDimension.width - rescaledSize.width); x > 0 ; x -= step)
155 for (int y = (imageDimension.height - rescaledSize.height); y > 0; y -= step){
156 possitions.add(new int[]{x,y});
157 if (((x - rescaledSize.width * 0.5) > 0) && ((y - rescaledSize.height * 0.5) > 0)){
158 possitions.add(new int[] {(int) Math.floor(x - rescaledSize.width * 0.5), (int) Math.floor(y - rescaledSize.height * 0.5)});
159 }
160 }
161 }
162 public ImagePlus getImage(Coordinate coordinate, ImagePlus srcImage){
163 ImagePlus result = new ImagePlus();
164 sourceImage.setRoi(coordinate.leftTop.x, coordinate.leftTop.y, coordinate.dimension.width, coordinate.dimension.height);
165 sourceImage.copy(false);
166 result.setTitle(Integer.toString(coordinate.leftTop.x) +"_"+ Integer.toString(coordinate.leftTop.y));
167 result.paste();
168 result.saveRoi();
169 if (scale != 1)
170 result.setImage(result.getProcessor().resize(IMAGE_BASE_SIZE.width, IMAGE_BASE_SIZE.height).createImage());
171 result.killRoi();
172 return result;
173 }
174
175
176 }
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.scale
double scale
Definition: ImageFacade.java:31
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.getImage
ImagePlus getImage(int[] position)
Definition: ImageFacade.java:110
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.setScale
void setScale(double scale)
Definition: ImageFacade.java:43
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.ImageFacade
ImageFacade(ImagePlus sourceImage, BufferedWriter separed, BufferedWriter separedList, double scale, double step)
Definition: ImageFacade.java:84
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.ImageFacade
ImageFacade(ImagePlus sourceImage)
Definition: ImageFacade.java:54
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.writer
BufferedWriter writer
Definition: ImageFacade.java:29
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.ImageFacade
ImageFacade(ImagePlus sourceImage, String separedPath, String separedPathList)
Definition: ImageFacade.java:58
cz.vutbr.feec.novak68.rapidminer.MyProcess
Definition: MyProcess.java:30
cz.vutbr.feec.novak68.tools.Coordinate
Definition: Coordinate.java:15
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.rescaledSize
Dimension rescaledSize
Definition: ImageFacade.java:24
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.IMAGE_BASE_SIZE
static final Dimension IMAGE_BASE_SIZE
Definition: ImageFacade.java:22
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.ImageFacade
ImageFacade(ImagePlus sourceImage, double zoomOfHeight, double step)
Definition: ImageFacade.java:66
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.possitions
ArrayList< int[]> possitions
Definition: ImageFacade.java:27
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.ImageFacade
ImageFacade(String pathToImage)
Definition: ImageFacade.java:51
cz.vutbr.feec.novak68.extractors.SimpleHogPropertyExtractor
Definition: SimpleHogPropertyExtractor.java:27
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.step
double step
Definition: ImageFacade.java:32
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.posIndex
int posIndex
Definition: ImageFacade.java:28
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.setStep
void setStep(double step)
Definition: ImageFacade.java:36
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.extractor
SimpleHogPropertyExtractor extractor
Definition: ImageFacade.java:25
cz.vutbr.feec.novak68.tools.Coordinate.leftTop
final Point leftTop
Definition: Coordinate.java:16
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.clearPosIndex
void clearPosIndex()
Definition: ImageFacade.java:136
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.computePossitions
void computePossitions()
Definition: ImageFacade.java:143
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.list
BufferedWriter list
Definition: ImageFacade.java:30
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.extractAll
void extractAll(MyProcess process, boolean useVariance)
Definition: ImageFacade.java:102
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.getImage
ImagePlus getImage(Coordinate coordinate, ImagePlus srcImage)
Definition: ImageFacade.java:162
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.tempImage
ImagePlus tempImage
Definition: ImageFacade.java:23
cz.vutbr.feec.novak68.imageProcessor.ImageFacade
Definition: ImageFacade.java:21
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.rescaleSize
void rescaleSize()
Definition: ImageFacade.java:138
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.extractAll
void extractAll()
Definition: ImageFacade.java:95
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.hasNextImage
boolean hasNextImage()
Definition: ImageFacade.java:127
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.sourceImage
ImagePlus sourceImage
Definition: ImageFacade.java:26
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.getScale
double getScale()
Definition: ImageFacade.java:40
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.getNextImage
ImagePlus getNextImage()
Definition: ImageFacade.java:124
cz.vutbr.feec.novak68.imageProcessor.ImageFacade.getStep
double getStep()
Definition: ImageFacade.java:33