• Stars
    star
    336
  • Rank 124,844 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created about 7 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Numpy & PyTorch implementation of three algorithms of image deformation using moving least squares. http://dl.acm.org/citation.cfm?doid=1179352.1141920

[# Moving Least Squares (MLS) (Numpy & PyTorch)

Introduction

Moving least squares is a method of reconstructing continuous functions from a set of unorganized point samples via the calculation of a weighted least squares measure biased towards the region around the point at which the reconstructed value is requested.

In computer graphics, the moving least squares method is useful for reconstructing a surface from a set of points. Often it is used to create a 3D surface from a point cloud through either downsampling or upsampling.

Methods

  • Affine deformation
  • Similarity deformation
  • Rigid deformation

Usage

1. Install Packages

pip install -r requirements.txt

The accelerated algorithms requires PyTorch. PyTorch Installation Guide

2. Try the demo

Please check the demo.py for usage. We provide four demos:

demo()          # Toy
demo2()         # Monalisa
demo3()         # Cells
demo_torch()    # Toy in PyTorch

NEW 2023-04-28: @spedr provides an interactive demo. (See interactive_demo.py)

You can run the demo with

python interactive_demo.py images/monalisa.jpg

Hotkeys:
q or ESC - Quit
d - Delete the selected control point
c - Clear all control points
a - Create an affine deformation and display it in a separate window
s - Create a similarity deformation and display it in a separate window
r - Create a rigid deformation and display it in a separate window
w - Write the last deformation to the images folder

Here's an usage example of performing a rigid deformation on Monalisa's smile.

monalisa_rigid_deformation.mp4

Results

  • Toy

Deformation

  • Monalisa (Rigid)

Rigid deformation

Rigid Deformation

The original label is overlapped on the deformed labels for better comparison.

Rigid Deformation

Code list

  • img_utils.py: Numpy implementation of the algorithms
  • img_utils_pytorch.py: PyTorch implementation of the algorithms
  • interp_torch.py: Interpolation 1D in PyTorch
  • demo.py: Demo programs

Metrics

Optimize memory usage

  • Here lists some examples of memory usage and running time of the numpy implementation
Image Size Control Points Affine Similarity Rigid
500 x 500 16 0.57s / 0.15GB 0.99s / 0.16GB 0.89s / 0.13GB
500 x 500 64 1.6s / 0.34GB 3.7s / 0.3GB 3.6s / 0.2GB
1000 x 1000 64 7.7s / 1.1GB 17s / 0.98GB 15s / 0.82GB
2000 x 2000 64 30s / 4.2GB 65s / 3.6GB 69s / 3.1GB
  • Estimate memory usage for large image: (h x w x N x 4 x 2) x 2~2.5
    • h, w: image size
    • N: number of control points
    • 4: float32
    • 2: coordinates (x, y)
    • 2~2.5: intermediate results

Accelerated by PyTorch

The algorithm is also implemented with PyTorch and has faster speed benefiting from the CUDA acceleration.

  • Rigid deformation
Image Size Control Points Numpy PyTorch with CUDA
100 x 100 16 0.025s 0.128s
500 x 500 16 0.753s 0.187s
500 x 500 32 1.934s 0.205s
500 x 500 64 3.384s 0.483s
1000 x 1000 64 13.089s 0.663s
2000 x 2000 64 61.874s 1.784s

(* Tested on pytorch=1.6.0 with cudatoolkit=10.1)

Update

  • 2023-04-28 Add an interactive demo. (Thanks to @spedr)

  • 2022-01-12 Implement three algorithms with PyTorch

  • 2021-12-24: Fix a bug of nan values in mls_rigid_deformation(). (see issue #13)

  • 2021-07-14: Optimize memory usage. Now a 2000x2000 image with 64 control points spend about 4.2GB memory. (20GB in the previous version)

  • 2020-09-25: No need for so-called inverse transformation. Just transform target pixels to the corresponding source pixels.

Reference

[1] Schaefer S, Mcphail T, Warren J. Image deformation using moving least squares[C]// ACM SIGGRAPH. ACM, 2006:533-540.

[2] interp implementation in interp_torch.py. Github: aliutkus/torchinterp1d ](https://github.com/spedr)

More Repositories

1

FPTrans

PyTorch implementation of paper "Feature-Proxy Transformer for Few-Shot Segmentation" (NeurIPS'22 Spotlight)
Python
46
star
2

conv_arithmetic

Convolution and Transposed Convolution in a Matrix Multiplication View
Python
14
star
3

navigator

ι›†ζˆδΊ†ε€šδΈͺζœη΄’εΌ•ζ“Žε’Œε¨±δΉ, 科研, ε·₯ε…·, η”Ÿζ΄»εΈΈη”¨η½‘ε€ηš„ε―Όθˆͺι‘΅
HTML
11
star
4

LDA

Tensorflow & PyTorch implementation of LDA loss. Paper: Deep Linear Discriminant Analysis http://arxiv.org/abs/1511.04707
Python
10
star
5

Group_Normalization

A simple group normalization with batch norm in tensorflow (of cource with moving average).
Python
9
star
6

jarvis73.github.io

My blog.
JavaScript
8
star
7

PEMP

The implementation of PEMP in paper "Prior-Enhanced Few-Shot Segmentation with Meta-Prototypes"
Python
7
star
8

DeepLearningForBeginners

Deep learning with tensorflow/PyTorch, mirrored stragety
Jupyter Notebook
6
star
9

Ant-Colony-Optimization

A python implementation of ant colony optimization for travelling salesman problem(TSP)
Python
6
star
10

MhdViewer

A basic medical image (mhd) viewer based on VTK and DCMTK library
C++
3
star
11

MachineLearning

My machine learning reporitory.
Python
2
star
12

BoxSegLiver

Medical image segmentation using deep learning methods
Python
2
star
13

BubbleNets-Python3

Change original Bubble Nets to Python3
Python
2
star
14

Helper

Helper functions for machine learning experiments
Python
2
star
15

DeepCNN-TF2

Tensorflow 2.0 examples of baseline models and useful skills ......
Python
2
star
16

FPTransPaddle

PaddlePaddle implementation of paper "Feature-Proxy Transformer for Few-Shot Segmentation" (NeurIPS'22 Spotlight)
Python
2
star
17

Myfloat

This is a project of floating point number
C
1
star
18

DeepCNN

Famous CNN models. Build model with Keras and train with Tensorflow session.
Python
1
star
19

VNet-Tensorflow-V2

VNet implementation with Tensorflow v2.0 for prostate segmentation segmentation
Python
1
star
20

tf-faster-rcnn

Faster R-CNN with tensorflow for liver detection
Python
1
star
21

DINs

Source code for the JBHI paper "DINs: Deep Interactive Networks for Neurofibroma Segmentation in Neurofibromatosis Type 1 on Whole-Body MRI"
Python
1
star
22

PuCo

Python
1
star