Filter Gambar dengan Mean, Median dan Batas Menggunakan Java

Photo by Alexandre Perotto on Unsplash

Ketetanggaan

sumber: http://www.charisfauzan.net/2016/02/operasi-ketetanggaan-piksel-pada-filter.html

Konsep Filter Mean, Median dan Batas

Implementasi Kode

Hasil dan perbandingan gambar original dan masing-masing filter

Bedah Kode

FilterContract.java

Neighbor.java

private int top, right, bottom, left;
private int current, mid;
private Color c;
// tetangga atas
if (row - 1 < 0) {
    top = 0;
} else {
    c = new Color(image.getRGB(row - 1, col));
    top = c.getRed();
}// tetangga kanan
if (col + 1 >= height) {
    right = 0;
} else {
    c = new Color(image.getRGB(row, col + 1));
    right = c.getRed();
}// tetangga bawah
if (row + 1 >= width) {
    bottom = 0;
} else {
    c = new Color(image.getRGB(row + 1, col));
    bottom = c.getRed();
}// tetangga kiri
if (col - 1 < 0) {
    left = 0;
} else {
    c = new Color(image.getRGB(row, col - 1));
    left = c.getRed();
}
int value = 0;
int[] values = {current, top, right, bottom, left};
switch (context) {
    case "median":
        Arrays.sort(values);
        value = values[values.length / 2];
        break;
    case "mean":
        value = Arrays.stream(values).sum() / values.length;
        break;
    case "batas":
        Arrays.sort(values);
        if (current < values[0]) {
            current = values[0];
            break;
        }        if (current > values[values.length-1]) {
            current = values[values.length-1];
            break;
        }        value = current;
        break;
}return value;

Mean.java, Median.java dan Batas.java

private String context = "median";
private BufferedImage image, newImage;
private int width, height;

App.java



Easyread

Easy read, easy understanding. A good writing is a writing that can be understood in easy ways

Mohammad Robih T. Z

Written by

Dokumentasi belajar melalui tulisan. Berbagi tulisan dari hasil belajar. https://biobii.github.io

Easyread

Easyread

Easy read, easy understanding. A good writing is a writing that can be understood in easy ways