Java BufferedImage Filter filterContrast(BufferedImage img)

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

Description

filter Contrast

License

Apache License

Declaration

public static BufferedImage filterContrast(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 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;
    }
}

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. filterDetectLines(BufferedImage img)
  6. filterFillHoles(BufferedImage img)
  7. filterImage(BufferedImageOp bufferedImageOp, BufferedImage srcImg, BufferedImage dstImg)
  8. filterMedian(BufferedImage img)