Class LsePdeFilter2

  • Direct Known Subclasses:
    LseCurvatureFlow2, LseEvolve2, LseGaussianBlur2, LseGradientAnisotropic2

    public abstract class LsePdeFilter2
    extends LsePdeFilter

    The abstract base class for finite-difference-based solvers for partial differential equations in 2D. This system exists to support level-set evolution for image segmentation.

    The internal 2D data and mask images are copies of the inputs to the constructor but padded with a 1-pixel thick border to support filtering on the image boundary. These images are of size (xbound+2)-by-(ybound+2). The inputs (x,y) to access the data and mask avlues are constrained to 0

    Version:
    0.1 November 7, 2006
    Author:
    David Eberly
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean[][] m_aabMask
      Pixels may be masked out so that the PDE solver does not process them.
      protected float[][] m_aafDst
      Successive iterations of the PDE solver toggle between two buffers.
      protected float[][] m_aafSrc
      Successive iterations of the PDE solver toggle between two buffers.
      protected float m_fFourthInvDxDy
      invFourthDxDy = 1/(4*dx*dy)
      protected float m_fHalfInvDx
      halfInvDx = 1/(2*dx)
      protected float m_fHalfInvDy
      halfInvDy = 1/(2*dy)
      protected float m_fInvDx
      invDx = 1/dx
      protected float m_fInvDxDx
      invDxDx = 1/(dx*dx)
      protected float m_fInvDy
      invDy = 1/dy
      protected float m_fInvDyDy
      invDyDy = 1/(dy*dy)
      protected float m_fUmm
      Temporary storage for 3x3 neighborhood.
      protected float m_fUmp
      Temporary storage for 3x3 neighborhood.
      protected float m_fUmz
      Temporary storage for 3x3 neighborhood.
      protected float m_fUpm
      Temporary storage for 3x3 neighborhood.
      protected float m_fUpp
      Temporary storage for 3x3 neighborhood.
      protected float m_fUpz
      Temporary storage for 3x3 neighborhood.
      protected float m_fUzm
      Temporary storage for 3x3 neighborhood.
      protected float m_fUzp
      Temporary storage for 3x3 neighborhood.
      protected float m_fUzz
      Temporary storage for 3x3 neighborhood.
      protected float m_fXSpacing
      The x-spacing of the image, call it dx.
      protected float m_fYSpacing
      The y-spacing of the image, call it dy.
      protected int m_iXBound
      The x-bound of the image.
      protected int m_iYBound
      The y-bound of the image.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected LsePdeFilter2​(int iXBound, int iYBound, float fXSpacing, float fYSpacing, float[] afData, boolean[] abMask, float fBorderValue, int eScaleType)
      Create a new PDE filter object for 2D images.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void assignDirichletImageBorder()
      Assign values to the 1-pixel-thick image border.
      protected void assignDirichletMaskBorder()
      Assign values to the 1-pixel-thick borders that surround unmasked regions.
      protected void assignNeumannImageBorder()
      Assign values to the 1-pixel-thick image border.
      protected void assignNeumannMaskBorder()
      Assign values to the 1-pixel-thick borders that surround unmasked regions.
      boolean getMask​(int iX, int iY)
      Get the mask value at pixel (x,y).
      float getU​(int iX, int iY)
      Get the image value at pixel (x,y), call it u(x,y).
      float getUx​(int iX, int iY)
      Get the first-order x-derivative of the image value at pixel (x,y), call it u_x(x,y).
      float getUxx​(int iX, int iY)
      Get the second-order x-derivative of the image value at pixel (x,y), call it u_xx(x,y).
      float getUxy​(int iX, int iY)
      Get the second-order mixed-derivative of the image value at pixel (x,y), call it u_xy(x,y).
      float getUy​(int iX, int iY)
      Get the first-order y-derivative of the image value at pixel (x,y), call it u_y(x,y).
      float getUyy​(int iX, int iY)
      Get the second-order y-derivative of the image value at pixel (x,y), call it u_yy(x,y).
      int getXBound()
      Get the x-bound for the image.
      float getXSpacing()
      Get the x-spacing for the image.
      int getYBound()
      Get the y-bound for the image.
      float getYSpacing()
      Get the y-spacing for the image.
      protected void lookUp5​(int iX, int iY)
      Copy the source data to temporary storage in order to avoid redundant array accesses.
      protected void lookUp9​(int iX, int iY)
      Copy the source data to temporary storage in order to avoid redundant array accesses.
      protected void onPostUpdate()
      Swap the buffers for the next pass of the PDE solver.
      protected void onPreUpdate()
      Recompute the boundary values when Neumann conditions are in effect.
      protected void onUpdate()
      Iterate over all the pixels and call onUpdate(x,y) for each pixel that is not masked out.
      protected abstract void onUpdate​(int iX, int iY)
      An abstract function that allows per-pixel processing by the PDE solver.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • m_iXBound

        protected int m_iXBound
        The x-bound of the image.
      • m_iYBound

        protected int m_iYBound
        The y-bound of the image.
      • m_fXSpacing

        protected float m_fXSpacing
        The x-spacing of the image, call it dx.
      • m_fYSpacing

        protected float m_fYSpacing
        The y-spacing of the image, call it dy.
      • m_fInvDx

        protected float m_fInvDx
        invDx = 1/dx
      • m_fInvDy

        protected float m_fInvDy
        invDy = 1/dy
      • m_fHalfInvDx

        protected float m_fHalfInvDx
        halfInvDx = 1/(2*dx)
      • m_fHalfInvDy

        protected float m_fHalfInvDy
        halfInvDy = 1/(2*dy)
      • m_fInvDxDx

        protected float m_fInvDxDx
        invDxDx = 1/(dx*dx)
      • m_fFourthInvDxDy

        protected float m_fFourthInvDxDy
        invFourthDxDy = 1/(4*dx*dy)
      • m_fInvDyDy

        protected float m_fInvDyDy
        invDyDy = 1/(dy*dy)
      • m_fUmm

        protected float m_fUmm
        Temporary storage for 3x3 neighborhood. In the notation m_fUij, the i and j indices are in {m,z,p}, referring to subtract 1 (m), no change (z), or add 1 (p) to the appropriate index.
      • m_fUzm

        protected float m_fUzm
        Temporary storage for 3x3 neighborhood. In the notation m_fUij, the i and j indices are in {m,z,p}, referring to subtract 1 (m), no change (z), or add 1 (p) to the appropriate index.
      • m_fUpm

        protected float m_fUpm
        Temporary storage for 3x3 neighborhood. In the notation m_fUij, the i and j indices are in {m,z,p}, referring to subtract 1 (m), no change (z), or add 1 (p) to the appropriate index.
      • m_fUmz

        protected float m_fUmz
        Temporary storage for 3x3 neighborhood. In the notation m_fUij, the i and j indices are in {m,z,p}, referring to subtract 1 (m), no change (z), or add 1 (p) to the appropriate index.
      • m_fUzz

        protected float m_fUzz
        Temporary storage for 3x3 neighborhood. In the notation m_fUij, the i and j indices are in {m,z,p}, referring to subtract 1 (m), no change (z), or add 1 (p) to the appropriate index.
      • m_fUpz

        protected float m_fUpz
        Temporary storage for 3x3 neighborhood. In the notation m_fUij, the i and j indices are in {m,z,p}, referring to subtract 1 (m), no change (z), or add 1 (p) to the appropriate index.
      • m_fUmp

        protected float m_fUmp
        Temporary storage for 3x3 neighborhood. In the notation m_fUij, the i and j indices are in {m,z,p}, referring to subtract 1 (m), no change (z), or add 1 (p) to the appropriate index.
      • m_fUzp

        protected float m_fUzp
        Temporary storage for 3x3 neighborhood. In the notation m_fUij, the i and j indices are in {m,z,p}, referring to subtract 1 (m), no change (z), or add 1 (p) to the appropriate index.
      • m_fUpp

        protected float m_fUpp
        Temporary storage for 3x3 neighborhood. In the notation m_fUij, the i and j indices are in {m,z,p}, referring to subtract 1 (m), no change (z), or add 1 (p) to the appropriate index.
      • m_aafSrc

        protected float[][] m_aafSrc
        Successive iterations of the PDE solver toggle between two buffers. This is the source buffer, which is the input to the solver.
      • m_aafDst

        protected float[][] m_aafDst
        Successive iterations of the PDE solver toggle between two buffers. This is the destination buffer, which is the output of the solver.
      • m_aabMask

        protected boolean[][] m_aabMask
        Pixels may be masked out so that the PDE solver does not process them. This is useful for filtering only those pixels in a subimage.
    • Constructor Detail

      • LsePdeFilter2

        protected LsePdeFilter2​(int iXBound,
                                int iYBound,
                                float fXSpacing,
                                float fYSpacing,
                                float[] afData,
                                boolean[] abMask,
                                float fBorderValue,
                                int eScaleType)
        Create a new PDE filter object for 2D images.
        Parameters:
        iXBound - The x-bound of the image.
        iYBound - The y-bound of the image.
        fXSpacing - The x-spacing of the image.
        fYSpacing - The y-spacing of the image.
        afData - The image elements, stored in lexicographical order.
        abMask - The image mask, stored in lexicographical order. A pixel value is processed by the PDE solver only when the mask value is false.
        fBorderValue - Specifies how to handle the image value. When set to Float.MAX_VALUE, Neumann conditions are in use, in which case zero-valued derivatives are assumed on the image border. Otherwise, Dirichlet conditions are used, in which case the image is assumed to be constant on the border with value specified by fBorderValue.
        eScaleType - The type of scaling to apply to the input image. The choices are NONE, UNIT, SYMMETRIC, or PRESERVE_ZERO.
    • Method Detail

      • getXBound

        public final int getXBound()
        Get the x-bound for the image.
        Returns:
        The x-bound for the image.
      • getYBound

        public final int getYBound()
        Get the y-bound for the image.
        Returns:
        The y-bound for the image.
      • getXSpacing

        public final float getXSpacing()
        Get the x-spacing for the image.
        Returns:
        The x-spacing for the image.
      • getYSpacing

        public final float getYSpacing()
        Get the y-spacing for the image.
        Returns:
        The y-spacing for the image.
      • getU

        public final float getU​(int iX,
                                int iY)
        Get the image value at pixel (x,y), call it u(x,y).
        Parameters:
        iX - The x-coordinate of the pixel.
        iY - The y-coordinate of the pixel.
        Returns:
        The image value, u(x,y).
      • getUx

        public final float getUx​(int iX,
                                 int iY)
        Get the first-order x-derivative of the image value at pixel (x,y), call it u_x(x,y).
        Parameters:
        iX - The x-coordinate of the pixel.
        iY - The y-coordinate of the pixel.
        Returns:
        The x-derivative of the image value, u_x(x,y).
      • getUy

        public final float getUy​(int iX,
                                 int iY)
        Get the first-order y-derivative of the image value at pixel (x,y), call it u_y(x,y).
        Parameters:
        iX - The x-coordinate of the pixel.
        iY - The y-coordinate of the pixel.
        Returns:
        The y-derivative of the image value, u_y(x,y).
      • getUxx

        public final float getUxx​(int iX,
                                  int iY)
        Get the second-order x-derivative of the image value at pixel (x,y), call it u_xx(x,y).
        Parameters:
        iX - The x-coordinate of the pixel.
        iY - The y-coordinate of the pixel.
        Returns:
        The xx-derivative of the image value, u_xx(x,y).
      • getUxy

        public final float getUxy​(int iX,
                                  int iY)
        Get the second-order mixed-derivative of the image value at pixel (x,y), call it u_xy(x,y).
        Parameters:
        iX - The x-coordinate of the pixel.
        iY - The y-coordinate of the pixel.
        Returns:
        The xy-derivative of the image value, u_xy(x,y).
      • getUyy

        public final float getUyy​(int iX,
                                  int iY)
        Get the second-order y-derivative of the image value at pixel (x,y), call it u_yy(x,y).
        Parameters:
        iX - The x-coordinate of the pixel.
        iY - The y-coordinate of the pixel.
        Returns:
        The yy-derivative of the image value, u_xx(x,y).
      • getMask

        public final boolean getMask​(int iX,
                                     int iY)
        Get the mask value at pixel (x,y).
        Parameters:
        iX - The x-coordinate of the pixel.
        iY - The y-coordinate of the pixel.
        Returns:
        The mask value at pixel (x,y). Its value is true when that pixel should not be processed by the PDE solver.
      • assignDirichletImageBorder

        protected void assignDirichletImageBorder()
        Assign values to the 1-pixel-thick image border. The border value has been specified during object construction.
      • assignNeumannImageBorder

        protected void assignNeumannImageBorder()
        Assign values to the 1-pixel-thick image border. The border values are chosen so that the first-order image derivatives at the border pixels are zero. Thus, the border values are duplicates of the adjacent image values.
      • assignDirichletMaskBorder

        protected void assignDirichletMaskBorder()
        Assign values to the 1-pixel-thick borders that surround unmasked regions. The border value has been specified during object construction.
      • assignNeumannMaskBorder

        protected void assignNeumannMaskBorder()
        Assign values to the 1-pixel-thick borders that surround unmasked regions. The border values are chosen so that the first-order image derivatives at the border pixels are zero. Thus, the border values are duplicates of the adjacent image values.
      • onPreUpdate

        protected void onPreUpdate()
        Recompute the boundary values when Neumann conditions are in effect. If a derived class overrides this, it must call the base-class onPreUpdate first.
        Specified by:
        onPreUpdate in class LsePdeFilter
      • onUpdate

        protected void onUpdate()
        Iterate over all the pixels and call onUpdate(x,y) for each pixel that is not masked out.
        Specified by:
        onUpdate in class LsePdeFilter
      • onPostUpdate

        protected void onPostUpdate()
        Swap the buffers for the next pass of the PDE solver. If a derived class overrides this, it must call the base-class onPostUpdate last.
        Specified by:
        onPostUpdate in class LsePdeFilter
      • onUpdate

        protected abstract void onUpdate​(int iX,
                                         int iY)
        An abstract function that allows per-pixel processing by the PDE solver. The pixel (x,y) must be in padded coordinates, namely, 1
        Parameters:
        iX - The x-coordinate of the pixel.
        iY - The y-coordinate of the pixel.
        • lookUp5

          protected void lookUp5​(int iX,
                                 int iY)
          Copy the source data to temporary storage in order to avoid redundant array accesses. The copy involves the 5 pixels (x,y), (x+1,y), (x-1,y), (x,y+1), and (x,y-1).
        • lookUp9

          protected void lookUp9​(int iX,
                                 int iY)
          Copy the source data to temporary storage in order to avoid redundant array accesses. The copy involves the 9 pixels in the 3x3 neighborhood of (x,y).