one.empty3.feature.Classification Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of empty3-library-3d Show documentation
Show all versions of empty3-library-3d Show documentation
3D rendering engine. Plus modeling. Expected glsl textures 3d and 2d rendering
/*
* Copyright (c) 2022-2023. Manuel Daniel Dahmen
*
*
* Copyright 2012-2023 Manuel Daniel Dahmen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package one.empty3.feature;
import one.empty3.io.ProcessFile;
import one.empty3.library.Lumiere;
import one.empty3.library.core.lighting.Colors;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
public class Classification extends ProcessFile {
Random random = new Random();
private BufferedImage imageOut;
private int SIZE = 5;
private double ratio = 0.3;
private double threshold = 0.3;
@Override
public boolean process(final File in, final File out) {
if (!in.getName().endsWith(".jpg"))
return false;
PixM selectPointColorMassAglo = null;
BufferedImage read = null;
try {
read = ImageIO.read(in);
selectPointColorMassAglo = PixM.getPixM(read, maxRes);
} catch (Exception ex) {}
try {
imageOut = ImageIO.read(in);
} catch (Exception ex) {}
assert selectPointColorMassAglo != null;
SelectPointColorMassAglo selectPointColorMassAglo1 = new SelectPointColorMassAglo(read);
int color = Color.WHITE.getRGB();
for (int i = 0; i < selectPointColorMassAglo1.getColumns(); i += 1)
for (int j = 0; j < selectPointColorMassAglo1.getLines(); j += 1) {
selectPointColorMassAglo1.setTmpColor(Colors.random());
double v = selectPointColorMassAglo1.averageCountMeanOf(i, j, SIZE, SIZE, threshold);
if (v > ratio) {
imageOut.setRGB(i, j, color);/*selectPointColorMassAglo.getChosenColor().getRGB()*/
} else {
double[] doubles = Lumiere.getDoubles(read.getRGB(i, j));
/*for(int c=0; c<3; c++)
doubles[c] = doubles[c]/3;
*/
imageOut.setRGB(i, j, Lumiere.getInt(doubles));
}
}
try {
ImageIO.write(imageOut, "jpg", out);
} catch (Exception ex) {}
return true;
}
public double getThreshold() {
return threshold;
}
public void setThreshold(double threshold) {
this.threshold = threshold;
}
}