imgaug icon indicating copy to clipboard operation
imgaug copied to clipboard

Question: How to return the transformation matrix from the imgaug.augmenters.geometric?

Open TommasoBendinelli opened this issue 4 years ago • 3 comments

Hello, I successfully created used iaa.PerspectiveTransform(scale=(0.01, 0.30)) on a batch of images. Now I would like to get the transformation matrix (i.e. the Prespective Transformation matrix) that lead from the original image to the augmented image. How do I get it?

TommasoBendinelli avatar Mar 25 '20 15:03 TommasoBendinelli

There is no trivial way to do this, but you can re-generate the matrices. Something like the following should usually work (didn't test it though):

import imgaug.augmenters as iaa
import imgaug as ia
import numpy as np

# input images
images = [
    np.zeros((64, 64, 3), dtype=np.uint8),
    np.ones((128, 100, 3), dtype=np.uint8)
]

# augmenter
aug = iaa.PerspectiveTransform(scale=0.5, seed=1234)

# create matrices
samples = aug._draw_samples(
    shapes=[image.shape for image in images],
    random_state=aug.random_state.copy()
)
matrices = samples.matrices

# augment images
images_aug = aug(images=images)

Sorry for the late reply.

aleju avatar Apr 12 '20 17:04 aleju

Hi, it seems the above code snippet does not quite work. Has the functions/parameters name been updated?

lthiet avatar Jun 14 '21 16:06 lthiet

How to get matrix from affine transformation? @aleju

leaf918 avatar Sep 13 '21 03:09 leaf918