Java BufferedImage Filter filterDetectLines(BufferedImage img)

Here you can find the source of filterDetectLines(BufferedImage img)

Description

filter Detect Lines

License

Apache License

Declaration

public static BufferedImage filterDetectLines(BufferedImage img) 

Method Source Code


//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;
    }
}

Related

  1. applyFilter(BufferedImage img, BufferedImageOp filter)
  2. applyFilter(BufferedImage img, ImageFilter filter)
  3. applyFilter(LookupTable lookupTable, BufferedImage srcImg)
  4. filter(BufferedImage image, BufferedImageOp op)
  5. filterContrast(BufferedImage img)
  6. filterFillHoles(BufferedImage img)
  7. filterImage(BufferedImageOp bufferedImageOp, BufferedImage srcImg, BufferedImage dstImg)
  8. filterMedian(BufferedImage img)
  9. filterScale(BufferedImage img, float ratio)