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
6 changes: 3 additions & 3 deletions AutoTransformPy/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from skimage.transform import AffineTransform, warp
import numpy as np

from matplotlib import pyplot as plt
# from matplotlib import pyplot as plt

def translate (image_path, num_images, max_translation):
"""Returns an array of images of length num_images randomly translated a random number of pixels up to max_rotation
Expand Down Expand Up @@ -47,13 +47,13 @@ def translate (image_path, num_images, max_translation):

# Perform image translation
translations = (np.random.randint(-max_translation, max_translation, num_images), np.random.randint(-max_translation, max_translation, num_images))
translated_images = []
translated_images = [org_image]

for i in range(len(translations[0])):
tform = AffineTransform(translation=(translations[0][i], translations[1][i]))
translated_images.append(warp(org_image, tform, mode="constant", preserve_range=True).astype('uint8'))

return np.asarray(translated_images), org_image
return np.asarray(translated_images)


# data, org_image = translate("../tests/imgs/milad.jpg", 10, 50)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def test_inputs():

def test_return_imgs(): # Tests that the number of images returned from translate is correct
test_img = imread("../tests/imgs/milad.jpg")
returned_arr, org_image = trans.translate("../tests/imgs/milad.jpg", 5, 10)
returned_arr = trans.translate("../tests/imgs/milad.jpg", 5, 10)

assert org_image.shape == test_img.shape
assert returned_arr.shape[0] == 5
assert returned_arr[0].shape == test_img.shape
assert returned_arr.shape[0] == 6
assert returned_arr.shape[1:] == test_img.shape