Class AlgorithmBilateralFilter
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.filters.AlgorithmBilateralFilter
-
- All Implemented Interfaces:
AlgorithmInterface
,java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmBilateralFilter extends AlgorithmBase implements AlgorithmInterface
Bilateral filtering smooths an image or VOI region of the image while preserving edges with 2 Gaussian functions. One is a Gaussian at a user defined spatial scale (sigma - standard deviation) and the second is a Gaussian at a user defined intensity scale. The spatial Gaussian weighs pixels with smaller spatial separations more heavily and the intensity Gaussian weighs pixels with similar intensities more heavily. RGB values are converted to CIELab values and the color distance is found using the CIE76 distance metric in CIELab space. The convolution is performed in CIELab space. Then CIELab is converted back to RGB. In contrast to standard Gaussian spatial smoothing, bilateral filtering produces no phantom colors along edges in color images, and reduces phantom colors where they appear in the original image.1D Gaussian = (1/sqrt(2*PI*sigma*sigma))*exp(-x*x/(2*sigma*sigma));
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 = 108.883. References: 1.) C. Tomasi and R. Manduchi, "Bilateral Filtering for Gray and Color Images", Proceedings of the 1998 IEEE International Conference on Computer Vision, Bombay, India. 2.)Sylvain Paris, Pierre Kornprobst, Jack Tumblin, and Fredo Durand, "A Gentle Introduction to Bilateral Filtering and its Applications", SIGGRAPH 2007. 3.) 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. The routine bilateralFilter is obtained from the modification of code in OpenCl code in bilateral_filter-dispatch.cpp with the following license: M/////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // // By downloading, copying, installing or using the software you agree to this license. // If you do not agree to this license, do not download, install, // copy or use the software. // // // License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, 2018, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. // Copyright (C) 2014-2015, Itseez Inc., all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistribution's of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistribution's in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * The name of the copyright holders may not be used to endorse or promote products // derived from this software without specific prior written permission. // // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. // In no event shall the Intel Corporation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused // and on any theory of liability, whether in contract, strict liability, // or tort (including negligence or otherwise) arising in any way out of // the use of this software, even if advised of the possibility of such damage. // //M- Version:
- 0.1 February 5, 2009
- Author:
- William Gandler
- See Also:
GenerateGaussian
,AlgorithmConvolver
-
-
Field Summary
Fields Modifier and Type Field Description int
BORDER_CONSTANT
int
BORDER_DEFAULT
int
BORDER_REFLECT
int
BORDER_REFLECT_101
int
BORDER_REPLICATE
int
BORDER_WRAP
private ModelImage
cieLabImage
private boolean
entireImage
Flag, if true, indicates that the whole image should be processed.private float[]
GaussData
Storage location of the Gaussian kernel.private double
imageMax
private float
intensityFraction
units of intensity range; it is multiplied by the intensity range to create intensitySigmaprivate double
intensityGaussianDenom
private int[]
kExtents
Dimensionality of the kernel.private double
scaleMax
private float[]
sigmas
Standard deviations of the gaussian used to calculate the kernels.private ModelImage
targetImage
private boolean
useProgressBar
-
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 AlgorithmBilateralFilter()
AlgorithmBilateralFilter(ModelImage srcImg, float[] sigmas, float intensityFraction, boolean maskFlag, boolean img25D, boolean useProgressBar)
Creates a new AlgorithmBilateralFilter object.AlgorithmBilateralFilter(ModelImage destImg, ModelImage srcImg, float[] sigmas, float intensityFraction, boolean maskFlag, boolean img25D, boolean useProgressBar)
Constructor which sets the source and destination images, the minimum and maximum progress value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
algorithmPerformed(AlgorithmBase algorithm)
Called after an algorithm this listener is registered to exits (maybe successfully, maybe not).double[][]
bilateralFilter(double[][] src, int channels, int d, double sigmaColor, double sigmaSpace, int borderType)
private void
convertCIELabtoRGB(float[] buffer)
private void
convertRGBtoCIELab()
double[][]
copyMakeBorder(double[][] src, int top, int bottom, int left, int right, int borderType, double borderValue)
void
finalize()
Prepares this class for destruction.private void
makeKernels2D()
Creates 2D Gaussian kernels for the blurring process.private void
makeKernels3D()
Creates 3D Gaussian kernels for the blurring process.void
runAlgorithm()
Starts the program.-
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
-
BORDER_CONSTANT
public final int BORDER_CONSTANT
- See Also:
- Constant Field Values
-
BORDER_REPLICATE
public final int BORDER_REPLICATE
- See Also:
- Constant Field Values
-
BORDER_REFLECT
public final int BORDER_REFLECT
- See Also:
- Constant Field Values
-
BORDER_WRAP
public final int BORDER_WRAP
- See Also:
- Constant Field Values
-
BORDER_REFLECT_101
public final int BORDER_REFLECT_101
- See Also:
- Constant Field Values
-
BORDER_DEFAULT
public final int BORDER_DEFAULT
- See Also:
- Constant Field Values
-
entireImage
private boolean entireImage
Flag, if true, indicates that the whole image should be processed. If false on process the image over the mask areas.
-
GaussData
private float[] GaussData
Storage location of the Gaussian kernel.
-
kExtents
private int[] kExtents
Dimensionality of the kernel.
-
sigmas
private float[] sigmas
Standard deviations of the gaussian used to calculate the kernels.
-
intensityFraction
private float intensityFraction
units of intensity range; it is multiplied by the intensity range to create intensitySigma
-
intensityGaussianDenom
private double intensityGaussianDenom
-
targetImage
private ModelImage targetImage
-
cieLabImage
private ModelImage cieLabImage
-
imageMax
private double imageMax
-
scaleMax
private double scaleMax
-
useProgressBar
private boolean useProgressBar
-
-
Constructor Detail
-
AlgorithmBilateralFilter
public AlgorithmBilateralFilter()
-
AlgorithmBilateralFilter
public AlgorithmBilateralFilter(ModelImage srcImg, float[] sigmas, float intensityFraction, boolean maskFlag, boolean img25D, boolean useProgressBar)
Creates a new AlgorithmBilateralFilter object.- Parameters:
srcImg
- DOCUMENT ME!sigmas
- DOCUMENT ME!intensityFraction
-maskFlag
- DOCUMENT ME!img25D
- DOCUMENT ME!useProgressBar
-
-
AlgorithmBilateralFilter
public AlgorithmBilateralFilter(ModelImage destImg, ModelImage srcImg, float[] sigmas, float intensityFraction, boolean maskFlag, boolean img25D, boolean useProgressBar)
Constructor which sets the source and destination images, the minimum and maximum progress value.- Parameters:
destImg
- the destination imagesrcImg
- the source imagesigmas
- the sigmasintensityFraction
- units of intensity range; it is multiplied by the intensity range to create intensitySigmamaskFlag
- the mask flagimg25D
- the 2.5D indicatoruseProgressBar
-
-
-
Method Detail
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalize
in classAlgorithmBase
-
runAlgorithm
public void runAlgorithm()
Starts the program.- Specified by:
runAlgorithm
in classAlgorithmBase
-
makeKernels2D
private void makeKernels2D()
Creates 2D Gaussian kernels for the blurring process. The kernel size is always odd and proportional (8X) to the standard deviation of the Gaussian.
-
makeKernels3D
private void makeKernels3D()
Creates 3D Gaussian kernels for the blurring process. The kernel size is always odd and proportional (8X) to the standard deviation of the Gaussian.
-
algorithmPerformed
public void algorithmPerformed(AlgorithmBase algorithm)
Description copied from interface:AlgorithmInterface
Called after an algorithm this listener is registered to exits (maybe successfully, maybe not). If the algorithm is run in a separate thread, this call will be made within that thread. If not, this call will be made from that same, shared thread.- Specified by:
algorithmPerformed
in interfaceAlgorithmInterface
- Parameters:
algorithm
- the algorithm which has just completed
-
convertRGBtoCIELab
private void convertRGBtoCIELab()
-
convertCIELabtoRGB
private void convertCIELabtoRGB(float[] buffer)
-
bilateralFilter
public double[][] bilateralFilter(double[][] src, int channels, int d, double sigmaColor, double sigmaSpace, int borderType)
-
copyMakeBorder
public double[][] copyMakeBorder(double[][] src, int top, int bottom, int left, int right, int borderType, double borderValue)
-
-