Revision 18384 trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/georeferencing/geotransform/GeoTransformProcess.java
GeoTransformProcess.java | ||
---|---|---|
42 | 42 |
|
43 | 43 |
import org.gvsig.rastertools.RasterProcess; |
44 | 44 |
|
45 |
import Jama.Matrix; |
|
46 | 45 |
|
47 | 46 |
import com.iver.andami.PluginServices; |
48 | 47 |
|
48 |
import Jama.Matrix; |
|
49 |
|
|
49 | 50 |
/** |
50 | 51 |
* Clase que representa una transformacion polinomial para la convertir las |
51 | 52 |
* coordenadas de una imagen en la imagen rectificada. |
... | ... | |
61 | 62 |
// de momento geo_points puntos sobre imagen georeferenciada, image_points |
62 | 63 |
// puntos sobre imagen a georeferenciar. |
63 | 64 |
|
65 |
// Utilizar GeoPoint |
|
64 | 66 |
protected double geo_points[][]=new double[2][]; |
65 | 67 |
protected double image_points[][]=new double[2][]; |
66 | 68 |
|
... | ... | |
106 | 108 |
// Chequear si el numero de puntos es suficiente para determinar la transformacion de orden n. |
107 | 109 |
if(!enoughPoints()){ |
108 | 110 |
// NOTIFICAR, NO SUFICIENTES PUNTOS PARA ORDEN SELECCIONADO |
109 |
return; |
|
111 |
minGPC=0; |
|
112 |
// Detener ejecucion del calculo. |
|
113 |
|
|
110 | 114 |
} |
111 | 115 |
} |
112 | 116 |
|
... | ... | |
125 | 129 |
public void process() throws InterruptedException { |
126 | 130 |
// Obtencion polinomio de transformacion en x |
127 | 131 |
getPolinomyalCoefX(); |
128 |
|
|
129 | 132 |
// Obtencion del polinomio de transformaci?n en y |
130 | 133 |
getPolinomialCoefY(); |
131 |
|
|
134 |
// calculo de los resultados |
|
132 | 135 |
getRMSerror(); |
133 | 136 |
} |
134 | 137 |
|
135 | 138 |
|
136 | 139 |
/** |
137 | 140 |
* @return coeficientes para el polinomio de transformaci?n en x. |
138 |
* */
|
|
141 |
**/ |
|
139 | 142 |
public double[] getPolinomyalCoefX(){ |
140 | 143 |
if(coefX==null) |
141 | 144 |
setDxGeneral(); |
... | ... | |
183 | 186 |
} |
184 | 187 |
} |
185 | 188 |
Matrix matrixResult= new Matrix(matrixDx); |
186 |
try { |
|
187 |
coefX=solveSistemforCramer(matrixResult,result); |
|
188 |
} catch (BadDeteminantException e) { |
|
189 |
// Resolver sistema de ecuaciones o por otro metodo |
|
190 |
} |
|
189 |
coefX=solveSistem(matrixResult,result); |
|
191 | 190 |
} |
192 | 191 |
|
193 | 192 |
|
... | ... | |
221 | 220 |
} |
222 | 221 |
} |
223 | 222 |
Matrix matrixResult= new Matrix(matrixDy); |
224 |
try { |
|
225 |
coefY=solveSistemforCramer(matrixResult,result); |
|
226 |
} catch (BadDeteminantException e) { |
|
227 |
// Resolver sistema de ecuaciones opor otro metodo |
|
228 |
} |
|
223 |
coefY=solveSistem(matrixResult,result); |
|
229 | 224 |
} |
230 | 225 |
|
231 | 226 |
/** |
232 |
* Resoluci?n del sistema por la regla de Cramer. |
|
233 |
* @return array con la solucion al sistema de ecuadiones. |
|
227 |
* @return array con la solucion al sistema de ecuadiones. |
|
234 | 228 |
* */ |
235 |
public double[] solveSistemforCramer(Matrix matrix, double columResult[]) throws BadDeteminantException{
|
|
229 |
public double[] solveSistem(Matrix matrix, double columResult[]){
|
|
236 | 230 |
double xCoef []= new double[minGPC]; |
237 |
double det= matrix.det(); |
|
238 |
if(det==0) |
|
239 |
throw new BadDeteminantException(); |
|
240 |
double aux[][]= matrix.getArrayCopy(); |
|
241 |
Matrix m=null; |
|
242 |
|
|
243 |
// Resolucion del sistema por cramer |
|
244 |
for(int k=0; k<columResult.length; k++) |
|
245 |
{ |
|
246 |
for(int i=0;i<columResult.length;i++) |
|
247 |
aux[i][k]= columResult[i]; |
|
248 |
m= new Matrix (aux); |
|
249 |
xCoef[k]= m.det()/det; |
|
250 |
aux=matrix.getArrayCopy();; |
|
251 |
} |
|
231 |
double [][]a= new double[columResult.length][1]; |
|
232 |
for (int i=0; i<columResult.length;i++) |
|
233 |
a[i][0]=columResult[i]; |
|
234 |
Matrix c= matrix.solve(new Matrix(a)); |
|
235 |
for (int i=0; i<columResult.length;i++) |
|
236 |
xCoef[i]=c.get(i,0); |
|
252 | 237 |
return xCoef; |
253 | 238 |
} |
254 | 239 |
|
255 | 240 |
|
256 |
|
|
257 |
|
|
241 |
/** |
|
242 |
* @return vector con los RMS |
|
243 |
* */ |
|
258 | 244 |
public double[] getRMSerror(){ |
259 | 245 |
|
260 | 246 |
double xEvaluate[]= new double [image_points.length]; |
... | ... | |
262 | 248 |
rms = new double [image_points.length]; |
263 | 249 |
xError= new double [image_points.length]; |
264 | 250 |
yError= new double[image_points.length]; |
265 |
// Para cada punto en coordenadas pixel se obtiene su x e y corregido |
|
266 | 251 |
for(int im_point=0; im_point<image_points.length;im_point++){ |
267 | 252 |
|
268 | 253 |
for(int i=0; i<minGPC;i++) |
... | ... | |
276 | 261 |
yError[im_point]= Math.pow(yEvaluate[im_point] -image_points[im_point][1], 2); |
277 | 262 |
rms[im_point]=Math.sqrt |
278 | 263 |
( |
279 |
xError[im_point]+ yError[im_point] |
|
280 |
|
|
281 |
|
|
264 |
xError[im_point]+ yError[im_point] |
|
282 | 265 |
); |
283 | 266 |
|
284 |
|
|
285 | 267 |
} |
268 |
|
|
269 |
System.out.print("Base X\t\t"); |
|
270 |
System.out.print("Base Y\t\t"); |
|
271 |
System.out.print("WarpX\t\t"); |
|
272 |
System.out.print("WarpY\t\t"); |
|
273 |
System.out.print("PredicX\t\t\t\t"); |
|
274 |
System.out.print("PredicY\t\t\t\t"); |
|
275 |
System.out.print("ErrorX\t\t\t\t"); |
|
276 |
System.out.print("ErrorY\t\t\t\t"); |
|
277 |
System.out.print("RMS"); |
|
278 |
// Escriir resultados |
|
279 |
for(int i=0; i<image_points.length;i++) |
|
280 |
{ |
|
281 |
System.out.print("\n"); |
|
282 |
System.out.print((new Double(geo_points[i][0]).toString()+"\t\t")); |
|
283 |
System.out.print((new Double(geo_points[i][1]).toString()+"\t\t")); |
|
284 |
System.out.print((new Double(image_points[i][0]).toString()+"\t\t")); |
|
285 |
System.out.print((new Double(image_points[i][1]).toString()+"\t\t")); |
|
286 |
System.out.print((new Double(xEvaluate[i]).toString()+"\t\t")); |
|
287 |
System.out.print((new Double(yEvaluate[i]).toString()+"\t\t")); |
|
288 |
System.out.print((new Double(xError[i]).toString()+"\t\t")); |
|
289 |
System.out.print((new Double(yError[i]).toString()+"\t\t")); |
|
290 |
System.out.print((new Double(rms[i]).toString()+"\t\t")); |
|
291 |
|
|
292 |
} |
|
293 |
return rms; |
|
294 |
} |
|
295 |
|
|
296 |
|
|
297 |
/** |
|
298 |
* @return array con el error en la coordenada x para los puntos de entrada |
|
299 |
* |
|
300 |
* */ |
|
301 |
public double[] getxError(){ |
|
302 |
return xError; |
|
286 | 303 |
|
287 |
return rms; |
|
304 |
} |
|
305 |
|
|
306 |
/** |
|
307 |
* @return array con el error en la coordenada y para los puntos de entrada |
|
308 |
* |
|
309 |
* */ |
|
310 |
public double[] getyError(){ |
|
311 |
return xError; |
|
288 | 312 |
|
289 | 313 |
} |
290 | 314 |
|
315 |
|
|
316 |
|
|
317 |
/** |
|
318 |
* Funci?n que evalua el polinomio de transformaci?n para un punto especifico |
|
319 |
* @param x coordenada x del punto |
|
320 |
* @param y coordenada y del punto |
|
321 |
* @return resultado de la evaluaci?n |
|
322 |
* */ |
|
323 |
double[] evaluate(double x, double y){ |
|
324 |
double eval[]= new double [2]; |
|
325 |
for(int i=0; i<minGPC;i++) |
|
326 |
{ |
|
327 |
eval[0]+=coefX[i] * Math.pow(x, exp[i][0]) * Math.pow(y, exp[i][1]); |
|
328 |
eval[1]+=coefY[i] * Math.pow(x, exp[i][0]) * Math.pow(y, exp[i][1]); |
|
329 |
|
|
330 |
} |
|
331 |
return eval; |
|
332 |
} |
|
333 |
|
|
334 |
|
|
335 |
|
|
291 | 336 |
public String getTitle() { |
292 | 337 |
return PluginServices.getText(this,"transformacion"); |
293 | 338 |
} |
Also available in: Unified diff