use of org.jaitools.media.jai.kernel.KernelFactory.ValueType in project hortonmachine by TheHortonMachine.
the class OmsKernelFilter method getKernelType.
private static ValueType getKernelType(String pKernel2) {
ValueType type = null;
pKernel2 = pKernel2.trim();
if (pKernel2.equals(BINARY)) {
type = KernelFactory.ValueType.BINARY;
} else if (pKernel2.equals(COSINE)) {
type = KernelFactory.ValueType.COSINE;
} else if (pKernel2.equals(DISTANCE)) {
type = KernelFactory.ValueType.DISTANCE;
} else if (pKernel2.equals(GAUSSIAN)) {
type = KernelFactory.ValueType.GAUSSIAN;
} else if (pKernel2.equals(INVERSE_DISTANCE)) {
type = KernelFactory.ValueType.INVERSE_DISTANCE;
} else if (pKernel2.equals(QUARTIC)) {
type = KernelFactory.ValueType.QUARTIC;
} else if (pKernel2.equals(TRIANGULAR)) {
type = KernelFactory.ValueType.TRIANGULAR;
} else if (pKernel2.equals(TRIWEIGHT)) {
type = KernelFactory.ValueType.TRIWEIGHT;
} else if (pKernel2.equals(EPANECHNIKOV)) {
type = KernelFactory.ValueType.EPANECHNIKOV;
} else {
throw new ModelsIllegalargumentException("Kernel type not recognised: " + pKernel2, "OmsKernelFilter");
}
return type;
}
use of org.jaitools.media.jai.kernel.KernelFactory.ValueType in project hortonmachine by TheHortonMachine.
the class OmsKernelDensity method process.
@SuppressWarnings("nls")
@Execute
public void process() throws Exception {
checkNull(inMap);
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inMap);
int cols = regionMap.getCols();
int rows = regionMap.getRows();
ValueType type = KernelFactory.ValueType.EPANECHNIKOV;
switch(pKernel) {
case 0:
type = KernelFactory.ValueType.BINARY;
break;
case 1:
type = KernelFactory.ValueType.COSINE;
break;
case 2:
type = KernelFactory.ValueType.DISTANCE;
break;
case 4:
type = KernelFactory.ValueType.GAUSSIAN;
break;
case 5:
type = KernelFactory.ValueType.INVERSE_DISTANCE;
break;
case 6:
type = KernelFactory.ValueType.QUARTIC;
break;
case 7:
type = KernelFactory.ValueType.TRIANGULAR;
break;
case 8:
type = KernelFactory.ValueType.TRIWEIGHT;
break;
}
KernelJAI kernel = KernelFactory.createCircle(pRadius, type);
RenderedImage inImg = inMap.getRenderedImage();
RandomIter inIter = RandomIterFactory.create(inImg, null);
WritableRaster outWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, HMConstants.doubleNovalue);
WritableRandomIter outIter = RandomIterFactory.createWritable(outWR, null);
float[] kernelData = kernel.getKernelData();
pm.beginTask("Estimating kernel density...", cols - 2 * pRadius);
for (int r = pRadius; r < rows - pRadius; r++) {
for (int c = pRadius; c < cols - pRadius; c++) {
double inputValue = inIter.getSampleDouble(c, r, 0);
if (isNovalue(inputValue)) {
continue;
}
if (doConstant)
inputValue = 1.0;
int k = 0;
for (int kr = -pRadius; kr <= pRadius; kr++, k++) {
for (int kc = -pRadius; kc <= pRadius; kc++) {
// data[gridCoords.y + j][gridCoords.x + i] += cdata[k] * centreValue;
double outputValue = outIter.getSampleDouble(c + kc, r + kr, 0);
if (isNovalue(outputValue)) {
outputValue = 0;
}
outputValue = outputValue + kernelData[k] * inputValue;
outIter.setSample(c + kc, r + kr, 0, outputValue);
}
}
}
pm.worked(1);
}
pm.done();
pm.beginTask("Finalizing...", cols);
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
double outputValue = outIter.getSampleDouble(c, r, 0);
if (isNovalue(outputValue)) {
outIter.setSample(c, r, 0, 0.0);
}
}
pm.worked(1);
}
pm.done();
outDensity = CoverageUtilities.buildCoverage("kerneldensity", outWR, regionMap, inMap.getCoordinateReferenceSystem());
}
use of org.jaitools.media.jai.kernel.KernelFactory.ValueType in project hortonmachine by TheHortonMachine.
the class OmsKernelFilter method process.
public void process() throws Exception {
checkNull(inRaster);
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
int cols = regionMap.getCols();
int rows = regionMap.getRows();
ValueType type = getKernelType(pKernel);
KernelJAI kernel = KernelFactory.createCircle(pRadius, type);
RenderedImage inImg = inRaster.getRenderedImage();
RandomIter inIter = RandomIterFactory.create(inImg, null);
WritableRaster outWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, HMConstants.doubleNovalue);
WritableRandomIter outIter = RandomIterFactory.createWritable(outWR, null);
float[] kernelData = kernel.getKernelData();
pm.beginTask("Processing...", cols - 2 * pRadius);
for (int r = pRadius; r < rows - pRadius; r++) {
for (int c = pRadius; c < cols - pRadius; c++) {
double kernelSum = 0.0;
int k = 0;
double outputValue = 0.0;
for (int kr = -pRadius; kr <= pRadius; kr++, k++) {
for (int kc = -pRadius; kc <= pRadius; kc++) {
double value = inIter.getSampleDouble(c + kc, r + kr, 0);
if (!isNovalue(value)) {
outputValue = outputValue + value * kernelData[k];
kernelSum = kernelSum + kernelData[k];
}
}
}
outIter.setSample(c, r, 0, outputValue / kernelSum);
}
pm.worked(1);
}
pm.done();
outRaster = CoverageUtilities.buildCoverage("filtered", outWR, regionMap, inRaster.getCoordinateReferenceSystem());
}
Aggregations