Revision 43864 branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/operations/median/MedianOperation.java
MedianOperation.java | ||
---|---|---|
61 | 61 |
* |
62 | 62 |
*/ |
63 | 63 |
public MedianOperation(OperationFactory factory) { |
64 |
this.factory = factory;
|
|
64 |
super(factory);
|
|
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
@SuppressWarnings("unchecked") |
... | ... | |
70 | 70 |
super.preProcess(); |
71 | 71 |
BufferManager manager = BufferLocator.getBufferManager(); |
72 | 72 |
|
73 |
if(this.parameters.getDynClass().getDynField(SIDE_WINDOW_PARAM)!=null) { |
|
74 |
sideWindow = (Integer)this.parameters.getDynValue(SIDE_WINDOW_PARAM); |
|
75 |
} else { |
|
76 |
sideWindow = 3; |
|
77 |
}; |
|
73 |
sideWindow = (int) this.getParameter(SIDE_WINDOW_PARAM, 3); |
|
78 | 74 |
halfSideWindow = (int)(sideWindow/2); |
79 | 75 |
|
80 |
int bands = this.buffer.getBandCount();
|
|
81 |
NoData[] noData = this.buffer.getBandNoData();
|
|
82 |
if (copyUnprocessedBands) {
|
|
76 |
int bands = this.getInputBuffer().getBandCount();
|
|
77 |
NoData[] noData = this.getInputBuffer().getBandNoData();
|
|
78 |
if (mustCopyUnprocessedBands()) {
|
|
83 | 79 |
try { |
84 |
this.outputBuffer = |
|
85 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), this.buffer.getBandTypes(), |
|
86 |
this.buffer.getBandNoData(), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
80 |
this.setOutputBuffer( |
|
81 |
manager.createBuffer( |
|
82 |
this.getInputBuffer().getRows(), |
|
83 |
this.getInputBuffer().getColumns(), |
|
84 |
this.getInputBuffer().getBandTypes(), |
|
85 |
this.getInputBuffer().getBandNoData(), |
|
86 |
this.getInputBuffer().getProjection(), |
|
87 |
this.getInputBuffer().getEnvelope())); |
|
87 | 88 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
88 | 89 |
throw new ProcessingOperationException(e); |
89 | 90 |
} |
90 | 91 |
} else { |
91 |
List<NoData> noDatas = new ArrayList<NoData>(); |
|
92 |
List<Integer> types = new ArrayList<Integer>(); |
|
93 |
for (int band = 0; band < bands; band++) { |
|
94 |
if (isProcessableBand(band)) { |
|
95 |
noDatas.add(this.buffer.getBandNoData()[band]); |
|
96 |
types.add(this.buffer.getBandTypes()[band]); |
|
97 |
} |
|
98 |
} |
|
99 |
int[] typesInt = new int[types.size()]; |
|
100 |
for (Iterator<Integer> iterator = types.iterator(); iterator.hasNext();) { |
|
101 |
int i = 0; |
|
102 |
Integer type = (Integer) iterator.next(); |
|
103 |
typesInt[i] = type.intValue(); |
|
104 |
} |
|
105 | 92 |
try { |
106 |
this.outputBuffer = |
|
107 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt, |
|
108 |
noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
93 |
this.setOutputBuffer( |
|
94 |
manager.createBuffer( |
|
95 |
this.getInputBuffer().getRows(), |
|
96 |
this.getInputBuffer().getColumns(), |
|
97 |
this.getProcessableBandTypesAsArray(), |
|
98 |
this.getProcessableBandNoDatasAsArray(), |
|
99 |
this.getInputBuffer().getProjection(), |
|
100 |
this.getInputBuffer().getEnvelope())); |
|
109 | 101 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
110 | 102 |
throw new ProcessingOperationException(e); |
111 | 103 |
} |
... | ... | |
114 | 106 |
rowProcessors = new RowProcessor[bands]; |
115 | 107 |
for (int band = 0; band < noData.length; band++) { |
116 | 108 |
if (isProcessableBand(band)) { |
117 |
int bandType = this.buffer.getBand(band).getDataType();
|
|
109 |
int bandType = this.getInputBuffer().getBand(band).getDataType();
|
|
118 | 110 |
switch (bandType) { |
119 | 111 |
case BufferManager.TYPE_BYTE: |
120 | 112 |
rowProcessors[band] = new ByteRowProcessor(band); |
... | ... | |
144 | 136 |
@Override |
145 | 137 |
public void process() throws ProcessingOperationException { |
146 | 138 |
super.process(); |
147 |
for (int band=0; band<this.buffer.getBandCount(); band++){
|
|
148 |
if (bandsToProcess.contains(band)) {
|
|
149 |
Band bufferBand = this.buffer.getBand(band);
|
|
150 |
Band outputBufferBand = this.outputBuffer.getBand(band);
|
|
139 |
for (int band=0; band<this.getInputBuffer().getBandCount(); band++){
|
|
140 |
if (getBandsToProcess().contains(band)) {
|
|
141 |
Band bufferBand = this.getInputBuffer().getBand(band);
|
|
142 |
Band outputBufferBand = this.getOutputBuffer().getBand(band);
|
|
151 | 143 |
|
152 | 144 |
|
153 |
for (int row = 0; row < this.buffer.getRows(); row++) {
|
|
145 |
for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
|
|
154 | 146 |
Object rowBuffer = bufferBand.createRowBuffer(); |
155 | 147 |
bufferBand.fetchRow(row, rowBuffer); |
156 |
List<Object> bundle = new ArrayList<Object>();
|
|
157 |
for(int r=Math.max(row-halfSideWindow,0); r<=Math.min(row+halfSideWindow,this.buffer.getRows()-1);r++){
|
|
148 |
List<Object> bundle = new ArrayList<>(); |
|
149 |
for(int r=Math.max(row-halfSideWindow,0); r<=Math.min(row+halfSideWindow,this.getInputBuffer().getRows()-1);r++){
|
|
158 | 150 |
Object bundleRow = bufferBand.createRowBuffer(); |
159 | 151 |
bufferBand.fetchRow(row, bundleRow); |
160 | 152 |
bundle.add(bundleRow); |
... | ... | |
168 | 160 |
outputBufferBand.putRow(row, outputRowBuffer); |
169 | 161 |
} |
170 | 162 |
} else { |
171 |
if(copyUnprocessedBands){
|
|
163 |
if(mustCopyUnprocessedBands()){
|
|
172 | 164 |
try { |
173 |
this.outputBuffer.getBand(band).copyFrom(this.buffer.getBand(band));
|
|
165 |
this.getOutputBuffer().getBand(band).copyFrom(this.getInputBuffer().getBand(band));
|
|
174 | 166 |
} catch (BandException e) { |
175 | 167 |
throw new ProcessingOperationException(e); |
176 | 168 |
} |
... | ... | |
195 | 187 |
|
196 | 188 |
public AbstractRowProcessor(int band) { |
197 | 189 |
this.band = band; |
198 |
noData = buffer.getBand(band).getNoData();
|
|
190 |
noData = getInputBuffer().getBand(band).getNoData();
|
|
199 | 191 |
} |
200 | 192 |
} |
201 | 193 |
|
... | ... | |
211 | 203 |
byte[] inputByteRow = (byte[])inputRow; |
212 | 204 |
byte[] outputByteRow = (byte[])outputRow; |
213 | 205 |
for (int i = 0; i < inputByteRow.length; i++) { |
214 |
List<Number> kernel = new ArrayList<Number>();
|
|
206 |
List<Number> kernel = new ArrayList<>(); |
|
215 | 207 |
for (Iterator<Object> iterator = bundleRow.iterator(); iterator.hasNext();) { |
216 | 208 |
byte[] row = (byte[]) iterator.next(); |
217 | 209 |
for(int c=Math.max(i-halfSideWindow,0); c<=Math.min(i+halfSideWindow,inputByteRow.length-1);c++){ |
218 |
Integer value = 0xFF & ((Byte) row[c]).byteValue();
|
|
210 |
Integer value = 0xFF & ((Byte) row[c]); |
|
219 | 211 |
if(noData.isDefined() && noData.getValue().equals(value)){ |
220 | 212 |
continue; |
221 | 213 |
} else { |
Also available in: Unified diff