Java examples for 2D Graphics:BufferedImage Effect
Image dilation
//package com.java2s; public class Main { public static int[][] dilation(int[][] image) { int w = image[0].length; int h = image.length; int[][] retVal = new int[h][w]; int[] ii = { 0, 1, 0, -1, 0 }; int[] jj = { 1, 0, -1, 0, 0 }; int n = ii.length; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int count = 0; for (int t = 0; t < n; t++) { if (y + ii[t] < 0 || y + ii[t] >= h || x + jj[t] < 0 || x + jj[t] >= w) { continue; }/* w w w . ja v a 2s . c o m*/ if (image[y + ii[t]][x + jj[t]] == 0) { count++; } } retVal[y][x] = count >= 2 ? 0 : 255; } } return retVal; } }