Class AlgorithmAHE
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmAHE
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmAHE extends AlgorithmBase
algorithm to apply an adaptive histogram to an image, placing it in a new ModelImage, or returning the changed picture to the same image. Running this algorithm with anull
destination image causes the algorithm to replace the source image with the resultant image.This is a 'regional' algorithm, that is it divides the image buffer into (mostly) equi-sized regions (a 'window') and forms the histogram from that region. The value of the cell (the brightness of the pixel at a particular location) is then mapped to the region. Over the entire image, this means that all pixels will still be brighter or darker than other pixels, but the brightness has been shifted making minor variations more apparent. The cumulative distribution is changed so that it becomes step-wise linear, making the darker pixels use the lowest possible values available to the image, the brightest use the highest possible values.
This algorithm may be used to perform a contrast-limited or 'clamped' histogram equalization. It is set by supplying a percentage of the maximum number of pixels in any particular brightness level. As the regional histograms are tabulated, the brightness with the maximum number of pixels attributed to it is remembered. The algorithm will then evenly redistibute the total number of pixels from any brightness which has a greater number than the max times this fraction to all other (less populous) brightnesses. (If the supplied per-centage is 80, for Instance, the maximum number of pixels to any brightness level, will be four-fifths the largest number number of pixels of any shade found.
The principle methodology of this algorithm, is to take each window, form a histogram; clamp so there is no brightness which can have more than a certain number of pixels; scale the brightnesses so that the values are spread evenly from the maximum to the minimum brightness. (ie., scale * histo(i)).
- Primary source: Stark, J Alex. Adaptive Image Contrast Enhancement Using Generalizations of Histgram Equalization.
- Background Information:
- Russ, John. Image Processing HandbookM.
- Tidestav, Claes. Short Introduction to Adaptive Equalization.
- Rabie, Tamer; Rangayan, Rangaraj; Paranjape, Raman. Adaptive-Neighborhood Image Deblurring.
- Lyon, Douglas. Image Processing in Java
According to Freedman and Diaconis as summarized in "Recent Developments in NonParametric Density Estimation" by Alan Julian Izenman, Journal of the American Statistical Association, March, 1991, Vol. 86, No. 413, pp. 205 - 224: The ideal histogram bin width W is given by W = 2(IQR)pow(N,-1/3) where IQR is the inrterquartile range(the 75 percentile minus the 25th percentile) and N is the number of available samples.
The three coordinates of CIELAB represent the lightness of the color(L* = 0 yields black and L* = 100 indicates diffuse white; specular white may be higher), its position between red/magenta and green(a*, negative values indicate green while positive values indicate magenta) and its position between yellow and blue(b*, negative values indicate blue and positive values indicate yellow). The asterisk(*) after L, a, and b are part of the full name, since they represent L*, a*, and b*, to distinguish them from Hunter's L, a, and b. The L* coordinate ranges from 0 to 100. The possible range of a* and b* coordinates depends on the color space that one is converting from. R = 0, G = 0, B = 0 => L* = 0, a* = 0, b* = 0 R = 255, G = 0, B = 0 => L* = 53.2, a* = 80.1, b* = 67.22 R = 0, G = 255, B = 0 => L* = 87.7, a* = -86.2, b* = 83.2 R = 0, G = 0, B = 255 => L* = 32.3, a* = 79.2, b* = -107.9 R = 255, G = 255, B = 0 => L* = 97.1, a* = -21.6, b* = 94.5 R = 255, G = 0, B = 255 => L* = 60.3, a* = 98.3, b* = -60.8 R = 0, G = 255, B = 255 => L* = 91.1, a* = -48.1, b* = -14.1 R = 255, G = 255, B = 255 => L* = 100.0, a* = 0.00525, b* = -0.0104 so the range of a* equals about the range of b* and the range of a* equals about twice the range of L*. The simplest distance metric delta E is CIE76 = sqrt((L2* - L1*)**2 + (a2* - a1*)**2 + (b2* - b1*)**2) XW, YW, and ZW (also called XN, YN, ZN or X0, Y0, Z0) are reference white tristimulus values - typically the white of a perfectly reflecting diffuser under CIE standard D65 illumination(defined by x = 0.3127 and y = 0.3291 in the CIE chromatcity diagram). The 2 degrees, D65 reference tristimulus values are: XN = 95.047, YN = 100.000, and ZN = 1 http://www.easyrgb.com has XYZ -> RGB, RGB -> XYZ, XYZ -> CIEL*ab, CIEL*ab -> XYZ, and XYZ(Tristimulus) Reference values of a perfect reflecting diffuser. Smoothing vs. sharpening of color images - Together or separated by Cristina Perez, Samuel Morillas, and Alberto Conejero, June, 2017. "Histogram equalization is a non-linear process and involves intensity values of the image and not the color components For these reasons, channel splitting and equalizing each channel separately is not the proper way for equalization of contrast. So, the first step is to convert the color space of the image from RGB into other color space which separates intensity values from color components such as HSV, YCbCr, or Lab, and apply equalization over the H, Y, or L channel respectively."- Version:
- 1.01; 20 Sep 2001
- Author:
- David Parsons (parsonsd), Matthew J. McAuliffe, Ph.D.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
bChannel
If true filter the blue channel.private float
bufMax
DOCUMENT ME!private float
bufMin
DOCUMENT ME!private boolean
clamped
Perform a "contrast limited" AHE.private float
clipLevel
DOCUMENT ME!private boolean
gChannel
If true filter the green channel.private int
hDivisions
number of divisions to make in the height.private double
imageMax
private float
imageOffset
DOCUMENT ME!private boolean
isColorImage
Indicates the image being messed with is a color image.private boolean
rChannel
If true filter the red channel.private double
scaleMax
private float[]
sortBuffer
DOCUMENT ME!private boolean
useCIELab
private int
valuesPerPixel
Number of elements in a pixel.private int
wDivisions
number of divisions to make in the width.-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmAHE(ModelImage srcImg, int hd, int wd, boolean useCIELab)
Constructor for images in which changes are returned to the source image.AlgorithmAHE(ModelImage destImg, ModelImage srcImg, int hd, int wd, boolean useCIELab)
Constructor for images in which changes are placed in a predetermined destination image.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
calcInPlace2D()
Histogram equalization on the source image.private void
calcInPlace3D()
Histogram Equalization on the source image and replaces the source image with the processed image.private void
calcStoreInDest2D()
This function produces a new image that has had itself histogram equalized. places filtered image in the destination image.private void
calcStoreInDest3D()
This function produces a new volume image that has been histogram equalized.private void
clip(int binNumber, int[] histogram, int clipLimit)
after generating a histogram,clip
will reduce the number of pixels attributed to that brightness level.private void
convertCIELabtoRGB(float[] L, float[] a, float[] b, float[] buffer)
private void
convertRGBtoCIELab(float[] buffer, float[] L, float[] a, float[] b)
private void
copyBuffers(float[] dest, float[] src)
Copies all values from the srcbuffer to the destination buffer. the format is intended to envision the organisation of dest[i] := src[i] float dest destination array float src source arrayvoid
finalize()
Prepares this class for destruction.protected void
findImageOffset(int type)
gets the bottom end of the image. for any image but color images, the bottom end is defined as the buffer minimum for all images except color images; there the offset is defined to be zeroprotected int
findTotalBins(int type, int ideal)
finds the total number of bins based on the type of image.private void
monoSliceFilter(float[] srcBuffer, float[] destBuffer)
Allows a single monochrome image slice to be filtered.private void
printhisto(int[] histo)
a debug tool.void
runAlgorithm()
starts the algorithm.void
setClipLevel(int sectorPercentage)
the Clip Level is a percentage of the maximum number of pixels in any particular brightness level.void
setContrastLimited(boolean beClamped)
Redistribute from brightnesses with at a least a specified percentage of the brightness with the maximum number of pixels.void
setRGBChannelFilter(boolean r, boolean g, boolean b)
RGB images are histogram equalized by 'channel.'-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
bChannel
private boolean bChannel
If true filter the blue channel.
-
bufMax
private float bufMax
DOCUMENT ME!
-
bufMin
private float bufMin
DOCUMENT ME!
-
clamped
private boolean clamped
Perform a "contrast limited" AHE.
-
clipLevel
private float clipLevel
DOCUMENT ME!
-
gChannel
private boolean gChannel
If true filter the green channel.
-
hDivisions
private int hDivisions
number of divisions to make in the height.
-
imageOffset
private float imageOffset
DOCUMENT ME!
-
isColorImage
private boolean isColorImage
Indicates the image being messed with is a color image.
-
rChannel
private boolean rChannel
If true filter the red channel.
-
useCIELab
private boolean useCIELab
-
sortBuffer
private float[] sortBuffer
DOCUMENT ME!
-
valuesPerPixel
private int valuesPerPixel
Number of elements in a pixel. Monochrome = 1, Color = 4. (a, R, G, B)
-
wDivisions
private int wDivisions
number of divisions to make in the width.
-
imageMax
private double imageMax
-
scaleMax
private double scaleMax
-
-
Constructor Detail
-
AlgorithmAHE
public AlgorithmAHE(ModelImage srcImg, int hd, int wd, boolean useCIELab)
Constructor for images in which changes are returned to the source image.- Parameters:
srcImg
- source image modelhd
- number of divisions to make of the image heightwd
- number of divisions to make of the image widthuseCIELab
- If color, only equalize on L in CIELab space
-
AlgorithmAHE
public AlgorithmAHE(ModelImage destImg, ModelImage srcImg, int hd, int wd, boolean useCIELab)
Constructor for images in which changes are placed in a predetermined destination image.- Parameters:
destImg
- image model where result image is to storedsrcImg
- source image modelhd
- number of divisions to make of the image heightwd
- number of divisions to make of the image widthuseCIELab
- If color, only equalize on L in CIELab space
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalize
in classAlgorithmBase
-
runAlgorithm
public void runAlgorithm()
starts the algorithm.- Specified by:
runAlgorithm
in classAlgorithmBase
-
setClipLevel
public void setClipLevel(int sectorPercentage)
the Clip Level is a percentage of the maximum number of pixels in any particular brightness level. This method allows one to set that percentage. As the regional histograms are tabulated, the brightness with the maximum number of pixels attributed to it is remembered. The algorithm will then evenly redistibute the total number of pixels from any brightness which has a greater number than the max times this fraction to all other (less populous) brightnesses.- Parameters:
sectorPercentage
- DOCUMENT ME!
-
setContrastLimited
public void setContrastLimited(boolean beClamped)
Redistribute from brightnesses with at a least a specified percentage of the brightness with the maximum number of pixels.- Parameters:
beClamped
- DOCUMENT ME!
-
setRGBChannelFilter
public void setRGBChannelFilter(boolean r, boolean g, boolean b)
RGB images are histogram equalized by 'channel.' That is, each color, red, blue and green, is run independantly of the other two colors. This permits selectively filtering any combination of the three channels instead of simply trying to handle all three at once. True filters that channel.- Parameters:
r
- DOCUMENT ME!g
- DOCUMENT ME!b
- DOCUMENT ME!
-
findImageOffset
protected final void findImageOffset(int type)
gets the bottom end of the image. for any image but color images, the bottom end is defined as the buffer minimum for all images except color images; there the offset is defined to be zero- Parameters:
type
- DOCUMENT ME!
-
findTotalBins
protected final int findTotalBins(int type, int ideal)
finds the total number of bins based on the type of image.- Parameters:
type
- DOCUMENT ME!ideal
- DOCUMENT ME!- Returns:
- the total number of bins.
-
calcInPlace2D
private void calcInPlace2D()
Histogram equalization on the source image. Replaces the original image with the filtered image.
-
calcInPlace3D
private void calcInPlace3D()
Histogram Equalization on the source image and replaces the source image with the processed image.
-
calcStoreInDest2D
private void calcStoreInDest2D()
This function produces a new image that has had itself histogram equalized. places filtered image in the destination image.
-
calcStoreInDest3D
private void calcStoreInDest3D()
This function produces a new volume image that has been histogram equalized. The Image is changed by filtering each slice individually.
-
clip
private void clip(int binNumber, int[] histogram, int clipLimit)
after generating a histogram,clip
will reduce the number of pixels attributed to that brightness level.The idea is to limit any brightness level in the histogram to a set value; the number of pixels that are above the limit are tallied. The total number of pixels that were found above the limit, is then spread evenly among the brightnesses that are below limit.
- Parameters:
binNumber
- the number of brightness levels available in the histogramhistogram
- array where the brightness values of all pixels in the image have been counted.clipLimit
- no brightness may have any more than this number of pixels. Obviously, this method will not achieve anything whenclipLimit
is as large or larger than the largest brightness inhistogram
.
-
copyBuffers
private void copyBuffers(float[] dest, float[] src)
Copies all values from the srcbuffer to the destination buffer. the format is intended to envision the organisation of dest[i] := src[i] float dest destination array float src source array- Parameters:
dest
- DOCUMENT ME!src
- DOCUMENT ME!
-
monoSliceFilter
private void monoSliceFilter(float[] srcBuffer, float[] destBuffer)
Allows a single monochrome image slice to be filtered. Any color image may be processed in this so long as each color plane is separate and provided one at a time. This means, extract [aRGB aRGB ...] buffer into 3 seperate buffers [RRRRRRRRRRR...] , [GGGGGG....] and [BBBBBBBB] and feed each into the sliceFilter one-at-a-time.The benefit is one sliceFilter for all image types; just break up each RGB image into these separate monochrome images sliceFilter and then reassemble int aRGB.
Only length of one slice (image.getExtents[0] * image.getExtents[1]) Will be copied at a time. Note that a progressBar is not changed in this method.
- Parameters:
srcBuffer
- source bufferdestBuffer
- destination Buffer
-
printhisto
private void printhisto(int[] histo)
a debug tool.- Parameters:
histo
- DOCUMENT ME!
-
convertRGBtoCIELab
private void convertRGBtoCIELab(float[] buffer, float[] L, float[] a, float[] b)
-
convertCIELabtoRGB
private void convertCIELabtoRGB(float[] L, float[] a, float[] b, float[] buffer)
-
-