Class AlgorithmKernelRegression

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.WindowListener, java.lang.Runnable, java.util.EventListener

    public class AlgorithmKernelRegression
    extends AlgorithmBase

    This is a port of MATLAB routines contained in kernelRegressionBasedImageProcessingToolBox_ver1-2beta written by Hiroyuki Takeda, Sina Farsiu, and Peyman Milanfar.

    References are:

    1. Takeda, H., Farsiu, S., and Milanfar, P., "Kernel Regression for Image Processing and Reconstruction", IEEE Transactions on Image Processing, Vol. 16, No. 2, February, 2007, pp. 349-366.
    2. Takeda, H., Farsiu, S., and Milanfar, P., "Robust Kernel Regression for Restoration and Reconstruction of Images from Sparse Noisy Data", Proceedings of the International Conference on Image Processing (ICIP), Atlanta, Georgia, October, 2006.
    3. Takeda, H., M.S. Thesis, "Kernel Regression for Image Processing and Reconstruction", Electrical Engineering, UC Santa Cruz, March, 2006.

    Convert a black and white image to a color image. Color results for RERGULARLY_SAMPLED_SECOND_ORDER classic are about as clear as the black and white results. For ITERATIVE_STEERING_KERNEL_SECOND_ORDER color results were much blurrier than the black and white results. Since here the color has R = G = B, the conversion to and from CIELab could be omitted. When this was done, then the color results were about as good as the black and white results.

    6 MATLAB example files for using the routines were included in the package. 4 of the 6 files use ckr2_regular followed by a variable number of iterations of the 2 routines steering and skr2_regular. This is the method selected by ITERATIVE_STEERING_KERNEL_SECOND_ORDER. ckr2_regular and skr2_regular output estimated image, vertical gradient, horizontal gradient. Tracing thru the code shows the horizontal gradient outputs go into the zy image gradient in steering and the vertical gradient goes into the zx image gradient in steering. I maintained this order of vertical = 2 and horizontal = 1. For ITERATIVE_STEERING_KERNEL_SECOND_ORDER for 256 by 256 black and white test images consisting of only horizontal gradient, horizontal gradient plus noise, vertical gradient, vertical gradient plus noise, I tested for mean squared error between original gradient image and filtered image. Reverse order seemed best. Used Gaussian noise set at 80 in test generator. Images went from 0 at one side to 255 at the other. Mean squared errors: Horizontal gradient 1 2 0.147917 2 1 0.15333 Horizontal gradient plus noise 1 2 27.91358 2 1 31.66997 Vertical gradient 1 2 0.1627 2 1 0.152878 Vertical gradient plus noise 1 2 26.1865 2 1 29.8788 So at first it seemed that the order should be reversed to 1 2. But then I checked ITER_STEERING_KEERNEL_SECOND_ORDER with 4 iterations on 6 black and white photos with Gaussian noise = 80. cap17black.fits 256 X 256 1 2 71.088 2 1 61.555 einstein.tif 256 X 256 1 2 158.718 2 1 75.609 airfield 512 X 512 1 2 135.985 2 1 129.268 boats 512 X 512 1 2 79.584 2 1 64.735 bridge 512 X 512 1 2 157.756 2 1 138.601 0136_0002_1 library card with bar codes 1 2 235.137 2 1 80.278 So leave order as originally found. Test files corresponding to ITERATIVE_STEERING_KERNEL_SECOND_ORDER: 1.) Lena_denoise.m Denoises Gaussian noise in black and white image . 2.) Pepper_deblock.m Deblocking example in black and white image. 3.) Lena_upscale.m Upscaling. There is only 1 iteration and upscaling occurs in the final skr2_regular rather than in the initial ckr2_regular. Upscaling should only be done on the final skr2_regular. If you upscale on ckr2_regular, you will have to iterate on the larger upscaled image and processing time will be increased. 4.) JFK_denoise.m Film grain removal from color image. Note the MATLAB package converts to YCrCb whereas I convert to CIELab for better luminance separation.

    ITERATIVE_STEERING_KERNEL_SECOND_ORDER_IRREGULAR uses ckr2_irregular followed by a variable number of iterations of the 2 routines steering and skr2_irregular to handle files with missing data points. The upscaling factor always = 1 for this method. Test file corresponding to ITERATIVE_STEERING_KERNEL_SECOND_ORDER_IRREGULAR: Lena_irregular.m

    REGULARLY_SAMPLED_SECOND_ORDER_CLASSIC corresponds to the first routine in ITERATIVE_STEERING_KERNEL_SECOND_ORDER, ckr2_regular.

    The method STEERING_KEERNEL_SECOND_ORDER_L1_NORM corresponds to: 1.) 3 X 3 median filter 2.) ckr2all_regular 3.) ckr2L1_regular 4.) steering 5.) skr2L1_regular. The test file Lena_saltpepper.m reduces salt and pepper noise in a black and white image. Note that the same upscale factor is used in ckr2all_regular, crkrL1_regular, and skr2L1_regular.


    From http://users.soe.ucsc.edu/~htakeda/KernelToolBox.htm:

     This is experimental software. It is provided for noncommercial research purposes only.
        Use at your own risk. No warranty is implied by this distribution.
        Copyright 2007 by University of California.
     
    • Field Detail

      • REGULARLY_SAMPLED_SECOND_ORDER_CLASSIC

        public static final int REGULARLY_SAMPLED_SECOND_ORDER_CLASSIC
        See Also:
        Constant Field Values
      • ITERATIVE_STEERING_KERNEL_SECOND_ORDER

        public static final int ITERATIVE_STEERING_KERNEL_SECOND_ORDER
        See Also:
        Constant Field Values
      • ITERATIVE_STEERING_KERNEL_SECOND_ORDER_IRREGULAR

        public static final int ITERATIVE_STEERING_KERNEL_SECOND_ORDER_IRREGULAR
        See Also:
        Constant Field Values
      • STEERING_KERNEL_SECOND_ORDER_L1_NORM

        public static final int STEERING_KERNEL_SECOND_ORDER_L1_NORM
        See Also:
        Constant Field Values
      • method

        private final int method
        1 of 4 possible sets of routines to be executed
      • hasNaN

        private final boolean hasNaN
        True if irregularly sampled data uses NaNs for missing samples
      • hasInfinity

        private final boolean hasInfinity
        True if irregularly sampled data uses infinities for missing samples
      • hasGreaterEqual

        private final boolean hasGreaterEqual
        True if irregularly sampled data uses numbers >= greaterEqualValue for missing samples
      • greaterEqualValue

        private final double greaterEqualValue
      • hasEqual

        private final boolean hasEqual
        True if irregularly sampled data uses numbers == equalValue for missing samples
      • equalValue

        private final double equalValue
      • hasLesserEqual

        private final boolean hasLesserEqual
        True if irregularly sampled data uses numbers <= lesserEqualValue for missing samples
      • lesserEqualValue

        private final double lesserEqualValue
      • initialGlobalSmoothing

        private final float initialGlobalSmoothing
      • iterativeGlobalSmoothing

        private final float iterativeGlobalSmoothing
      • iterativeGlobalSmoothing2

        private final float iterativeGlobalSmoothing2
        Global smoothing parameter in skr2L1_regular in STEERING_KERNEL_SECOND_ORDER_L1_NORM
      • upscale

        private final int upscale
      • initialKernelSize

        private final int initialKernelSize
        The kernel must be initialKernelSize by initialKernelSize
      • iterativeKernelSize

        private final int iterativeKernelSize
      • iterations

        private final int iterations
        The total number of iterations
      • iterations2

        private final int iterations2
        Iterations of the steepest descent method in L1 steering kernel regression in skr2L1_regular in STEERING_KERNEL_SECOND_ORDER_L1_NORM
      • windowSize

        private int windowSize
        The size of the local orientation analysis window
      • lambda

        private final float lambda
        The regularization for the elongation parameter
      • alpha

        private final float alpha
        The structure sensitive parameter
      • classicStepSize

        private final float classicStepSize
      • steeringStepSize

        private final float steeringStepSize
      • do25D

        private boolean do25D
        Currently only do5D = true is implemented.
      • nDims

        private int nDims
      • output

        private float[] output
      • horizontalGradient

        private float[] horizontalGradient
      • verticalGradient

        private float[] verticalGradient
      • extents

        private int[] extents
      • xDim

        private int xDim
      • yDim

        private int yDim
      • zDim

        private int zDim
      • C

        private float[][][][][] C
      • I

        private boolean[] I
        True if data is present at a point, false if data is missing at a point
      • input

        private float[] input
      • zInit

        private float[] zInit
      • scaleMax

        private double scaleMax
    • Constructor Detail

      • AlgorithmKernelRegression

        public AlgorithmKernelRegression​(ModelImage destImage,
                                         ModelImage srcImg,
                                         int method,
                                         boolean hasNaN,
                                         boolean hasInfinity,
                                         boolean hasGreaterEqual,
                                         double greaterEqualValue,
                                         boolean hasEqual,
                                         double equalValue,
                                         boolean hasLesserEqual,
                                         double lesserEqualValue,
                                         float initialGlobalSmoothing,
                                         float iterativeGlobalSmoothing,
                                         float iterativeGlobalSmoothing2,
                                         int upscale,
                                         int initialKernelSize,
                                         int iterativeKernelSize,
                                         int iterations,
                                         int iterations2,
                                         int windowSize,
                                         float lambda,
                                         float alpha,
                                         float classicStepSize,
                                         float steeringStepSize,
                                         boolean do25D)
        Creates a new AlgorithmKernelRegression object.
        Parameters:
        destImage - denoised image
        srcImg - 2D or 3D source image
        method - 1 of 4 possible sets of routines to be executed
        hasNaN - true if irregularly sampled data uses NaN for missing values
        hasInfinity - true if irregularly sampled data uses infinity for missing values
        hasGreaterEqual - true if irregularly sampled data uses values >= greaterEqualValue for missing values
        greaterEqualValue -
        hasEqual - true if irregularly sampled data uses values == equalValue for missing values
        equalValue -
        hasLesserEqual - true if irregularly sampled data uses values <= lesserEqualValue for missing values
        lesserEqualValue -
        initialGlobalSmoothing -
        iterativeGlobalSmoothing -
        iterativeGlobalSmoothing2 - Global smoothing in L1 steering kernel regression
        upscale - Upscaling factor
        initialKernelSize -
        iterativeKernelSize -
        iterations - Total number of iterations
        iterations2 - Iterations in L1 steering kernel regression
        windowSize - Size of the local orientation analysis window
        lambda - Regularization for the elongation parameter
        alpha - Structure sensitive parameter
        classicStepSize -
        steeringStepSize -
        do25D - If true, do slice by slice filtering
    • Method Detail

      • finalize

        public void finalize()
        Prepares this class for destruction.
        Overrides:
        finalize in class AlgorithmBase
      • runAlgorithm

        public void runAlgorithm()
        Starts the nonlocal means filter algorithm.
        Specified by:
        runAlgorithm in class AlgorithmBase
      • ckr2Regular

        private void ckr2Regular​(int upscale)
      • ckr2Irregular

        private void ckr2Irregular()
      • ckr2IrregularCIELab

        private void ckr2IrregularCIELab()
      • ckr2L1Regular

        private void ckr2L1Regular()
        Second order classic kernel regression function with L1-norm for regularly sampled data
      • ckr2allRegular

        private void ckr2allRegular()
        Second order classic kernel regression function for regularly sampled data
      • ckr2RegularCIELab

        private void ckr2RegularCIELab​(int upscale)
      • steering

        private void steering()
        Compute steering matrices
      • skr2Regular

        private void skr2Regular​(int upscale)
      • skr2Irregular

        private void skr2Irregular()
      • skr2IrregularCIELab

        private void skr2IrregularCIELab()
      • skr2L1Regular

        private void skr2L1Regular()
      • skr2RegularCIELab

        private void skr2RegularCIELab​(int upscale)
      • convertRGBtoCIELab

        private void convertRGBtoCIELab()
      • convertCIELabtoRGB

        private void convertCIELabtoRGB​(float[] buffer)