Skip to content

Instantly share code, notes, and snippets.

@tomahim
Last active March 3, 2018 17:22
Show Gist options
  • Save tomahim/51b4c58f3ad3b76b323289371ba6e94f to your computer and use it in GitHub Desktop.
Save tomahim/51b4c58f3ad3b76b323289371ba6e94f to your computer and use it in GitHub Desktop.
Simple image transformation with scikit-image
import random
from scipy import ndarray
import skimage as sk
from skimage import transform
from skimage import util
def random_rotation(image_array: ndarray):
# pick a random degree of rotation between 25% on the left and 25% on the right
random_degree = random.uniform(-25, 25)
return sk.transform.rotate(image_array, random_degree)
def random_noise(image_array: ndarray):
# add random noise to the image
return sk.util.random_noise(image_array)
def horizontal_flip(image_array: ndarray):
# horizontal flip doesn't need skimage, it's easy as flipping the image array of pixels !
return image_array[:, ::-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment