Skip to main content

Fourier transform based image registration

Project description

Foureg

Image registration using discrete Fourier transform.

Given two images, foureg calculates a similarity transformation that transforms one image into the other.

Example

The example transforms an image with a user defined transformation and then rediscovers it using foureg.

import matplotlib.pyplot as plt
import numpy as np
import torch
from PIL import Image

from foureg import (Constraints, frame_img, similarity, similarity_matrix,
                    transform_img)

# Generate the test images
transformation = similarity_matrix(0.8, -10, (60, 20))
master = np.asarray(Image.open("./resources/examples/sample1.png"))
master = torch.from_numpy(master.copy()).type(torch.float32)

slave = transform_img(master, transformation, invert=True)

# Define some constraints and coregister
constraints = Constraints(angle=(-10, 5), scale=(0.8, 0.2), tx=(60, 3), ty=(20, 1))
imreg_result = similarity(
    master, slave, constraints=constraints, numiter=5, filter_pcorr=5
)

# Transform the slave image
slave_transformed = transform_img(slave, imreg_result.transformation, invert=False)

_, axs = plt.subplots(1, 4, figsize=(13, 8))
im_0 = axs[0].imshow(master)
plt.colorbar(im_0, ax=axs[0])
im_1 = axs[1].imshow(slave)
plt.colorbar(im_1, ax=axs[1])
im_2 = axs[2].imshow(slave_transformed)
plt.colorbar(im_2, ax=axs[2])
im_3 = axs[3].imshow(np.abs(slave_transformed - master))
plt.colorbar(im_3, ax=axs[3])

plt.show()

Features

  • Image pre-processing options (frequency filtration, image extension).
  • Under-the-hood options exposed (iterations, phase correlation filtration).
  • Permissive open-source license (3-clause BSD).
  • GPU accelerated

Origin story

This is a fork of the imreg_dft borned of the desire to achieve the following goals:

  • Ability to return the final transformation in matrix form as opposed to the angle, translation and scaling factor separately. The original code makes obtaining that matrix really hard because it does it performs using scipy in away that each transformation resizes the image.
  • Better performance powered by pytorch
  • A more focused codebase. The only goal here is to estimate similarity transformations between pairs of images.

Acknowledgements

The code was originally developed by Christoph Gohlke (University of California, Irvine, USA) and later on developed further by Matěj Týč (Brno University of Technology, CZ). This repo wouldn't exist without them.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

foureg-1.0.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

foureg-1.0.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file foureg-1.0.0.tar.gz.

File metadata

  • Download URL: foureg-1.0.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/22.6.0

File hashes

Hashes for foureg-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5fb3b2af173c7c946471d05208d0f4998d3300e4e45af0d536297b7b97f06bd4
MD5 69e3d8089dbd59d10cf51fe1a6151a5d
BLAKE2b-256 6247d88dd8911468a296e1b4c45b6247dbd2e41ce9e5d496819d25184e7126e0

See more details on using hashes here.

File details

Details for the file foureg-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: foureg-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/22.6.0

File hashes

Hashes for foureg-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5efd7bbf97fa65fe4daaf9a24973245f395b00584ac0a15cebb735362f819991
MD5 6fa10e5d5c5ceda5443143d09622a042
BLAKE2b-256 d94a4ad3e72f015d658b0264e0ac291c18d06487b362b9a974b85b76a8684261

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page