Class AlgorithmPbBoundaryDetection

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

    public class AlgorithmPbBoundaryDetection
    extends AlgorithmBase
    Compute probability of boundary using brightness gradient and texture gradient Original MATLAB code written by David R. Martin in April 2003 Reference: "Learning to Detect Natural Image Boundaries Using Local Brightness, Color, and Texture Cues" by David R. Martin, Charles C. Fowlkes, and Jitendra Malik, IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 26, No. 5, May, 2004, pp. 530-549.
    Author:
    ilb
    • Field Detail

      • gradientType

        private int gradientType
      • presentation

        private int presentation
      • lowRadius

        private double lowRadius
      • highRadius

        private double highRadius
      • numOrientations

        private int numOrientations
      • smooth

        private java.lang.String smooth
      • sigma

        private double sigma
      • nthresh

        private int nthresh
      • hmult

        private double hmult
      • xDim

        private int xDim
      • yDim

        private int yDim
      • raFile

        private java.io.RandomAccessFile raFile
      • byteShortBuffer

        private final byte[] byteShortBuffer
        byte array for short *
      • byteIntBuffer

        private final byte[] byteIntBuffer
        byte array for int *
      • byteLongBuffer

        private final byte[] byteLongBuffer
        byte array for long *
      • epsilon

        private final double epsilon
    • Constructor Detail

      • AlgorithmPbBoundaryDetection

        public AlgorithmPbBoundaryDetection()
        AlgorithmPbBoundaryDetection - default constructor.
      • AlgorithmPbBoundaryDetection

        public AlgorithmPbBoundaryDetection​(ModelImage destImg,
                                            ModelImage srcImg,
                                            int gradientType,
                                            int presentation,
                                            double lowRadius,
                                            double highRadius,
                                            int numOrientations,
                                            java.lang.String smooth,
                                            double sigma,
                                            int nthresh,
                                            double hmult)
        AlgorithmPbBoundaryDetection.
        Parameters:
        destImg - DOCUMENT ME!
        srcImg - DOCUMENT ME!
        gradientType -
        presentation -
        lowRadius -
        highRadius -
        numOrientations -
        smooth -
        sigma -
    • Method Detail

      • runAlgorithm

        public void runAlgorithm()
        Description copied from class: AlgorithmBase
        Actually runs the algorithm. Implemented by inheriting algorithms.
        Specified by:
        runAlgorithm in class AlgorithmBase
      • pbCanny

        private void pbCanny​(double[][] pb)
      • pb2MM2

        private void pb2MM2​(double[][] pb,
                            double[][] theta)
      • pb2MM

        private void pb2MM​(double[][] pb,
                           double[][] theta)
      • pbCG

        private void pbCG​(double[][] pb,
                          double[][] theta)
      • pbCGTG

        private void pbCGTG​(double[][] pb,
                            double[][] theta)
      • pbGM2

        private void pbGM2​(double[][] pb,
                           double[][] theta)
      • pbGM

        private void pbGM​(double[][] pb,
                          double[][] theta)
      • pbBG

        private void pbBG​(double[][] pb,
                          double[][] theta)
      • pbBGTG

        private void pbBGTG​(double[][] pb,
                            double[][] theta)
      • pbTG

        private void pbTG​(double[][] pb,
                          double[][] theta)
      • nonmax

        private void nonmax​(double[][] imout,
                            double[][] im,
                            double[][] theta)
      • nonmax

        private void nonmax​(double[][] imout,
                            double[][] im,
                            double theta)
      • det2MM

        private void det2MM​(double[][] e0,
                            double[][] e1,
                            double[][] theta,
                            double sigmaI,
                            double sigmaO)
        Parameters:
        e0 - output smaller eigenvlaues
        e1 - output larger eigenvalues
        theta - output Orientation of first eigenvector + PI/2 (i.e. orientation of possible edge)
        sigmaI - input Inner scale (sigma for image derivatives)
        sigmaO - input Outer scale (sigma for spatial averaging)
      • detCG

        private void detCG​(double[][][][] cg,
                           double[] theta)
      • detCGTG

        private void detCGTG​(double[][][][] cg,
                             double[][][] tg,
                             double[] theta)
      • detGM

        private void detGM​(double[][] m,
                           double[][] theta,
                           double sigma)
      • detBG

        private void detBG​(double[][][] bg,
                           double[] theta)
      • detBGTG

        private void detBGTG​(double[][][] bg,
                             double[][][] tg,
                             double[] theta)
      • detTG

        private void detTG​(double[][][] tg,
                           double[] theta)
      • assignTextons

        private void assignTextons​(int[][] map,
                                   double[][][][] fim,
                                   double[][] textons)
      • distsqr

        private void distsqr​(double[][] z,
                             double[][] x,
                             double[][] y)
      • readFile

        private void readFile​(double[][][][] fb,
                              double[][] tex,
                              double[][] tsim)
      • getString

        public final java.lang.String getString​(int length)
                                         throws java.io.IOException
        Reads a string from a file of given length.
        Parameters:
        length - Number of bytes that form the string.
        Returns:
        The string read from the file.
        Throws:
        java.io.IOException - if there is an error reading the file
      • getLong

        public final long getLong​(boolean bigEndian)
                           throws java.io.IOException
        Reads eight unsigned bytes from file.
        Parameters:
        bigEndian - true indicates big endian byte order, false indicates little endian.
        Returns:
        The value of the long read from the file.
        Throws:
        java.io.IOException - if there is an error reading the file
      • getInt

        public final int getInt​(boolean bigEndian)
                         throws java.io.IOException
        Reads four signed bytes from file.
        Parameters:
        bigEndian - true indicates big endian byte order, false indicates little endian.
        Returns:
        The value of the integer read from the file.
        Throws:
        java.io.IOException - if there is an error reading the file
      • getUnsignedShort

        public final int getUnsignedShort​(boolean bigEndian)
                                   throws java.io.IOException
        Reads two unsigned bytes from file.
        Parameters:
        bigEndian - true indicates big endian byte order, false indicates little endian.
        Returns:
        The value of unsigned short read from the file returned as an int.
        Throws:
        java.io.IOException - if there is an error reading the file
      • readCString

        private java.lang.String readCString()
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • cgmo

        private void cgmo​(double[][][][] cg,
                          double[] theta,
                          ModelImage image,
                          double[] radius,
                          int numOrientations,
                          java.lang.String smooth,
                          double[] sigmaSmooth)
      • cgmo

        private void cgmo​(double[][][][] cg,
                          double[] theta,
                          ModelImage image,
                          double[] radius,
                          int numOrientations,
                          int nbins,
                          double sigmaSim,
                          double gamma,
                          java.lang.String smooth,
                          double[] sigmaSmooth)
        cgmo for color Compute the color gradient at a single scale and multiple orientations
        Parameters:
        cg - output output [yDim][xDim][3][numOrientations] array for color
        output - [numOrientations] theta
        image - RGB image, values in [0, 1].
        radius - Radius of disc for cg array
        numOrientations - Number of orientations for cg array
        nbins - Number of bins; should be > 1/sigmaSim.
        sigmaSim - For color similarity function
        gamma - Gamma correction for LAB [2.5].
        smooth - Smoothing method, one of {"gaussian", "savgol", "none"}, default none
        sigmaSmooth - Sigma for smoothing, default to radius
      • RGB2Lab

        private void RGB2Lab​(double[][][] L,
                             double[] red,
                             double[] green,
                             double[] blue)
      • cgmo

        private void cgmo​(double[][][] cg,
                          double[] theta,
                          ModelImage image,
                          double radius,
                          int numOrientations,
                          java.lang.String smooth,
                          double sigmaSmooth)
      • cgmo

        private void cgmo​(double[][][] cg,
                          double[] theta,
                          ModelImage image,
                          double radius,
                          int numOrientations,
                          int nbins,
                          double sigmaSim,
                          java.lang.String smooth,
                          double sigmaSmooth)
        cgmo for black and white Compute the color gradient at a single scale and multiple orientations
        Parameters:
        cg - output [yDim][xDim][numOrientations] array for black and white
        output - [numOrientations] theta
        image - Grayscale image, values in [0, 1].
        radius - Radius of disc for cg array
        numOrientations - Number of orientations for cg array
        nbins - Number of bins; should be > 1/sigmaSim.
        sigmaSim - For color similarity function
        smooth - Smoothing method, one of {"gaussian", "savgol", "none"}, default none
        sigmaSmooth - Sigma for smoothing, default to radius
      • tgmo

        private void tgmo​(double[][][] tg,
                          double[] theta,
                          int[][] tmap,
                          int ntex,
                          double radius,
                          int numOrientations,
                          double[][] tsim,
                          java.lang.String smooth,
                          double sigma)
        Compute the texture gradient at a single scale and multiple orientations
        Parameters:
        output - tg [yDim][xDim][numOrientations] array
        output - [numOrientations] theta Disc orientations (which are orthogonal to the texture gradient).
        tmap - [yDim][xDim] Texton map, values in [1, ntex]
        ntex - Number of textons
        radius - Radius of disc for texture gradient
        numOrientations - Number of orientations at which to compute the texture graident
        tsim - Texton similarity matrix. If not provided, then use chi-squared.
        smooth - Smoothing method. One of "gaussian", "savgol", "none". Default "none".
        sigma - Sigma for smoothing. Default to radius.
      • tgso

        private void tgso​(double[][] tg,
                          int[][] tmap,
                          int ntex,
                          double radius,
                          double theta,
                          java.lang.String smooth,
                          double sigma,
                          double[][] tsim)
        Compute the texture graident at a single orientation and scale
        Parameters:
        output - tg [yDim][xDim] array
        tmap - [yDim][xDim] Texton map, values in [1, ntex].
        ntex - Number of textons
        radius - Radius of disc for tg
        theta - Orientation orthogonal to tg.
        smooth - Smoothing method, one of {"gaussian", "savgol", "none"}, default = "none".
        sigma - Sigma for smoothing. Default to radius.
        tsim - [ntex][ntex] Texton similarity matrix. If not provided, then use chi-squared.
      • fitparab

        private void fitparab​(double[][] a,
                              double[][] b,
                              double[][] c,
                              double[][] z,
                              double ra,
                              double rb,
                              double theta)
      • savgol

        private void savgol​(double[][] c,
                            double[][] z,
                            int d,
                            int k,
                            double ra,
                            double rb,
                            double theta)
      • fbRun

        private void fbRun​(double[][][][] fim,
                           double[][][][] fb,
                           double[][] im)
      • fbRun

        private void fbRun​(double[][] fim,
                           double[][] fb,
                           double[][] im)
      • fftconv2

        private void fftconv2​(double[][] fim,
                              double[][] im,
                              double[][] f)
      • padReflect

        private void padReflect​(double[][] impad,
                                double[][] im,
                                int r)
      • oeFilter

        private void oeFilter​(double[][] f,
                              double sigmaX,
                              double sigmaY,
                              int support)
      • oeFilter

        private void oeFilter​(double[][] f,
                              double sigmaX,
                              double sigmaY,
                              int support,
                              double theta)
      • oeFilter

        private void oeFilter​(double[][] f,
                              double sigmaX,
                              double sigmaY,
                              int support,
                              double theta,
                              int deriv)
      • oeFilter

        private void oeFilter​(double[][] f,
                              double sigmaX,
                              double sigmaY,
                              int support,
                              double theta,
                              int deriv,
                              boolean dohil,
                              boolean dovis)
        Compute unit L1- norm 2D filter. The filter is a Gaussian in the x direction The filter is a Gaussian derivative with optional Hilbert transform in the y direction. The filter is zero-meaned if deriv > 0.
        Parameters:
        f - output [sz][sz] square filter
        sigmaX -
        sigmaY -
        support - Make filter +/- this many sigma
        theta - Orientation of x axis, in radians
        deriv - Degree of y derivative, one of {0, 1, 2}.
        dohil - Do Hilbert transform in y direction?
        dovis - Visualization for debugging?
      • conv2

        private void conv2​(double[][] A,
                           double[][] B,
                           double[][] Cout)