scikit-imageimage-augmentation

AffineTransform skimage without cutting off the edges


i am trying to transform image, that is rotated and a little skewed with Skimage.

image = io.imread("id_1.jpg")
afine_tf = tf.AffineTransform(shear=0.3, rotation=-0.5)
modified = tf.warp(image, inverse_map=afine_tf)
io.imshow(modified)
io.show()

but every time I do this, the edges are cut off, is there a possibility to transform the image without cutting edges?

Original: enter image description here

Cutted edges after script above: enter image description here

Kind regards


Solution

  • You need to provide the output_shape= argument to warp, and make sure it is big enough to contain your transformed image. To do this generically (for affine transforms) you need to transform all four corners of the image, and take the maximum value for each axis. You also need to make sure the whole image is in the positive coordinate space, as there is no way to display quadrants with negative coordinates.