#image #elastic #mls #computer-vision #graphics #deformation

moving-least-squares-image

Image deformation using moving least squares

2 releases

0.1.1 Apr 25, 2022
0.1.0 Oct 8, 2021

#2046 in Algorithms

31 downloads per month

MPL-2.0 license

30KB
581 lines

Image Deformation Using Moving Least Squares

Rust implementation of the paper "Image Deformation Using Moving Least Squares", Schaefer 2006.

mls demo output

The optional rayon feature enables parallel iterators for the generation of the warped image.

Here is what using the library looks like:

// Open an image from disk.
let img = image::open("data/woody.jpg")?.into_rgb8();

// Define the source control points.
let controls_src: &[(f32, f32)] = &[
    (20.0, 160.0),
    ...
    (250.0, 369.0),
];

// Define the destination control points.
let controls_dst: &[(f32, f32)] = &[
    (20.0, 250.0),
    ...
    (250.0, 369.0),
];

// Create new warped image.
let warped_img_affine =
    mls_image::reverse_dense(&img, controls_src, controls_dst, mls::deform_affine);

lib.rs:

Functions to compute warped images with an MLS algorithm. Two warping functions are provided:

  • a dense warp where the deformation is computed for each pixel,
  • a sparse warp where its only computed on a sparse grid, and the other pixels locations are interpolated.

Dependencies

~10MB
~36K SLoC