use of org.jwildfire.io.ImageReader in project JWildfire by thargor6.
the class ImageSequenceLoader method loadImage.
@Override
protected SimpleImage loadImage() {
String fn = new File(this.filename).getName();
String ext;
int p = fn.lastIndexOf(".");
if ((p > 0) && (p < fn.length() - 1)) {
ext = fn.substring(p, fn.length());
fn = fn.substring(0, p);
} else {
ext = "";
}
String baseFn = fn;
String numberPart = "";
for (int i = fn.length() - 1; i >= 0; i--) {
char c = fn.charAt(i);
if (!((c >= '0') && (c <= '9'))) {
baseFn = fn.substring(0, i + 1);
if (i < fn.length() - 1)
numberPart = fn.substring(i + 1, fn.length());
break;
} else if (i == 0) {
numberPart = fn;
baseFn = "";
}
}
System.out.println("BASE: " + baseFn);
System.out.println("NUMBER: " + numberPart);
System.out.println("EXT: " + ext);
// generate current filename
fn = String.valueOf(this.frame);
while (fn.length() < numberPart.length()) fn = "0" + fn;
fn = new File(this.filename).getParent() + File.separator + baseFn + fn + ext;
System.out.println(this.frame + ": " + fn);
try {
return new ImageReader(getDesktop()).loadImage(fn);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.jwildfire.io.ImageReader 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