use of org.jwildfire.create.tina.meshgen.filter.PreFilter in project JWildfire by thargor6.
the class ImageStackSampler method getIntensityInternal.
private int getIntensityInternal(int pX, int pY, int pZ) {
if (pX < 0 || pX >= stackXSize || pY < 0 || pY >= stackYSize || pZ < 0 || pZ >= stackZSize)
return 0;
SimpleImage img = images.get(pZ);
if (img == null) {
String filename = String.format(inputfilename, imagesIndex.get(pZ));
try {
SimpleImage loadedImage = new ImageReader().loadImage(filename);
for (PreFilter filter : preFilterList) {
filter.apply(loadedImage);
}
if (downsample > 1) {
double square = downsample * downsample;
img = new SimpleImage(loadedImage.getImageWidth() / downsample, loadedImage.getImageHeight() / downsample);
for (int i = 0; i < img.getImageHeight(); i++) {
for (int j = 0; j < img.getImageWidth(); j++) {
long sum = 0;
for (int ii = 0; ii < downsample; ii++) {
for (int jj = 0; jj < downsample; jj++) {
sum += loadedImage.getRValue(j * downsample + jj, i * downsample + ii);
}
}
int value = (int) (sum / square + 0.5);
img.setRGB(j, i, value, value, value);
}
}
} else {
img = loadedImage;
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
images.set(pZ, img);
int imgCount = 1;
for (int i = pZ - 1; i >= 0; i--) {
if (images.get(i) != null) {
imgCount++;
if (imgCount >= MAX_IMAGES_IN_CACHE) {
images.set(i, null);
imgCount--;
}
} else {
break;
}
}
}
return img.getRValue(pX, pY);
}
Aggregations