use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class HoughCircles method run.
public void run(BufferedImage circleImage) {
offx = 0;
offy = 0;
width = raster.getWidth();
height = raster.getHeight();
offset = width;
imageValues = new byte[width * height];
int count = 0;
RandomIter renderedImageIterator = RandomIterFactory.create(raster, null);
for (int r = 0; r < height; r++) {
for (int c = 0; c < width; c++) {
int sample = renderedImageIterator.getSample(c, r, 0);
imageValues[count++] = (byte) sample;
}
}
renderedImageIterator.done();
double[][][] houghValues = houghTransform();
// Create image View for Hough Transform.
// ImageProcessor newip = new ByteProcessor(width, height);
// byte[] newpixels = (byte[]) newip.getPixels();
// createHoughPixels(houghValues, newpixels);
//
// // Create image View for Marked Circles.
// ImageProcessor circlesip = new ByteProcessor(width, height);
// byte[] circlespixels = (byte[]) circlesip.getPixels();
// Mark the center of the found circles in a new image
// if (useThreshold)
// getCenterPointsByThreshold(threshold);
// else
Coordinate[] centerPoints = getCenterPoints(houghValues, maxCircles);
// drawCircles(houghValues, circlespixels);
Graphics2D g2d;
if (circleImage != null) {
g2d = (Graphics2D) circleImage.getGraphics();
} else {
g2d = (Graphics2D) raster.getGraphics();
}
g2d.setColor(Color.red);
g2d.setStroke(new BasicStroke(2));
for (Coordinate point : centerPoints) {
int size = (int) point.z * 2;
g2d.drawOval((int) point.x - size / 2, (int) point.y + -size / 2, size, size);
}
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsAb method process.
@Execute
public void process() throws Exception {
if (!concatOr(outAb == null, doReset)) {
return;
}
checkNull(inTca, inPlan);
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inTca);
int nCols = regionMap.getCols();
int nRows = regionMap.getRows();
double xRes = regionMap.getXres();
RandomIter tcaIter = CoverageUtilities.getRandomIterator(inTca);
RandomIter planIter = CoverageUtilities.getRandomIterator(inPlan);
WritableRaster alungWR = CoverageUtilities.createWritableRaster(nCols, nRows, null, null, null);
WritableRandomIter alungIter = RandomIterFactory.createWritable(alungWR, null);
WritableRaster bWR = CoverageUtilities.createWritableRaster(nCols, nRows, null, null, null);
WritableRandomIter bIter = RandomIterFactory.createWritable(bWR, null);
try {
pm.beginTask(msg.message("ab.calculating"), nRows * nCols);
processGrid(nCols, nRows, (c, r) -> {
if (pm.isCanceled()) {
return;
}
double planSample = planIter.getSampleDouble(c, r, 0);
if (!isNovalue(planSample) && planSample != 0.0) {
if (xRes > 1 / planSample && planSample >= 0.0) {
bIter.setSample(c, r, 0, 0.1 * xRes);
} else if (xRes > Math.abs(1 / planSample) && planSample < 0.0) {
bIter.setSample(c, r, 0, xRes + 0.9 * xRes);
} else {
double bSample = 2 * Math.asin(xRes / (2 * (1 / planSample))) * (1 / planSample - xRes);
bIter.setSample(c, r, 0, bSample);
if (planSample >= 0.0 && bSample < 0.1 * xRes) {
bIter.setSample(c, r, 0, 0.1 * xRes);
}
if (planSample < 0.0 && bSample > (xRes + 0.9 * xRes)) {
bIter.setSample(c, r, 0, xRes + 0.9 * xRes);
}
}
}
if (planSample == 0.0) {
bIter.setSample(c, r, 0, xRes);
}
alungIter.setSample(c, r, 0, tcaIter.getSample(c, r, 0) * xRes * xRes / bIter.getSampleDouble(c, r, 0));
if (isNovalue(planSample)) {
alungIter.setSample(c, r, 0, doubleNovalue);
bIter.setSample(c, r, 0, doubleNovalue);
}
pm.worked(1);
});
pm.done();
} finally {
tcaIter.done();
planIter.done();
alungIter.done();
bIter.done();
}
outAb = CoverageUtilities.buildCoverage("alung", alungWR, regionMap, inTca.getCoordinateReferenceSystem());
outB = CoverageUtilities.buildCoverage("b", bWR, regionMap, inTca.getCoordinateReferenceSystem());
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsAspectIM method processCell.
@Override
protected void processCell(int readCol, int readRow, int writeCol, int writeRow, int readCols, int readRows, int writeCols, int writeRows) {
RandomIter elevIter = inRasterIterators.get(0);
Double novalue = inRasterNovalues.get(0);
GridNode node = new GridNode(elevIter, readCols, readRows, xRes, yRes, readCol, readRow, novalue);
double aspect = OmsAspect.calculateAspect(node, radtodeg, doRound);
WritableRandomIter outDataIter = outRasterIterators.get(0);
outDataIter.setSample(writeCol, writeRow, 0, aspect);
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsCurvaturesIM method processCell.
@Override
protected void processCell(int readCol, int readRow, int writeCol, int writeRow, int readCols, int readRows, int writeCols, int writeRows) {
RandomIter elevIter = inRasterIterators.get(0);
Double novalue = inRasterNovalues.get(0);
GridNode node = new GridNode(elevIter, readCols, readRows, xRes, yRes, readCol, readRow, novalue);
OmsCurvatures.calculateCurvatures2(node, planTangProf);
if (outPlan != null)
outRasterIterators.get(0).setSample(writeCol, writeRow, 0, planTangProf[0]);
if (outTang != null)
outRasterIterators.get(1).setSample(writeCol, writeRow, 0, planTangProf[1]);
if (outProf != null)
outRasterIterators.get(2).setSample(writeCol, writeRow, 0, planTangProf[2]);
}
use of javax.media.jai.iterator.RandomIter in project hortonmachine by TheHortonMachine.
the class OmsGeomorphon method process.
@Execute
public void process() throws Exception {
checkNull(inElev);
if (pRadius <= 0) {
throw new ModelsIllegalargumentException("The search radius has to be > 0.", this, pm);
}
final double diagonalDelta = pRadius / sqrt(2.0);
final RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
int cols = regionMap.getCols();
final int rows = regionMap.getRows();
final RandomIter elevIter = CoverageUtilities.getRandomIterator(inElev);
final GridGeometry2D gridGeometry = inElev.getGridGeometry();
WritableRaster[] outWRHolder = new WritableRaster[1];
outRaster = CoverageUtilities.createCoverageFromTemplate(inElev, HMConstants.doubleNovalue, outWRHolder);
final WritableRandomIter outIter = CoverageUtilities.getWritableRandomIterator(outWRHolder[0]);
pm.beginTask("Calculate classes...", cols);
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
try {
double classification = calculateGeomorphon(elevIter, gridGeometry, pRadius, pThreshold, diagonalDelta, c, r);
outIter.setSample(c, r, 0, classification);
} catch (TransformException e) {
e.printStackTrace();
}
}
pm.worked(1);
}
pm.done();
}
Aggregations