Package gov.nih.mipav.model.algorithms
Class AlgorithmHistogramMatch
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmHistogramMatch
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmHistogramMatch extends AlgorithmBase
Algorithm that matches the transforms a match or source image so as to make its histogram equal to the histogram of a base image. In order to easily note the great similarity of the histograms, the histogram displays must both be in linear mode rather than log mode so that small differences are not exaggerated. The algorithm is as follows: 1.) Make the histogram for the match image. 2.) Make the histogram cumulative. 3.) Create the scaled cumulative histogram mapping scaled so that the last bin of mapping has the range of the source image. 4.) For the base image create a histogram with the same number of bins as the match image. 5.) Make the histogram cumulative. 6.) Create the scaled cumulative histogram cumHist scaled so that the last bin of cumHist has the range of the source image. 7.) For each value of mapping[i] find the cumHist[j] that is closest in value. 8.) In remap[i] put the value of srcImage corresponding to the jth bin. 9.) For each srcBuffer[i] find the bin number brightnessLevel and replace the srcBuffer[i] with the remap[brightnessLevel]. References: 1.) Digital Image Processing by Rafael C. Gonzalez and Richard E. Woods, Addison-Wesley Publishing Company, 1992, pp. 173-182. 2.) Two-Dimensional Signal and Image Processing by Jae S. Lim, Prentice-Hall, Inc., 1990, pp. 453-459.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.
-
-
Field Summary
Fields Modifier and Type Field Description private ModelImage
baseImage
DOCUMENT ME!private boolean
bChannel
DOCUMENT ME!private float
bufMax
DOCUMENT ME!private float
bufMin
DOCUMENT ME!private boolean
gChannel
DOCUMENT ME!private boolean
isColorImage
DOCUMENT ME!private boolean
rChannel
DOCUMENT ME!private int
valuesPerPixel
DOCUMENT ME!-
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 AlgorithmHistogramMatch(ModelImage srcImg, ModelImage baseImage)
Constructor for 3D images in which changes are returned to the source image.AlgorithmHistogramMatch(ModelImage destImg, ModelImage srcImg, ModelImage baseImage)
Constructor for 3D 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
calcInPlace()
Histogram matching of the source image to the base image.private void
calcStoreInDest()
This function produces a new image that has had itself histogram matched to the base image. places filtered image in the destination image.private void
filter(float[] srcBuffer, float[] baseBuffer)
just break up each RGB image into these separate monochrome images sliceFilter and then reassemble int aRGB.void
finalize()
Prepares this class for destruction.private void
findBufferMinMax(float[] buf, int bufStart, int bufEnd)
Finds the local maximum and minimum values in the given range in order, as given by the starting and stoping values.private float
getIdealWidth(float[] srcBuffer)
Calculate idealWidth for bins.void
runAlgorithm()
starts the algorithm.-
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
-
baseImage
private ModelImage baseImage
DOCUMENT ME!
-
bChannel
private boolean bChannel
DOCUMENT ME!
-
bufMax
private float bufMax
DOCUMENT ME!
-
bufMin
private float bufMin
DOCUMENT ME!
-
gChannel
private boolean gChannel
DOCUMENT ME!
-
isColorImage
private boolean isColorImage
DOCUMENT ME!
-
rChannel
private boolean rChannel
DOCUMENT ME!
-
valuesPerPixel
private int valuesPerPixel
DOCUMENT ME!
-
-
Constructor Detail
-
AlgorithmHistogramMatch
public AlgorithmHistogramMatch(ModelImage srcImg, ModelImage baseImage)
Constructor for 3D images in which changes are returned to the source image.- Parameters:
srcImg
- source image modelbaseImage
- image whose histogram serves as a model
-
AlgorithmHistogramMatch
public AlgorithmHistogramMatch(ModelImage destImg, ModelImage srcImg, ModelImage baseImage)
Constructor for 3D images in which changes are placed in a predetermined destination image.- Parameters:
destImg
- image model where result image is to storedsrcImg
- source image modelbaseImage
- image whose histogram serves as a model
-
-
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
-
calcInPlace
private void calcInPlace()
Histogram matching of the source image to the base image. Replaces the original image with the filtered image.
-
calcStoreInDest
private void calcStoreInDest()
This function produces a new image that has had itself histogram matched to the base image. places filtered image in the destination image.
-
filter
private void filter(float[] srcBuffer, float[] baseBuffer)
just break up each RGB image into these separate monochrome images sliceFilter and then reassemble int aRGB.- Parameters:
srcBuffer
- source bufferbaseBuffer
- base Buffer
-
getIdealWidth
private float getIdealWidth(float[] srcBuffer)
Calculate idealWidth for bins.
-
findBufferMinMax
private void findBufferMinMax(float[] buf, int bufStart, int bufEnd)
Finds the local maximum and minimum values in the given range in order, as given by the starting and stoping values.- Parameters:
buf
- float array of valuesbufStart
- where to begin lookingbufEnd
- where to stop
-
-