Class BrightnessContrastFilter

java.lang.Object
  extended by java.awt.image.ImageFilter
      extended by java.awt.image.RGBImageFilter
          extended by BrightnessContrastFilter
All Implemented Interfaces:
java.awt.image.ImageConsumer, java.lang.Cloneable

public class BrightnessContrastFilter
extends java.awt.image.RGBImageFilter

Class BrightnessContrastFilter implements RGBFilter for image adjustment to implement a contrast/brightness filter. It maps the unscaled (brightness,contrast) values with maximum (maxBrightness,maxContrast) to brightness and contrast values (bScaled,cScaled) in [0.0:1.0]. The Filter maps RGB pixel values to a new RGB pixel value as a function of (bScaled,cScaled) and the (maxGray,minG,maxG) of the image.

 The brightness, contrast model assumes that the half-way range of 
 each is the original image value. The transform  for the new gray value
 g' is:
       g' = slopeC*g + bIntercept.

 These are derived as follows:
       maxSlopeC= maxGray / (maxG - minG),
       bIntercept = (bScaled - 0.5) * (2 * maxGray).
 We then  compute the contrast intercept to cover the complete range
 so that
   1. if cScaled=1.0, then slopeC= maxSlopeC,
   2. if cScaled=0.5, then slopeC= 1.0.
 Then,
       ssM= maxSlopeC-1.0) / 0.5,
       ssB= (0.5 * maxSlopeC + 2),
 and then,
       slopeC= ssM*cScaled + ssB.    
The filtering part is derived from the code in the Chan & Lee "The Java Class Library", (JDK1.0.2) pg 1143.

This is also similar to the example in the more recent JavaClassLibJDK1.1.2/JavaClassVol2/java/awt.image/ RGBImageFilter/canFilterIndexColorModel

This work was produced by Peter Lemkin of the National Cancer Institute, an agency of the United States Government. As a work of the United States Government there is no associated copyright. It is offered as open source software under the Mozilla Public License (version 1.1) subject to the limitations noted in the accompanying LEGAL file. This notice must be included with the code. The Flicker Mozilla and Legal files are available on http://open2dprot.sourceforge.net/Flicker

Version:
$Date$ $Revision$
Author:
P. Lemkin (LECB/NCI), G. Thornwall (SAIC), Frederick, MD
See Also:
Flicker Home

Field Summary
(package private)  int b
          current BLUE pixel when filter is running
(package private)  float bIntercept
          brightness intercept is (bS -0.5)*(2*maxGray)
(package private)  float bScaled
          scaled current brightness value to range of [0:1.0]
(package private)  int colorMode
          method to use when filter RBG: (NORM_COLOR, PSEUDO_COLOR, RGB_TO_GRAY_COLOR)
(package private)  float cScaled
          scaled current contrast value to range of [0:1.0]
private static int dbugCtr
           
(package private) static Flicker flk
          flicker instance
(package private)  int g
          current GREEN pixel when filter is running
(package private)  float hue
          current hue pixel value when HSV filtering
(package private)  ImageScroller is
          The Image Scroller for the image data to compute filter on
 int maxG
          maximum Gray value seen in the original inputpixels[].
(package private)  int maxGray
           
(package private)  float maxSlopeC
          maximum contrast needed to cover the maximum dynamic range compute as: maxSlopeC= maxGray/(maxG-minG));
 int minG
          minimum Gray value seen in the original inputpixels[].
(package private)  int newRGBpixel
          current new RGB pixel when filter is running
(package private)  boolean pseudoColorFlag
          true if pseudo color else grayscale.
(package private)  int r
          current RED pixel when filter is running
(package private)  int[] rgb3
          array hold return values (R,G,B) for hsv2rgb(H,S,V)
(package private)  boolean rgbToGrayFlag
          cvt RGB to grayscale.
(package private)  float saturation
          current saturation pixel value when HSV filtering
(package private)  float slopeC
          contrast slope is (cS -0.5)*maxSlopeC
(package private)  float value
          current value pixel value when HSV filtering
 
Fields inherited from class java.awt.image.RGBImageFilter
canFilterIndexColorModel, newmodel, origmodel
 
Fields inherited from class java.awt.image.ImageFilter
consumer
 
Fields inherited from interface java.awt.image.ImageConsumer
COMPLETESCANLINES, IMAGEABORTED, IMAGEERROR, RANDOMPIXELORDER, SINGLEFRAME, SINGLEFRAMEDONE, SINGLEPASS, STATICIMAGEDONE, TOPDOWNLEFTRIGHT
 
Constructor Summary
BrightnessContrastFilter(Flicker flkS)
          BrightnessContrastFilter() - constructor.
 
Method Summary
(package private)  char cvByteToChar(byte b)
          cvByteToChar() - convert signed byte [-128:+127] to unsigned char in range [0:255]
(package private)  int cvByteToInt(byte b)
          cvByteToInt() - convert signed byte [-128:+127] to unsigned int in range [0:255]
(package private)  byte cvIntToByte(int i)
          cvIntToByte() - convert int in range [0:255] to signed byte in range of [-128:+127].
 int filterRGB(int x, int y, int rgbPixel)
          filterRGB() - 1:1 pixel filtering required for RGBFilter class.
