Spatial Examples

[1]:
from easycv import Image
from easycv.transforms import Resize, Rescale, Rotate, Crop, Translate, Mirror, Paste

For this example we will load an image with random(). For more examples of image loading check Image examples.

[2]:
img = Image.random()
img
[2]:
../../_images/examples_transforms_spatial_3_0.png

Resize

To resize an image we simply apply the Rezise Transform, for more information check the reference.

[3]:
img.apply(Resize(width=300, height=250))
[3]:
../../_images/examples_transforms_spatial_6_0.png

Rescale

To rescale an image we simply apply the Rescale Transform with the factors of x and y, for more information check the reference.

[4]:
img.apply(Rescale(fx=2, fy=1))
[4]:
../../_images/examples_transforms_spatial_9_0.png

Rotate

To rotate an image we simply apply the Rotate Transform with the degrees to rotate, for more information check the reference.

[5]:
img.apply(Rotate(degrees=50))
[5]:
../../_images/examples_transforms_spatial_12_0.png

Crop

To crop an image we simply apply the Crop Transform with the boundaries of each side, for more information check the reference.

[6]:
img.apply(Crop(rectangle=[[50,50],[100,100]]))
[6]:
../../_images/examples_transforms_spatial_15_0.png

Translate

To translate an image we simply apply the Translate Transform with the vector to translate, for more information check the reference.

[7]:
img.apply(Translate(x=10,y=50))
[7]:
../../_images/examples_transforms_spatial_18_0.png

Mirror

To flip an image we simply apply the Mirror Transform with the desired axis to flip, for more information check the reference.

[8]:
img.apply(Mirror(axis="y"))
[8]:
../../_images/examples_transforms_spatial_21_0.png

Paste

To paste an image on to another simply apply the Paste transform with the image to use and the rectangle to paste, for more information check the reference.

[9]:
img.apply(Paste(paste=Image.random(), rectangle=[[20,20],[200,200]]))
[9]:
../../_images/examples_transforms_spatial_24_0.png