use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsPeakflow method processWithTopIndex.
private void processWithTopIndex(WritableRaster supRescaledWR, WritableRaster subRescaledWR) throws Exception {
double[][] topindexCb = doCb(inTopindex);
// cumulate topindex
for (int i = 0; i < topindexCb.length; i++) {
if (i > 0) {
topindexCb[i][1] = topindexCb[i][1] + topindexCb[i - 1][1];
}
}
double max = topindexCb[topindexCb.length - 1][1];
// normalize
for (int i = 0; i < topindexCb.length; i++) {
topindexCb[i][1] = topindexCb[i][1] / max;
}
List<Double> meanValueList = new ArrayList<Double>();
List<Double> cumulatedValueList = new ArrayList<Double>();
for (int i = 0; i < topindexCb.length; i++) {
meanValueList.add(topindexCb[i][0]);
cumulatedValueList.add(topindexCb[i][1]);
}
LinearListInterpolator interpolator = new LinearListInterpolator(meanValueList, cumulatedValueList);
double topindexThreshold = interpolator.linearInterpolateX(1 - pSat / 100);
RenderedImage topindexRI = inTopindex.getRenderedImage();
RandomIter topindexIter = RandomIterFactory.create(topindexRI, null);
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
double topindex = topindexIter.getSampleDouble(c, r, 0);
if (topindex >= topindexThreshold) {
if (subRescaledWR != null) {
subRescaledWR.setSample(c, r, 0, doubleNovalue);
}
} else {
supRescaledWR.setSample(c, r, 0, doubleNovalue);
}
}
}
}
use of javax.media.jai.iterator.RandomIter in project geowave by locationtech.
the class WarpNearestOpImage method computeRectShort.
@Override
protected void computeRectShort(final PlanarImage src, final RasterAccessor dst, final RandomIter roiIter, final boolean roiContainsTile) {
// Random Iterator on the source image bounds
final RandomIter iter = RandomIterFactory.create(src, src.getBounds(), TILE_CACHED, ARRAY_CALC);
// Initial settings
final int minX = src.getMinX();
final int maxX = src.getMaxX();
final int minY = src.getMinY();
final int maxY = src.getMaxY();
final int dstWidth = dst.getWidth();
final int dstHeight = dst.getHeight();
final int dstBands = dst.getNumBands();
final int lineStride = dst.getScanlineStride();
final int pixelStride = dst.getPixelStride();
final int[] bandOffsets = dst.getBandOffsets();
final short[][] data = dst.getShortDataArrays();
final float[] warpData = new float[2 * dstWidth];
int lineOffset = 0;
// NO ROI AND NODATA
if (caseA || (caseB && roiContainsTile)) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
// If the pixel is outside the input image bounds
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// Nearest interpolation
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) iter.getSample(sx, sy, b);
}
}
pixelOffset += pixelStride;
}
}
// ONLY ROI
} else if (caseB) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// value
if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// Else the related source pixel is set
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) iter.getSample(sx, sy, b);
}
}
}
pixelOffset += pixelStride;
}
}
// ONLY NODATA
} else if (caseC || (hasROI && hasNoData && roiContainsTile)) {
short inputValue = 0;
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// The related source pixel is set if it isn't a nodata
for (int b = 0; b < dstBands; b++) {
// Input value selected
inputValue = (short) iter.getSample(sx, sy, b);
if (noDataRange.contains(inputValue)) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
} else {
data[b][pixelOffset + bandOffsets[b]] = inputValue;
}
}
}
pixelOffset += pixelStride;
}
}
// BOTH ROI AND NODATA
} else {
short inputValue = 0;
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// value
if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// nodata
for (int b = 0; b < dstBands; b++) {
// Input value selected
inputValue = (short) iter.getSample(sx, sy, b);
if (noDataRange.contains(inputValue)) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
} else {
data[b][pixelOffset + bandOffsets[b]] = inputValue;
}
}
}
}
pixelOffset += pixelStride;
}
}
}
iter.done();
}
use of javax.media.jai.iterator.RandomIter in project geowave by locationtech.
the class WarpNearestOpImage method computeRectUShort.
@Override
protected void computeRectUShort(final PlanarImage src, final RasterAccessor dst, final RandomIter roiIter, final boolean roiContainsTile) {
// Random Iterator on the source image bounds
final RandomIter iter = RandomIterFactory.create(src, src.getBounds(), TILE_CACHED, ARRAY_CALC);
// Initial settings
final int minX = src.getMinX();
final int maxX = src.getMaxX();
final int minY = src.getMinY();
final int maxY = src.getMaxY();
final int dstWidth = dst.getWidth();
final int dstHeight = dst.getHeight();
final int dstBands = dst.getNumBands();
final int lineStride = dst.getScanlineStride();
final int pixelStride = dst.getPixelStride();
final int[] bandOffsets = dst.getBandOffsets();
final short[][] data = dst.getShortDataArrays();
final float[] warpData = new float[2 * dstWidth];
int lineOffset = 0;
// NO ROI AND NODATA
if (caseA || (caseB && roiContainsTile)) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
// If the pixel is outside the input image bounds
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// Nearest interpolation
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) (iter.getSample(sx, sy, b) & 0xFFFF);
}
}
pixelOffset += pixelStride;
}
}
// ONLY ROI
} else if (caseB) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// value
if (!(roiBounds.contains(sx, sy) && roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// Else the related source pixel is set
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) (iter.getSample(sx, sy, b) & 0xFFFF);
}
}
}
pixelOffset += pixelStride;
}
}
// ONLY NODATA
} else if (caseC || (hasROI && hasNoData && roiContainsTile)) {
short inputValue = 0;
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// The related source pixel is set if it isn't a nodata
for (int b = 0; b < dstBands; b++) {
// Input value selected
inputValue = (short) (iter.getSample(sx, sy, b) & 0xFFFF);
if (noDataRange.contains(inputValue)) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
} else {
data[b][pixelOffset + bandOffsets[b]] = inputValue;
}
}
}
pixelOffset += pixelStride;
}
}
// BOTH ROI AND NODATA
} else {
short inputValue = 0;
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// value
if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
}
}
} else {
// nodata
for (int b = 0; b < dstBands; b++) {
// Input value selected
inputValue = (short) (iter.getSample(sx, sy, b) & 0xFFFF);
if (noDataRange.contains(inputValue)) {
data[b][pixelOffset + bandOffsets[b]] = (short) backgroundValues[b];
} else {
data[b][pixelOffset + bandOffsets[b]] = inputValue;
}
}
}
}
pixelOffset += pixelStride;
}
}
}
iter.done();
}
use of javax.media.jai.iterator.RandomIter in project geowave by locationtech.
the class WarpNearestOpImage method computeRectDouble.
@Override
protected void computeRectDouble(final PlanarImage src, final RasterAccessor dst, final RandomIter roiIter, final boolean roiContainsTile) {
// Random Iterator on the source image bounds
final RandomIter iter = RandomIterFactory.create(src, src.getBounds(), TILE_CACHED, ARRAY_CALC);
// Initial settings
final int minX = src.getMinX();
final int maxX = src.getMaxX();
final int minY = src.getMinY();
final int maxY = src.getMaxY();
final int dstWidth = dst.getWidth();
final int dstHeight = dst.getHeight();
final int dstBands = dst.getNumBands();
final int lineStride = dst.getScanlineStride();
final int pixelStride = dst.getPixelStride();
final int[] bandOffsets = dst.getBandOffsets();
final double[][] data = dst.getDoubleDataArrays();
final float[] warpData = new float[2 * dstWidth];
int lineOffset = 0;
// NO ROI AND NODATA
if (caseA || (caseB && roiContainsTile)) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
// If the pixel is outside the input image bounds
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
}
}
} else {
// Nearest interpolation
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = iter.getSampleDouble(sx, sy, b);
}
}
pixelOffset += pixelStride;
}
}
// ONLY ROI
} else if (caseB) {
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
}
}
} else {
// value
if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
}
}
} else {
// Else the related source pixel is set
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = iter.getSampleDouble(sx, sy, b);
}
}
}
pixelOffset += pixelStride;
}
}
// ONLY NODATA
} else if (caseC || (hasROI && hasNoData && roiContainsTile)) {
double inputValue = 0;
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
}
}
} else {
// The related source pixel is set if it isn't a nodata
for (int b = 0; b < dstBands; b++) {
// Input value selected
inputValue = iter.getSampleDouble(sx, sy, b);
if (noDataRange.contains(inputValue)) {
data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
} else {
data[b][pixelOffset + bandOffsets[b]] = inputValue;
}
}
}
pixelOffset += pixelStride;
}
}
// BOTH ROI AND NODATA
} else {
double inputValue = 0;
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
// Calculation of the warp for the selected row
warp.warpRect(dst.getX(), dst.getY() + h, dstWidth, 1, warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
/*
* The warp object subtract 0.5 from backward mapped source coordinate. Need to do a round
* to get the nearest neighbor. This is different from the standard nearest
* implementation.
*/
final int sx = round(warpData[count++]);
final int sy = round(warpData[count++]);
if ((sx < minX) || (sx >= maxX) || (sy < minY) || (sy >= maxY)) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
}
}
} else {
// value
if (!(roiBounds.contains(sx, sy) && (roiIter.getSample(sx, sy, 0) > 0))) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
}
}
} else {
// nodata
for (int b = 0; b < dstBands; b++) {
// Input value selected
inputValue = iter.getSampleDouble(sx, sy, b);
if (noDataRange.contains(inputValue)) {
data[b][pixelOffset + bandOffsets[b]] = backgroundValues[b];
} else {
data[b][pixelOffset + bandOffsets[b]] = inputValue;
}
}
}
}
pixelOffset += pixelStride;
}
}
}
iter.done();
}
use of javax.media.jai.iterator.RandomIter in project geowave by locationtech.
the class WarpOpImage method computeRect.
/**
* Warps a rectangle. If ROI is present, the intersection between ROI and tile bounds is
* calculated; The result ROI will be used for calculations inside the computeRect() method.
*/
@Override
protected void computeRect(final PlanarImage[] sources, final WritableRaster dest, final Rectangle destRect) {
// Retrieve format tags.
final RasterFormatTag[] formatTags = getFormatTags();
final RasterAccessor dst = new RasterAccessor(dest, destRect, formatTags[1], getColorModel());
RandomIter roiIter = null;
boolean roiContainsTile = false;
boolean roiDisjointTile = false;
// tile bounds is taken.
if (hasROI) {
final Rectangle srcRectExpanded = mapDestRect(destRect, 0);
// The tile dimension is extended for avoiding border errors
srcRectExpanded.setRect(srcRectExpanded.getMinX() - leftPad, srcRectExpanded.getMinY() - topPad, srcRectExpanded.getWidth() + rightPad + leftPad, srcRectExpanded.getHeight() + bottomPad + topPad);
if (!roiBounds.intersects(srcRectExpanded)) {
roiDisjointTile = true;
} else {
roiContainsTile = roi.contains(srcRectExpanded);
if (!roiContainsTile) {
if (!roi.intersects(srcRectExpanded)) {
roiDisjointTile = true;
} else {
final PlanarImage roiIMG = getImage();
roiIter = RandomIterFactory.create(roiIMG, null, TILE_CACHED, ARRAY_CALC);
}
}
}
}
if (!hasROI || !roiDisjointTile) {
switch(dst.getDataType()) {
case DataBuffer.TYPE_BYTE:
computeRectByte(sources[0], dst, roiIter, roiContainsTile);
break;
case DataBuffer.TYPE_USHORT:
computeRectUShort(sources[0], dst, roiIter, roiContainsTile);
break;
case DataBuffer.TYPE_SHORT:
computeRectShort(sources[0], dst, roiIter, roiContainsTile);
break;
case DataBuffer.TYPE_INT:
computeRectInt(sources[0], dst, roiIter, roiContainsTile);
break;
case DataBuffer.TYPE_FLOAT:
computeRectFloat(sources[0], dst, roiIter, roiContainsTile);
break;
case DataBuffer.TYPE_DOUBLE:
computeRectDouble(sources[0], dst, roiIter, roiContainsTile);
break;
}
// WritableRaster
if (dst.isDataCopy()) {
dst.clampDataArrays();
dst.copyDataToRaster();
}
} else {
// set to backgroundValues
if (setBackground) {
ImageUtil.fillBackground(dest, destRect, backgroundValues);
}
}
}
Aggregations