Image Rotation with Scikit-Image Transform

  • Share this:

Code introduction


This function takes an image path and an angle of rotation as arguments, and then uses the transform module from the scikit-image library to rotate the image.


Technology Stack : scikit-image, NumPy

Code Type : Image processing

Code Difficulty : Intermediate


                
                    
def rotate_image(image_path, angle):
    from skimage import io, transform
    import numpy as np

    # Load the image
    image = io.imread(image_path)
    # Define the center of the image
    center = (image.shape[1] // 2, image.shape[0] // 2)
    # Perform the rotation
    rotated = transform.rotate(image, angle, resize=True, center=center)
    return rotated