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 package org.openimaj.image.processing.transform;
31
32 import java.util.HashMap;
33 import java.util.Map;
34
35 import org.openimaj.image.FImage;
36 import org.openimaj.math.geometry.point.Point2d;
37 import org.openimaj.math.geometry.point.Point2dImpl;
38 import org.openimaj.math.geometry.shape.Shape;
39
40
41
42
43
44
45
46
47 public class FProjectionProcessor extends ProjectionProcessor<Float, FImage> {
48
49
50
51
52
53
54
55
56
57
58
59 @Override
60 public FImage performProjection(int windowMinC , int windowMaxC , int windowMinR , int windowMaxR , Float backgroundColour) {
61 FImage output = null;
62 output = new FImage(windowMaxC-windowMinC,windowMaxR-windowMinR);
63 if(backgroundColour!=null)
64 output.fill(backgroundColour);
65 Shape[][] shapeRects = this.getCurrentShapes();
66 for(int y = 0; y < output.getHeight(); y++)
67 {
68 for(int x = 0; x < output.getWidth(); x++){
69 Point2d realPoint = new Point2dImpl(windowMinC + x,windowMinR + y);
70 int i = 0;
71 for (int j = 0; j < shapeRects.length; j++) {
72 if(backgroundColour == null || isInside(j,shapeRects,realPoint)){
73 double[][] transform = this.transformsInverted.get(i).getArray();
74
75 float xt = (float)transform[0][0] * realPoint.getX() + (float)transform[0][1] * realPoint.getY() + (float)transform[0][2];
76 float yt = (float)transform[1][0] * realPoint.getX() + (float)transform[1][1] * realPoint.getY() + (float)transform[1][2];
77 float zt = (float)transform[2][0] * realPoint.getX() + (float)transform[2][1] * realPoint.getY() + (float)transform[2][2];
78
79 xt /= zt;
80 yt /= zt;
81 FImage im = this.images.get(i);
82 if(backgroundColour!=null)
83 output.pixels[y][x] = im.getPixelInterp(xt, yt,backgroundColour);
84 else
85 output.pixels[y][x] = im.getPixelInterp(xt, yt);
86 }
87 i++;
88 }
89 }
90 }
91 return output;
92 }
93
94
95
96
97
98
99
100
101
102
103
104 @Override
105 public FImage performBlendedProjection(int windowMinC , int windowMaxC , int windowMinR , int windowMaxR , Float backgroundColour) {
106 FImage output = null;
107 output = new FImage(windowMaxC-windowMinC,windowMaxR-windowMinR);
108 Map<Integer,Boolean> setMap = new HashMap<Integer,Boolean>();
109 FImage blendingPallet = output.newInstance(2, 1);
110 for(int y = 0; y < output.getHeight(); y++)
111 {
112 for(int x = 0; x < output.getWidth(); x++){
113 Point2d realPoint = new Point2dImpl(windowMinC + x,windowMinR + y);
114 int i = 0;
115 for(Shape s : this.projectedShapes){
116 if(s.isInside(realPoint)){
117 double[][] transform = this.transformsInverted.get(i).getArray();
118
119 float xt = (float)transform[0][0] * realPoint.getX() + (float)transform[0][1] * realPoint.getY() + (float)transform[0][2];
120 float yt = (float)transform[1][0] * realPoint.getX() + (float)transform[1][1] * realPoint.getY() + (float)transform[1][2];
121 float zt = (float)transform[2][0] * realPoint.getX() + (float)transform[2][1] * realPoint.getY() + (float)transform[2][2];
122
123 xt /= zt;
124 yt /= zt;
125 Float toSet = null;
126 if(backgroundColour!=null)
127 toSet = this.images.get(i).getPixelInterp(xt, yt,backgroundColour);
128 else
129 if(setMap.get(y * output.getWidth() + x)!=null)
130 toSet = this.images.get(i).getPixelInterp(xt, yt,output.getPixelInterp(x, y));
131 else
132 toSet = this.images.get(i).getPixelInterp(xt, yt);
133
134 if(setMap.get(y * output.getWidth() + x)!=null){
135 blendingPallet.pixels[0][1] = toSet;
136 blendingPallet.pixels[0][0] = output.getPixel(x, y);
137
138 toSet = blendingPallet.getPixelInterp(0.1, 0.5);
139 }
140 setMap.put(y * output.getWidth() + x,true);
141 output.pixels[y][x] = toSet;
142 }
143 i++;
144 }
145 }
146 }
147 return output;
148 }
149
150 }