(package private)  void hsv2rgb(float hue, float saturation, float value, int[] rgb)
          hsv2rgb() - convert (hue,saturation,value) color model to (red,green,blue) color model.
(package private)  void setBrCt(ImageScroller is, int brightness, int contrast, int maxBrightness, int maxContrast, boolean calcBrightnessFlag)
          setBrCt() - set parameters for the filter when it is invoked by pressing or dragging the mouse with the Shift key pressed.
 
Methods inherited from class java.awt.image.RGBImageFilter
filterIndexColorModel, filterRGBPixels, setColorModel, setPixels, setPixels, substituteColorModel
 
Methods inherited from class java.awt.image.ImageFilter
clone, getFilterInstance, imageComplete, resendTopDownLeftRight, setDimensions, setHints, setProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbugCtr

private static int dbugCtr

flk

static Flicker flk
flicker instance


is

ImageScroller is
The Image Scroller for the image data to compute filter on


colorMode

int colorMode
method to use when filter RBG: (NORM_COLOR, PSEUDO_COLOR, RGB_TO_GRAY_COLOR)


rgbToGrayFlag

boolean rgbToGrayFlag
cvt RGB to grayscale. Get from global flag. Only should map RGB to grayscale if not doing sequential transforms since then would transform garbage.


pseudoColorFlag

boolean pseudoColorFlag
true if pseudo color else grayscale. Get from global flag Only should map grayscale to RGB if not doing sequential transforms since then would transform garbage.


rgb3

int[] rgb3
array hold return values (R,G,B) for hsv2rgb(H,S,V)


hue

float hue
current hue pixel value when HSV filtering


saturation

float saturation
current saturation pixel value when HSV filtering


value

float value
current value pixel value when HSV filtering


r

int r
current RED pixel when filter is running


g

int g
current GREEN pixel when filter is running


b

int b
current BLUE pixel when filter is running


newRGBpixel

int newRGBpixel
current new RGB pixel when filter is running


maxGray

int maxGray

maxG

public int maxG
maximum Gray value seen in the original inputpixels[]. -1 means it is not defined.


minG

public int minG
minimum Gray value seen in the original inputpixels[]. -1 means it is not defined.


maxSlopeC

float maxSlopeC
maximum contrast needed to cover the maximum dynamic range compute as: maxSlopeC= maxGray/(maxG-minG));


bIntercept

float bIntercept
brightness intercept is (bS -0.5)*(2*maxGray)


slopeC

float slopeC
contrast slope is (cS -0.5)*maxSlopeC


bScaled

float bScaled
scaled current brightness value to range of [0:1.0]


cScaled

float cScaled
scaled current contrast value to range of [0:1.0]

Constructor Detail

BrightnessContrastFilter

public BrightnessContrastFilter(Flicker flkS)
BrightnessContrastFilter() - constructor.

Method Detail

setBrCt

final void setBrCt(ImageScroller is,
                   int brightness,
                   int contrast,
                   int maxBrightness,
                   int maxContrast,
                   boolean calcBrightnessFlag)
setBrCt() - set parameters for the filter when it is invoked by pressing or dragging the mouse with the Shift key pressed.

Parameters:
is - is the image data to compute filter on
brightness - new value of brightness [0:maxBrightness-1], unscaled
contrast - new value of contrast [0:maxContrast-1], unscaled
maxBrightness - max value of brightness, unscaled
maxContrast - max value of contrast, unscaled
calcBrightnessFlag - use slider values or calc via mousedDragged [DEPRICATED]

hsv2rgb

final void hsv2rgb(float hue,
                   float saturation,
                   float value,
                   int[] rgb)
hsv2rgb() - convert (hue,saturation,value) color model to (red,green,blue) color model. Note: all domains and ranges are 0 to 1.0. This is taken from: R. Sproull, W. Sutherland, and M. Ullner, Device Independent Graphics, McGraw Hill, 1985, page 488.

Parameters:
hue - in the range of [0.0:1.0]
saturation - in the range of [0.0:1.0] default to 1.0
value - of dynamic range
rgb - is the red[0], green[1], blue[3] colormap

cvByteToInt

final int cvByteToInt(byte b)
cvByteToInt() - convert signed byte [-128:+127] to unsigned int in range [0:255]

Parameters:
b - is byte to convert
Returns:

cvByteToChar

final char cvByteToChar(byte b)
cvByteToChar() - convert signed byte [-128:+127] to unsigned char in range [0:255]

Parameters:
b - is byte to convert
Returns:
unsigned char

cvIntToByte

final byte cvIntToByte(int i)
cvIntToByte() - convert int in range [0:255] to signed byte in range of [-128:+127].

Parameters:
i - is integer to convert
Returns:
usigned byte

filterRGB

public int filterRGB(int x,
                     int y,
                     int rgbPixel)
filterRGB() - 1:1 pixel filtering required for RGBFilter class. compute (r,g,b)' = f(r,g,b) where f() is a function of the colorMode (NORM_COLOR,

Specified by:
filterRGB in class java.awt.image.RGBImageFilter
Parameters:
x - coordinate of pixel (not used)
y - coordinate of pixel (not used)
rgb - is pixel (r,g,b) value
Returns:
new filtered pixel (r,g,b) value