Class ImageDeformPointMLS_F32

  • All Implemented Interfaces:

    public class ImageDeformPointMLS_F32
    extends java.lang.Object
    implements Point2Transform2_F32

    Implementation of 'Moving Least Squares' (MLS) control point based image deformation models described in [1].

    Usage Procedure:
    1. Invoke configure(int, int, int, int)
    2. Invoke addControl(float, float) for each control point
    3. Invoke fixateUndistorted() when all control points have been added
    4. Invoke setDistorted(int, float, float) to change the distorted location of a control point
    5. Invoke fixateDistorted() after you are done changing distorted locations

    Each control point has an undistorted and distorted location. The fixate functions are used to precompute different portions of the deformation to maximize speed by avoiding duplicate computations. Instead of computing a distortion for each pixel a regular grid is used instead. Pixel points are interpolated between grid points using bilinear interpolation.

    This should be a faithful implementation of MLS. Potential deviations listed below:

    1. Pixels should be adjusted when converting to grid coordinates to maintain the same aspect ratio as the input image. This way the results is "independent" of the internal grids shape/size. [1] does not mention this issue.
    2. When compared against images published in [1] the rigid transform appears slightly different. However, when compared against other implementations those appear to produce nearly identical results to this implementation.

    [1] Schaefer, Scott, Travis McPhail, and Joe Warren. "Image deformation using moving least squares." ACM transactions on graphics (TOG). Vol. 25. No. 3. ACM, 2006.

    • Constructor Detail

      • ImageDeformPointMLS_F32

        public ImageDeformPointMLS_F32​(TypeDeformMLS type)
      • ImageDeformPointMLS_F32

        protected ImageDeformPointMLS_F32()
    • Method Detail

      • reset

        public void reset()
        Discards all existing control points
      • configure

        public void configure​(int width,
                              int height,
                              int gridRows,
                              int gridCols)
        Specifies the input image size and the size of the grid it will use to approximate the idea solution. All control points are discarded
        width - Image width
        height - Image height
        gridRows - grid rows
        gridCols - grid columns
      • addControl

        public int addControl​(float x,
                              float y)
        Adds a new control point at the specified location. Initially the distorted and undistorted location will be set to the same
        x - coordinate x-axis in image pixels
        y - coordinate y-axis in image pixels
        Index of control point
      • setUndistorted

        public void setUndistorted​(int which,
                                   float x,
                                   float y)
        Sets the location of a control point.
        x - coordinate x-axis in image pixels
        y - coordinate y-axis in image pixels
      • add

        public int add​(float srcX,
                       float srcY,
                       float dstX,
                       float dstY)
        Function that let's you set control and undistorted points at the same time
        srcX - distorted coordinate
        srcY - distorted coordinate
        dstX - undistorted coordinate
        dstY - undistorted coordinate
        Index of control point
      • setDistorted

        public void setDistorted​(int which,
                                 float x,
                                 float y)
        Sets the distorted location of a specific control point
        which - Which control point
        x - distorted coordinate x-axis in image pixels
        y - distorted coordinate y-axis in image pixels
      • fixateUndistorted

        public void fixateUndistorted()
        Precompute the portion of the equation which only concerns the undistorted location of each point on the grid even the current undistorted location of each control point.
      • fixateDistorted

        public void fixateDistorted()
        Recompute the deformation of each point in the internal grid now that the location of control points is not changing any more. Must call fixateUndistorted() first.
      • compute

        public void compute​(float x,
                            float y,
                            Point2D_F32 out)
        Description copied from interface: Point2Transform2_F32
        Applies transformation
        Specified by:
        compute in interface Point2Transform2_F32
        x - x-coordinate of point
        y - y-coordinate of point
        out - Transformed point location.
      • getAlpha

        public float getAlpha()
      • setAlpha

        public void setAlpha​(float alpha)