Class 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 Detail

      • 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
      • 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 image
        srcImg - the source image
        sigmas - the sigmas
        intensityFraction - units of intensity range; it is multiplied by the intensity range to create intensitySigma
        maskFlag - the mask flag
        img25D - the 2.5D indicator
        useProgressBar -
    • Method Detail

      • finalize

        public void finalize()
        Prepares this class for destruction.
        Overrides:
        finalize in class AlgorithmBase
      • 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 interface AlgorithmInterface
        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)