more using stuff

This commit is contained in:
JFronny 2021-07-07 09:50:18 +02:00
parent 3ef211f082
commit f867e40ca8
4 changed files with 22 additions and 7 deletions

View File

@ -26,7 +26,7 @@ public class Main {
pict = stackViewer.push(UtilGeometric.rotate(pict, UtilGeometric.RotateMode.Left));
pict = stackViewer.push(UtilGeometric.rotate(pict, UtilGeometric.RotateMode.Right));
pict = stackViewer.push(UtilGeometric.mirror(pict, UtilGeometric.MirrorMode.Vertical));
//pict = stackViewer.push(ImageUtil.blurBox(pict, 10));
stackViewer.push(UtilMatrix.blurBox(new Picture(pict), 10));
pict = stackViewer.push(UtilMatrix.blurGauss(pict, 3, 2));
pict = stackViewer.push(UtilMatrix.sharpen(pict, 3));
pict = stackViewer.push(UtilColor.invert(pict));
@ -34,7 +34,10 @@ public class Main {
pict = stackViewer.push(UtilColor.tint(pict, new Color(255, 0, 0, 128)));
pict = stackViewer.push(UtilColor.tint(pict, new Color(0, 255, 0, 0)));
pict = stackViewer.push(UtilColor.tint(pict, new Color(0, 0, 255, 255)));
pict = stackViewer.push(UtilColor.grayscale(pict));
stackViewer.push(UtilColor.grayscale(new Picture(pict), UtilColor.GrayscaleMode.Avg));
stackViewer.push(UtilColor.grayscale(new Picture(pict), UtilColor.GrayscaleMode.Min));
stackViewer.push(UtilColor.grayscale(new Picture(pict), UtilColor.GrayscaleMode.Max));
pict = stackViewer.push(UtilColor.grayscale(pict, UtilColor.GrayscaleMode.Natural));
pict.save(run.resolve("moscov.png"));
stackViewer.repaint();
} catch (IOException e) {

View File

@ -3,10 +3,13 @@ package io.gitlab.jfronny.ImgJava.imageProcessing;
import io.gitlab.jfronny.ImgJava.util.MColor;
import io.gitlab.jfronny.ImgJava.util.Picture;
import javax.swing.plaf.metal.MetalIconFactory;
import java.awt.*;
public class UtilColor {
public enum GrayscaleMode {
Avg, Min, Max, Natural
}
public static Picture tint(Picture picture, Color tint) {
int w = picture.getWidth();
int h = picture.getHeight();
@ -93,7 +96,7 @@ public class UtilColor {
return picture;
}
public static Picture grayscale(Picture picture) {
public static Picture grayscale(Picture picture, GrayscaleMode mode) {
int w = picture.getWidth();
int h = picture.getHeight();
@ -103,8 +106,12 @@ public class UtilColor {
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
Color c = pixel[x][y];
int n = c.getRed() + c.getGreen() + c.getBlue();
n /= 3;
int n = MColor.clamp(switch (mode) {
case Avg -> (c.getRed() + c.getGreen() + c.getBlue()) / 3d;
case Max -> Math.max(Math.max(c.getRed(), c.getBlue()), c.getGreen());
case Min -> Math.min(Math.min(c.getRed(), c.getBlue()), c.getGreen());
case Natural -> c.getRed() * 0.299d + c.getGreen() * 0.587d + c.getBlue() * 0.114d;
});
pixelNeu[x][y] = new Color(n, n, n, c.getAlpha());
}
}

View File

@ -27,7 +27,7 @@ public class MColor {
return new Color(clamp(r), clamp(g), clamp(b), clamp(a));
}
private static int clamp(double d) {
public static int clamp(double d) {
return (int)Math.round(Math.max(Math.min(d, 255), 0));
}

View File

@ -74,6 +74,11 @@ public class Picture {
public Picture(int width, int height) {
this(width, height, "D0D0D0");
}
public Picture(Picture pict) {
this(pict.getWidth(), pict.getHeight());
setPixelArray(pict.getPixelArray());
}
/**
* Erzeugt ein Bild aus einer Datei