Here you can find the source of filterThreshold(BufferedImage img, int threshold)
public static BufferedImage filterThreshold(BufferedImage img, int threshold)
//package com.java2s; //License from project: Apache License import java.awt.Color; import java.awt.image.BufferedImage; public class Main { public static BufferedImage filterThreshold(BufferedImage img, int threshold) { final int w = img.getWidth(); final int h = img.getHeight(); final BufferedImage newImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Color min = Color.BLACK; Color max = Color.WHITE; if (threshold < 0) { min = Color.WHITE;/*from w w w . j a v a 2 s. c o m*/ max = Color.BLACK; threshold = -threshold; } threshold *= 3; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { final Color color = new Color(img.getRGB(x, y)); if (color.getRed() + color.getGreen() + color.getBlue() < threshold) { newImg.setRGB(x, y, min.getRGB()); } else { newImg.setRGB(x, y, max.getRGB()); } } } return newImg; } }