Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AutoTransformPy/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from skimage.io import imread
from skimage.transform import rotate as rot
import numpy as np
import os

def rotate (image_path, num_images, max_rotation):
"""Returns an array of images of length num_images randomly rotated a random degree up to max_rotation
Expand Down Expand Up @@ -48,6 +49,9 @@ def rotate (image_path, num_images, max_rotation):
if max_rotation < 1 or max_rotation > 360:
raise ValueError("The maximum rotation must be between 1 and 360.")

if not os.path.isfile(image_path):
raise FileNotFoundError("No image found at path")

# Perform image rotation
rotations = np.random.randint(-max_rotation, max_rotation, num_images)
org_image = imread(image_path)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def test_inputs():
rot.rotate("../tests/imgs/milad.jpg", 7, 500) # Outside of the rotation range
rot.rotate("../tests/imgs/milad.jpg", -1, 500) # Nonsense number of images to return

with pytest.raises(FileNotFoundError):
rot.rotate("../tests/imgs/Path.jpg") # Incorrect directory/file not in location

def test_return_imgs(): # Tests that the number of images returned from rotate is correct
test_img = imread("../tests/imgs/milad.jpg")
returned_arr = rot.rotate("../tests/imgs/milad.jpg", 5, 180)
Expand Down