Jan-Pieter
Jan-Pieter

Reputation: 137

Image transformation based on 3 points

I want to transform (translate, rotate and scale) an image based on 3 points identified on both overlapping images. Based on the pixel coordinates of the 3 points I want to create a large tiff which merges the two. For the next overlap i want to do the same etc. untill I get a large tiff which combines all the pictures. It's a bit like georeferencing but without the coordinates being used. The problem is I have no experience matplotlib. So far i have created a script which shows each couple of overlapping images side by side and when i close the window the next couple opens etc. I have also managed to get the pixel coordinates from clicked points on these images. But now I have to start the transformation based on the 3 points and I just don't know where to start. Any help on usable functions etc.?

EDIT: the images are low resolution thermal images so i don't think automatic transformations will work

Upvotes: 1

Views: 594

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207808

You could use wand which is a Python binding to ImageMagick. So, start with this image:

enter image description here

We can distort the red vertex (138,80) to the top-left corner, the green (43,22) to the bottom-left and the blue (49,125) to the bottom right like this (the image is 152x152):

#!/usr/bin/env python3

from wand.image import Image

# Open image and distort, giving start x,y and end x,y for 3 points
with Image(filename='start.png') as img:
    points = (138, 80, 0, 0,        # Red vertex
               43, 22, 0,152,       # Green vertex
               49,125, 152,152)     # Blue vertex
    img.distort('affine',points)

    # Save result
    img.save(filename='result.png')

enter image description here


You can do just the same thing in Terminal from the command-line too:

magick start.png -distort affine "138,80 0,0 43,22 0,152 49,125 152,152" result.png

Keywords: Image processing, Python, distort, distortion, affine transform, transformation, scale, rotate, ImageMagick.

Upvotes: 1

Related Questions