Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / imageAnalysis / calibrateRegression / CalibrateRegressionAlgorithm.java @ 59

History | View | Annotate | Download (3.04 KB)

1
package es.unex.sextante.imageAnalysis.calibrateRegression;
2

    
3
import es.unex.sextante.core.GeoAlgorithm;
4
import es.unex.sextante.core.Sextante;
5
import es.unex.sextante.dataObjects.IRasterLayer;
6
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
7
import es.unex.sextante.exceptions.RepeatedParameterNameException;
8
import es.unex.sextante.math.regression.Regression;
9

    
10
public class CalibrateRegressionAlgorithm
11
         extends
12
            GeoAlgorithm {
13

    
14
   public static final String CALIBRATED = "CALIBRATED";
15
   public static final String INPUT      = "INPUT";
16
   public static final String REF        = "REF";
17

    
18

    
19
   @Override
20
   public void defineCharacteristics() {
21

    
22
      setName(Sextante.getText("Calibrate_an_image__regression"));
23
      setUserCanDefineAnalysisExtent(false);
24
      setGroup(Sextante.getText("Image_processing"));
25

    
26
      try {
27
         m_Parameters.addInputRasterLayer(INPUT, Sextante.getText("Image_to_calibrate"), true);
28
         m_Parameters.addInputRasterLayer(REF, Sextante.getText("Reference_image"), false);
29
         addOutputRasterLayer(CALIBRATED, Sextante.getText("Calibrated_image"));
30
      }
31
      catch (final RepeatedParameterNameException e) {
32
         Sextante.addErrorToLog(e);
33
      }
34

    
35
   }
36

    
37

    
38
   @Override
39
   public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
40

    
41
      int x, y;
42
      int iNX, iNY;
43
      double dCellValue, dCellValue2;
44
      final Regression regression = new Regression();
45
      IRasterLayer input, ref;
46
      IRasterLayer output;
47

    
48
      input = m_Parameters.getParameterValueAsRasterLayer(INPUT);
49
      ref = m_Parameters.getParameterValueAsRasterLayer(REF);
50
      input.setFullExtent();
51
      ref.setWindowExtent(input.getWindowGridExtent());
52
      output = getNewRasterLayer(CALIBRATED, Sextante.getText("Calibrated_image"), input.getDataType(),
53
               input.getWindowGridExtent());
54
      if ((ref.getDataType() == IRasterLayer.RASTER_DATA_TYPE_INT) || (ref.getDataType() == IRasterLayer.RASTER_DATA_TYPE_SHORT)) {
55
         ref.setInterpolationMethod(IRasterLayer.INTERPOLATION_NearestNeighbour);
56
      }
57

    
58
      iNX = input.getNX();
59
      iNY = input.getNY();
60

    
61
      for (y = 0; (y < iNY) && setProgress(y, iNY); y++) {
62
         for (x = 0; x < iNX; x++) {
63
            dCellValue = input.getCellValueAsDouble(x, y);
64
            dCellValue2 = ref.getCellValueAsDouble(x, y);
65
            if (!input.isNoDataValue(dCellValue) && !ref.isNoDataValue(dCellValue2)) {
66
               regression.addValue(dCellValue, dCellValue2);
67
            }
68
         }
69

    
70
      }
71

    
72
      regression.calculate();
73

    
74
      for (y = 0; (y < iNY) && setProgress(y, iNY); y++) {
75
         for (x = 0; x < iNX; x++) {
76
            dCellValue = input.getCellValueAsDouble(x, y);
77
            if (input.isNoDataValue(dCellValue)) {
78
               output.setNoData(x, y);
79
            }
80
            else {
81
               output.setCellValue(x, y, regression.getY(dCellValue));
82
            }
83
         }
84

    
85
      }
86

    
87
      return !m_Task.isCanceled();
88

    
89

    
90
   }
91

    
92
}