Revision 20685
trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/mosaic/process/HistogramMatchingProcess.java | ||
---|---|---|
50 | 50 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
51 | 51 |
import org.gvsig.raster.buffer.WriterBufferServer; |
52 | 52 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
53 |
import org.gvsig.raster.dataset.IBuffer; |
|
54 | 53 |
import org.gvsig.raster.dataset.IRasterDataSource; |
55 | 54 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
56 | 55 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
... | ... | |
125 | 124 |
if (!RasterBuffer.loadInMemory(dsetCopy)) |
126 | 125 |
bufferFactory.setReadOnly(true); |
127 | 126 |
|
128 |
//sourceGrid= rasterSource.getRender().getGrid(); |
|
129 | 127 |
sourceGrid = new Grid(bufferFactory,rasterSource.getRenderBands()); |
130 | 128 |
gridResult = new Grid(sourceGrid.getGridExtent(), sourceGrid.getGridExtent(),sourceGrid.getDataType(), new int[]{0,1,2}); |
131 |
// Tabla de histograma acumulado referencia |
|
132 |
acumulateR= Histogram.convertTableToNormalizeAccumulate(histogramReference.getTable()); |
|
133 | 129 |
|
134 |
// Tabla de histograma acumulado fuente
|
|
130 |
acumulateR= Histogram.convertTableToNormalizeAccumulate(histogramReference.getTable());
|
|
135 | 131 |
acumulateS= Histogram.convertTableToNormalizeAccumulate(histogramSource.getTable()); |
136 | 132 |
|
137 | 133 |
}catch (RasterBufferInvalidException e) { |
... | ... | |
139 | 135 |
} catch (HistogramException e) { |
140 | 136 |
return; |
141 | 137 |
} catch (InterruptedException e) { |
142 |
Thread.currentThread().interrupt(); |
|
143 |
}
|
|
138 |
Thread.currentThread().interrupt();
|
|
139 |
} |
|
144 | 140 |
} |
145 | 141 |
|
146 | 142 |
|
... | ... | |
149 | 145 |
* */ |
150 | 146 |
public void process() throws InterruptedException { |
151 | 147 |
|
152 |
int tableAsign[][]= new int[3][256];
|
|
148 |
byte tableAsign[][]= new byte[3][256];
|
|
153 | 149 |
int progress=0; |
154 | 150 |
int index=0; |
155 | 151 |
double inValue=0; |
... | ... | |
159 | 155 |
for (int band=0; band < rasterSource.getRenderBands().length; band++){ |
160 | 156 |
for(int i= 0; i< tableAsign[0].length; i++){ |
161 | 157 |
inValue = acumulateS[band][i]; |
162 |
int value= searchInHistogramReference(inValue,band);
|
|
163 |
tableAsign[band][i]= value-127;
|
|
158 |
byte value=(byte) (searchInHistogramReference(inValue,band)-128);
|
|
159 |
tableAsign[band][i]= value; |
|
164 | 160 |
} |
165 | 161 |
} |
166 | 162 |
|
... | ... | |
174 | 170 |
for(int j=0;j<sourceGrid.getNX();j++){ |
175 | 171 |
byte data= (byte) ((sourceGrid.getCellValueAsByte(j,i))); |
176 | 172 |
index=data+128; |
177 |
gridResult.setCellValue(j,i,(byte)(tableAsign[band][index]));
|
|
173 |
gridResult.setCellValue(j,i,(byte)((tableAsign[band][index])));
|
|
178 | 174 |
percent=(int)( progress*100/(gridResult.getLayerNY()*rasterSource.getRenderBands().length)); |
179 | 175 |
} |
180 | 176 |
} |
... | ... | |
197 | 193 |
int i=0; |
198 | 194 |
while(value>acumulateR[band][i]){ |
199 | 195 |
i++; |
200 |
if(i==256)
|
|
201 |
return (int)254;
|
|
196 |
if(i==255)
|
|
197 |
return (int)255;
|
|
202 | 198 |
} |
203 | 199 |
if(i==0) |
204 | 200 |
return 0; |
... | ... | |
218 | 214 |
|
219 | 215 |
try{ |
220 | 216 |
|
221 |
String filename= "histogramMatching2.tif";
|
|
217 |
String filename= "histogramMatching2.img";
|
|
222 | 218 |
GeoRasterWriter grw = null; |
223 | 219 |
writerBufferServer = new WriterBufferServer(gridResult.getRasterBuf()); |
224 | 220 |
grw = GeoRasterWriter.getWriter(writerBufferServer, filename, gridResult.getBandCount(),rasterSource.getAffineTransform(), gridResult.getRasterBuf().getWidth(), gridResult.getRasterBuf().getHeight(), gridResult.getRasterBuf().getDataType(), GeoRasterWriter.getWriter(filename).getParams(), null); |
Also available in: Unified diff