Here you can find the source of filterDetectLines(BufferedImage img)
public static BufferedImage filterDetectLines(BufferedImage img)
//package com.java2s; //License from project: Apache License import java.awt.Color; import java.awt.image.BufferedImage; public class Main { public static BufferedImage filterDetectLines(BufferedImage img) { int x, y; int r, ra, rb; final int w = img.getWidth(); final int h = img.getHeight(); final BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); /* Remove white lines */ for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { r = new Color(img.getRGB(x, y)).getRed(); dst.setRGB(x, y, img.getRGB(x, y)); if (y > 0 && y < h - 1) { ra = new Color(img.getRGB(x, y - 1)).getRed(); rb = new Color(img.getRGB(x, y + 1)).getRed(); if (r > ra && (r - ra) * (r - rb) > 5000) { dst.setRGB(x, y, new Color(ra, ra, ra).getRGB()); }//from w w w . j a va2s . c o m } } } /* Remove black lines */ for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { r = new Color(img.getRGB(x, y)).getRed(); if (y > 0 && y < h - 1) { ra = new Color(img.getRGB(x, y - 1)).getRed(); rb = new Color(img.getRGB(x, y + 1)).getRed(); if (r < ra && (r - ra) * (r - rb) > 500) { dst.setRGB(x, y, new Color(ra, ra, ra).getRGB()); } } } } return dst; } }