use of org.jwildfire.transform.ConvolveTransformer in project JWildfire by thargor6.
the class BaseFlameListCreator method preprocessImage.
private void preprocessImage(SimpleImage tImage) {
if (imageParams.getErode() == 1) {
long t0 = System.currentTimeMillis();
ErodeTransformer eT = new ErodeTransformer();
eT.initDefaultParams(tImage);
eT.setMode(ErodeTransformer.Mode.DILATE);
eT.setSize(imageParams.getErodeSize());
eT.setShape(ErodeTransformer.Shape.DISK);
eT.transformImage(tImage);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.ERODE).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
List<SimpleImage> convImages = new ArrayList<SimpleImage>();
if (imageParams.getConv_north() == 1) {
long t0 = System.currentTimeMillis();
SimpleImage north = tImage.clone();
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(north);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.setKernelDirection(KernelDirection.NORTH);
transformer.setColorMode(ColorMode.GREY);
transformer.transformImage(north);
convImages.add(north);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_NORTH).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
if (imageParams.getConv_east() == 1) {
long t0 = System.currentTimeMillis();
SimpleImage east = tImage.clone();
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(east);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.setKernelDirection(KernelDirection.EAST);
transformer.setColorMode(ColorMode.GREY);
transformer.transformImage(east);
convImages.add(east);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_EAST).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
if (imageParams.getConv_south() == 1) {
long t0 = System.currentTimeMillis();
SimpleImage south = tImage.clone();
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(south);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.setKernelDirection(KernelDirection.SOUTH);
transformer.setColorMode(ColorMode.GREY);
transformer.transformImage(south);
convImages.add(south);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_SOUTH).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
if (imageParams.getConv_west() == 1) {
long t0 = System.currentTimeMillis();
SimpleImage west = tImage.clone();
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(west);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.setKernelDirection(KernelDirection.WEST);
transformer.setColorMode(ColorMode.GREY);
transformer.transformImage(west);
convImages.add(west);
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_WEST).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
if (convImages.size() == 1) {
SimpleImage convImage = convImages.get(0);
tImage.setBufferedImage(convImage.getBufferedImg(), convImage.getImageWidth(), convImage.getImageHeight());
} else if (convImages.size() > 1) {
long t0 = System.currentTimeMillis();
for (int i = 0; i < tImage.getImageHeight(); i++) {
for (int j = 0; j < tImage.getImageWidth(); j++) {
int r = 0, g = 0, b = 0;
for (SimpleImage convImage : convImages) {
r += convImage.getRValue(j, i);
g += convImage.getGValue(j, i);
b += convImage.getBValue(j, i);
}
r = Tools.roundColor((double) r / (double) convImages.size());
g = Tools.roundColor((double) g / (double) convImages.size());
b = Tools.roundColor((double) b / (double) convImages.size());
tImage.setRGB(j, i, r, g, b);
}
}
long t1 = System.currentTimeMillis();
statistics.getAction(ActionType.CONV_MERGE).setDuration(t1 - t0);
currProgress += updatePreprocessStep;
progressUpdater.updateProgress(currProgress);
}
}
use of org.jwildfire.transform.ConvolveTransformer in project JWildfire by thargor6.
the class Gauss3x3PreFilter method apply.
@Override
public void apply(SimpleImage pImage) {
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(pImage);
transformer.setKernelType(KernelType.GAUSSIAN_BLUR_3x3);
transformer.transformImage(pImage);
}
use of org.jwildfire.transform.ConvolveTransformer in project JWildfire by thargor6.
the class Gauss5x5PreFilter method apply.
@Override
public void apply(SimpleImage pImage) {
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(pImage);
transformer.setKernelType(KernelType.GAUSSIAN_BLUR_5x5);
transformer.transformImage(pImage);
}
use of org.jwildfire.transform.ConvolveTransformer in project JWildfire by thargor6.
the class RandomFlameGeneratorSampler method calculateCoverage.
public static double calculateCoverage(SimpleImage pImg, int bgRed, int bgGreen, int bgBlue, boolean useFilter) {
SimpleImage img;
if (useFilter) {
SimpleImage filteredImg = new SimpleImage(pImg.getBufferedImg(), pImg.getImageWidth(), pImg.getImageHeight());
ConvolveTransformer transformer = new ConvolveTransformer();
transformer.initDefaultParams(filteredImg);
transformer.setKernelType(KernelType.SOBEL_3X3);
transformer.transformImage(filteredImg);
img = filteredImg;
} else {
img = pImg;
}
long maxCoverage = img.getImageWidth() * img.getImageHeight();
long coverage = 0;
Pixel pixel = new Pixel();
if (bgRed == 0 && bgGreen == 0 && bgBlue == 0) {
for (int k = 0; k < img.getImageHeight(); k++) {
for (int l = 0; l < img.getImageWidth(); l++) {
pixel.setARGBValue(img.getARGBValue(l, k));
if (pixel.r > 29 || pixel.g > 15 || pixel.b > 78) {
coverage++;
}
}
}
} else {
for (int k = 0; k < img.getImageHeight(); k++) {
for (int l = 0; l < img.getImageWidth(); l++) {
pixel.setARGBValue(img.getARGBValue(l, k));
if (Math.abs(pixel.r - bgRed) > 29.0 && Math.abs(pixel.g - bgGreen) > 15.0 && Math.abs(pixel.b - bgBlue) > 78.0) {
coverage++;
}
}
}
}
return (double) coverage / (double) maxCoverage;
}
Aggregations