Here you can find the source of filterContrast(BufferedImage img)
public static BufferedImage filterContrast(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 filterContrast(BufferedImage img) { final int[] histo = new int[256]; int x, y, i, min = 255, max = 0; int r;//from w w w.j av a 2s . c om final int w = img.getWidth(); final int h = img.getHeight(); final BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { r = new Color(img.getRGB(x, y)).getGreen(); if (r < min) { min = r; } if (r > max) { max = r; } } } if (min == max) { histo[min] = 127; } else { for (i = min; i < max + 1; i++) { histo[i] = (i - min) * 255 / (max - min); } } for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { r = new Color(img.getRGB(x, y)).getGreen(); dst.setRGB(x, y, new Color(histo[r], histo[r], histo[r]).getRGB()); } } return dst; } }