root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / mosaic / process / HistogramMatchProcess.java @ 22800
History | View | Annotate | Download (7.64 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Iba?ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.mosaic.process; |
42 |
|
43 |
import java.io.File; |
44 |
import java.io.IOException; |
45 |
|
46 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
47 |
import org.gvsig.raster.RasterProcess; |
48 |
import org.gvsig.raster.buffer.BufferFactory; |
49 |
import org.gvsig.raster.buffer.RasterBuffer; |
50 |
import org.gvsig.raster.buffer.WriterBufferServer; |
51 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
52 |
import org.gvsig.raster.dataset.IBuffer; |
53 |
import org.gvsig.raster.dataset.IRasterDataSource; |
54 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
55 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
56 |
import org.gvsig.raster.datastruct.Histogram; |
57 |
import org.gvsig.raster.grid.filter.RasterFilter; |
58 |
import org.gvsig.raster.grid.filter.histogramMatching.HistogramMatchingByteFilter; |
59 |
import org.gvsig.raster.util.RasterToolsUtil; |
60 |
|
61 |
import com.iver.andami.PluginServices; |
62 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
63 |
|
64 |
|
65 |
/**
|
66 |
* Clase que implementa el proceso de Histogram Matching para un conjuto de imagenes
|
67 |
* que se quieren hacer corresponder con un histogram de referencia. El proceso tomara como parametros
|
68 |
* un conjunto de capas y un histograma maestro y ejecutara de forma secuencial un filtro de histogramMatch
|
69 |
* para cada una de ellas. El proceso se realiza sobre las bandas de visulaizaci?n.
|
70 |
*
|
71 |
* @params
|
72 |
* <LI>FLyrRasterSE[] "inputRasterLayers": Capas raster de entrada</LI>
|
73 |
* <LI>Histogram "masterHistogram": Histograma con el que se hace la correspondencia</LI>
|
74 |
* <LI>int "numbandas": PROVISIONAL.</LI>
|
75 |
* <LI>String "outputPath": Ruta completa al fichero de salida del proceso</LI>
|
76 |
*
|
77 |
* @result
|
78 |
* <LI>outputRassterLayers[]: Capas raster resultantes</LI>
|
79 |
*
|
80 |
* par histograma source - histograma referencia.
|
81 |
*
|
82 |
* @author aMu?oz (alejandro.mu?oz@uclm.es)
|
83 |
* @version 30/4/2008
|
84 |
* */
|
85 |
public class HistogramMatchProcess extends RasterProcess{ |
86 |
|
87 |
private FLyrRasterSE inputRasterLayers[] = null; |
88 |
private FLyrRasterSE outputRassterLayers[] = null; |
89 |
private Histogram histogramMaster = null; |
90 |
private String layerInProcess = null; |
91 |
private int countInProcess = 0,totalcount= 0; |
92 |
private int numbands = 0; |
93 |
private RasterFilter filtro = new HistogramMatchingByteFilter(); |
94 |
private IBuffer rasterResult = null; |
95 |
private WriterBufferServer writerBufferServer = null; |
96 |
private String path = null; |
97 |
|
98 |
|
99 |
/** Metodo en el que se recogen los par?metros para el proceso
|
100 |
* layers conjunto de capas a las que se aplica el proceso
|
101 |
* histogramMaster histograma de referencia
|
102 |
* view vista sobre la que se cargan los resultados
|
103 |
* */
|
104 |
|
105 |
public void init() { |
106 |
inputRasterLayers =(FLyrRasterSE []) getParam("inputRasterLayers"); |
107 |
outputRassterLayers = new FLyrRasterSE[inputRasterLayers.length];
|
108 |
histogramMaster= (Histogram) getParam("masterHistogram");
|
109 |
numbands = ((Integer)getParam("numbands")).intValue(); //****************************** |
110 |
path = (String) getStringParam("outputPath"); |
111 |
} |
112 |
|
113 |
|
114 |
/** Proceso.
|
115 |
* Para cada capa de las contenidas en layers, se aplica un filtro de histogramMatching
|
116 |
* entre la capa y el histograma de referencia pasado como paramero.
|
117 |
* */
|
118 |
public void process() throws InterruptedException { |
119 |
try{
|
120 |
int k=0; |
121 |
totalcount= inputRasterLayers.length-1;
|
122 |
for (int i=0; i< inputRasterLayers.length;i++){ |
123 |
// Para el resto de los histogramas seleccionados
|
124 |
if(inputRasterLayers[i]!=null){ |
125 |
k++; |
126 |
layerInProcess= inputRasterLayers[i].getName(); |
127 |
IRasterDataSource dsetCopy = null;
|
128 |
dsetCopy = inputRasterLayers[i].getDataSource().newDataset(); |
129 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy);
|
130 |
bufferFactory.setDrawableBands(inputRasterLayers[i].getRenderBands()); |
131 |
if (!RasterBuffer.loadInMemory(dsetCopy))
|
132 |
bufferFactory.setReadOnly(true);
|
133 |
bufferFactory.setAreaOfInterest(); |
134 |
filtro.addParam("raster",bufferFactory.getRasterBuf());
|
135 |
filtro.addParam("histogramReference",histogramMaster);
|
136 |
filtro.addParam("numbands",new Integer(numbands)); |
137 |
filtro.addParam("filterName",new String("histogram")); |
138 |
filtro.execute(); |
139 |
rasterResult=(RasterBuffer) filtro.getResult("raster");
|
140 |
outputRassterLayers[i] = createLayer(path + File.separator + "hist" + i + ".tif",i); |
141 |
} |
142 |
} |
143 |
|
144 |
}catch (Exception e2) { |
145 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "filter_error"), this, e2); |
146 |
} |
147 |
finally{
|
148 |
externalActions.end(outputRassterLayers); |
149 |
} |
150 |
|
151 |
} |
152 |
|
153 |
|
154 |
|
155 |
public String getTitle() { |
156 |
return PluginServices.getText(this,"histohramMatchProcess"); |
157 |
} |
158 |
|
159 |
public int getPercent() { |
160 |
if(writerBufferServer!=null) |
161 |
return writerBufferServer.getPercent();
|
162 |
else
|
163 |
return filtro.getPercent();
|
164 |
} |
165 |
|
166 |
/** log con la informaci?n del proceso */
|
167 |
public String getLog(){ |
168 |
return PluginServices.getText(this,"hiatogramMatchLog")+layerInProcess+" ("+countInProcess+"/"+totalcount+")"; |
169 |
|
170 |
} |
171 |
|
172 |
|
173 |
public FLyrRasterSE createLayer(String path, int i){ |
174 |
|
175 |
FLyrRasterSE lyr = null;
|
176 |
try{
|
177 |
if(path==null) |
178 |
return null; |
179 |
GeoRasterWriter grw = null;
|
180 |
writerBufferServer = new WriterBufferServer(rasterResult);
|
181 |
grw = GeoRasterWriter.getWriter(writerBufferServer, path, rasterResult.getBandCount(),inputRasterLayers[i].getAffineTransform(), rasterResult.getWidth(), rasterResult.getHeight(), rasterResult.getDataType(), GeoRasterWriter.getWriter(path).getParams(), inputRasterLayers[i].getProjection()); |
182 |
|
183 |
grw.dataWrite(); |
184 |
grw.setWkt(inputRasterLayers[i].getWktProjection()); |
185 |
grw.writeClose(); |
186 |
rasterResult.free(); |
187 |
|
188 |
int endIndex = path.lastIndexOf("."); |
189 |
if (endIndex < 0) |
190 |
endIndex = path.length(); |
191 |
lyr = FLyrRasterSE.createLayer( |
192 |
path.substring(path.lastIndexOf(File.separator) + 1, endIndex), |
193 |
path, |
194 |
null
|
195 |
); |
196 |
|
197 |
} catch (NotSupportedExtensionException e) {
|
198 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer_notsupportedextension"), this, e); |
199 |
} catch (RasterDriverException e) {
|
200 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e); |
201 |
} catch (IOException e) { |
202 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e); |
203 |
} catch (InterruptedException e) { |
204 |
Thread.currentThread().interrupt();
|
205 |
} catch (LoadLayerException e) {
|
206 |
RasterToolsUtil.messageBoxError("error_cargar_capa", this, e); |
207 |
} |
208 |
return lyr;
|
209 |
} |
210 |
|
211 |
|
212 |
public Object getResult() { |
213 |
return outputRassterLayers;
|
214 |
} |
215 |
|
216 |
} |