renom.utility.image.data_augmentation.color_jitter

renom.utility.image.data_augmentation.color_jitter. color_jitter ( x , h=None , s=None , v=None , random=False , labels=None , **kwargs )

Performs a HSV color jitter of a RGB images. if x is a Batch, apply jitter transform to Batch. if arguments include labels, apply label transformation.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional RGB images
  • h ( tuple ) – multiple value to h channel of HSV color space. when you apply random transformation, please use tuple (min h, max h)
  • s ( tuple ) – multiple value to s channel of HSV color space. when you apply random transformation, please use tuple (min s, max s)
  • v ( tuple ) – multiple value to v channel of HSV color space. when you apply random transformation, please use tuple (min v, max v)
  • random ( bool ) – If True, apply random jitter transform
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
Returns:

Images(4 dimension) of jitter transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.color_jitter import color_jitter
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> jitter_image = color_jitter(image, v=2)
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(jitter_image[0] / 255); axes[1].set_title("Jitter One Image")
>>> plt.show()
class renom.utility.image.data_augmentation.color_jitter. ColorJitter ( h=None , s=None , v=None )

Apply color jitter transformation to the input x and labels.

Parameters:
  • h ( tuple ) – multiple value to h channel of HSV color space. when you apply random transformation, please use tuple (min h, max h)
  • s ( tuple ) – multiple value to s channel of HSV color space. when you apply random transformation, please use tuple (min s, max s)
  • v ( tuple ) – multiple value to v channel of HSV color space. when you apply random transformation, please use tuple (min v, max v)
transform ( x , random=False , labels=None , **kwargs )

Performs a HSV color jitter of a RGB images. if x is a Batch, apply jitter transform to Batch if arguments include labels, apply label transformation

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional RGB images
  • random ( bool ) – apply random jitter or not
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
Returns:

Images(4 dimension) of jitter transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.color_jitter import ColorJitter
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> cj = ColorJitter(v=2)
>>> jitter_image = cj.transform(image)
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(jitter_image[0] / 255); axes[1].set_title("Jitter One Image")
>>> plt.show()

renom.utility.image.data_augmentation.crop

renom.utility.image.data_augmentation.crop. crop ( x , left_top=(0 , 0) , size=(0 , 0) , labels=None , num_class=0 , random=False )

Performs a Crop of a Numpy images. if x is a Batch, apply Crop transform to Batch. if arguments include labels, apply label transformation.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • left_top ( tuple ) – x and y of top left (y, x)
  • size ( tuple ) – width and height of crop image (Height, Width)
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets (for rectangle transformation)
  • random ( bool ) – If True, apply random cropping. left_top is randomly decided.
Returns:

Images(4 dimension) of crop transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.crop import crop
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> crop_image = crop(image, left_top=(10, 10), size=(100, 100))
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(crop_image[0] / 255); axes[1].set_title("Crop One Image")
>>> plt.show()
class renom.utility.image.data_augmentation.crop. Crop ( left_top=(0 , 0) , size=(0 , 0) )

Apply crop transformation to the input x and labels.

Parameters:
  • left_top ( tuple ) – x and y of top left (y, x)
  • size ( tuple ) – width and height of crop image (Height, Width)
transform ( x , random=False , labels=None , num_class=0 )

Performs a Crop of a Numpy images. if x is a Batch, apply Crop transform to Batch if arguments include labels, apply label transformation

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • random ( bool ) – If True, apply random cropping. left_top is randomly desided.
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets (for rectangle transformation)
Returns:

Images(4 dimension) of crop transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.crop import Crop
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> cr = Crop(left_top=(10, 10), size=(100, 100))
>>> crop_image = cr.transform(image)
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(crop_image[0] / 255); axes[1].set_title("Crop One Image")
>>> plt.show()

renom.utility.image.data_augmentation.flip

renom.utility.image.data_augmentation.flip. flip ( x , flip=0 , random=False , labels=None , num_class=0 )

Performs a flip of a Numpy images. if x is a Batch, apply flip transform to Batch. if arguments include labels, apply label transformation.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • flip ( int ) – 1 means Horizontal Flip. 2 means Vertical Flip. 3 means both. else no flip conversion.
  • random ( bool ) – apply random flip or not
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets (for rectangle transformation)
Returns:

Images(4 dimension) of flip transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.flip import flip
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> flip_image = flip(image, flip=1) # Horizontal Flip
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(flip_image[0] / 255); axes[1].set_title("Flip One Image")
>>> plt.show()
class renom.utility.image.data_augmentation.flip. Flip ( flip )

Apply flip transformation to the input x and labels.

Parameters: flip ( int ) – 1 means Horizontal Flip. 2 means Vertical Flip. 3 means both. else no flip conversion.
transform ( x , random=False , labels=None , num_class=0 )

Performs a flip of a Numpy images. if x is a Batch, apply flip transform to Batch if arguments include labels, apply label transformation

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • random ( bool ) – apply random flip or not
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets (for rectangle transformation)
Returns:

Images(4 dimension) of flip transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example:
>>> from renom.utility.image.data_augmentation.flip import Flip
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> fl = Flip(flip=1) # Horizontal Flip
>>> flip_image = fl.transform(image)
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(flip_image[0] / 255); axes[1].set_title("Flip One Image")
>>> plt.show()

renom.utility.image.data_augmentation.rescale

renom.utility.image.data_augmentation.rescale. rescale ( x , option='' , labels=None , **kwargs )

Performs a rescale transform of a Numpy images. if x is a Batch, apply rescale transform to Batch.

Parameters:
  • x ( ndarray ) – 4(batch) dimensional images
  • option ( str ) – option of rescale. “zero”: rescale images to [-0.5, 0.5]. “vgg” : substract averate values of vgg datasets. other : rescale [0.0, 1.0].
  • labels ( ndarray ) – rectangle labels(2-dimensional array). ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
Returns:

Images(4 dimension) of rescale transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example:
>>> from rescale import rescale
>>> from PIL import Image as im
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> rescale_image = rescale(image, option="zero")
>>> print(rescale_image.min(), rescale_image.max())
(-0.5, 0.5)
class renom.utility.image.data_augmentation.rescale. Rescale ( option='' )

Apply rescale transformation to the input x

Parameters: option ( str ) – option of rescale. “zero”: rescale images to [-0.5, 0.5]. “vgg” : substract averate values of vgg datasets. other : rescale [0.0, 1.0].
transform ( x , labels=None , **kwargs )

Performs a rescale transform of a Numpy images. if x is a Batch, apply rescale transform to Batch

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
Returns:

Images(4 dimension) of rescale transformed. If including labels, return with transformed labels

Return type:

(ndarray)

>>> from renom.utility.image.data_augmentation.rescale import Rescale
>>> from PIL import Image as im
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> rs = Rescale(option="zero")
>>> rescale_image = rs.transform(image)
>>> print(rescale_image.min(), rescale_image.max())
(-0.5, 0.5)

renom.utility.image.data_augmentation.resize

renom.utility.image.data_augmentation.resize. resize ( x , size=(0 , 0) , labels=None , num_class=0 , **kwargs )

Performs a resize transformation of a Numpy Image ‘x’. if x is a Batch, apply Resize transform to Batch. if arguments include labels, apply label transformation.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional x(images)
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets
Returns:

Images(4 dimension) of resize transformed. If including labels, return with transformed labels

Return type:

ndarray

Example:
>>> from renom.utility.image.data_augmentation.resize import resize
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> resize_image = resize(image, size=(300, 500))
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(resize_image[0] / 255); axes[1].set_title("Resize One Image")
>>> plt.show()
class renom.utility.image.data_augmentation.resize. Resize ( size=(0 , 0) )

Apply resize transformation to the input x and labels.

Parameters: size ( tuple ) – size of (‘Height’, “Width”)
transform ( x , labels=None , num_class=0 , **kwargs )

Performs a resize transformation of a Numpy Image x. if x is a Batch, apply Resize transform to Batch. if arguments include labels, apply label transformation.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional x
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets
Returns:

Images(4 dimension) of resize transformed. If including labels, return with transformed labels

Return type:

ndarray

Example:
>>> from renom.utility.image.data_augmentation.resize import Resize
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> rs = Resize(size=(300, 500))
>>> resize_image = rs.transform(image)
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(resize_image[0] / 255); axes[1].set_title("Resize One Image")
>>> plt.show()

renom.utility.image.data_augmentation.rotate

renom.utility.image.data_augmentation.rotate. rotate ( x , degree , fill_mode='constant' , fill_val=0 , random=False , labels=None )

Performs a rotation of a Numpy images. if x is a Batch, apply rotation transform to Batch.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • degree ( int ) – rotation degree [-180 : 180]
  • fill_mode ( str ) – method of interpolation after rotate transform you can use [‘constant’, ‘nearest’]
  • fill_val ( float ) – the interpolation value if fill_mode is ‘constant’
  • random ( bool ) – random rotation. degree is [-degree, +degree]
  • labels ( ndarray ) – you can use only when degree=90
Returns:

Images(4 dimension) of rotate transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.rotate import rotate
>>> from PIL import Image as im
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> rotate_image = rotate(image, degree=10)
class renom.utility.image.data_augmentation.rotate. Rotate ( degree , fill_mode='constant' , fill_val=0 )

Apply rotate transformation to the input x

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • degree ( int ) – rotation degree [-180 : 180]
  • fill_mode ( str ) – method of interpolation after rotate transform you can use [‘constant’, ‘nearest’]
  • fill_val ( float ) – the interpolation value if fill_mode is ‘constant’

Example

>>> from rotate import rotate
>>> from PIL import Image as im
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> rt = Rotate(degree=10)
>>> rotate_image = rt.transform(image)
transform ( x , random=False , labels=None , num_class=0 , **kwargs )

Performs a rotation of a Numpy images. if x is a Batch, apply rotation transform to Batch

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • random ( bool ) – random rotation. degree is [-degree, +degree]
  • labels ( ndarray ) – you can use only when degree=90
Retuens:
(ndarray): Images(4 dimension) of rotate transformed.
If including labels, return with transformed labels

renom.utility.image.data_augmentation.shift

renom.utility.image.data_augmentation.shift. shift ( x , shift , fill_mode='constant' , fill_val=0 , random=False , labels=None , num_class=0 )

Performs shift transformation to Numpy images. if x is a Batch, apply shifts transform to Batch. if arguments include labels, apply label transformation.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • shift ( tuple ) – values of x and y shifts (y, x)
  • fill_mode ( str ) – method of interpolation after rotate transform
  • fill_val ( float ) – the interpolation value if fill_mode is ‘constant’
  • random ( bool ) – random shift or not
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets
Returns:

Images(4 dimension) of shift transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.shift import shift
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> shift_image = shift(image, shift=(50, 50))
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(shift_image[0] / 255); axes[1].set_title("Shift One Image")
>>> plt.show()
class renom.utility.image.data_augmentation.shift. Shift ( shift , fill_mode='constant' , fill_val=0 )

Apply shift transformation to the input x and labels

Parameters:
  • shift ( tuple ) – values of x and y shifts (y, x)
  • fill_mode ( str ) – method of interpolation after rotate transform
  • fill_val ( float ) – the interpolation value if fill_mode is ‘constant’
transform ( x , random=0 , labels=None , num_class=0 )

Performs shift transformation to Numpy images. if x is a Batch, apply shifts transform to Batch. if arguments include labels, apply label transformation.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional images
  • random ( bool ) – random shift or not
  • labels ( ndarray ) – rectangle labels(2-dimensional array) ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets
Returns:

Images(4 dimension) of shift transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.shift import Shift
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> sh = Shift(shift=(50, 50))
>>> shift_image = sh.transform(image)
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(shift_image[0] / 255); axes[1].set_title("Shift One Image")
>>> plt.show()

renom.utility.image.data_augmentation.zoom

renom.utility.image.data_augmentation.zoom. zoom ( x , zoom_rate=(1 , 1) , random=False , labels=None , num_class=0 )

Apply zoom in transformation to the input x. if x is a Batch, apply Zoom transform to Batch. needs zoom_rate (has to be > 1.0). If you use Random transformation, Zoom will be done randomly for values between the two limits given by the tuple or from 1 to zoom_rate.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional Images
  • zoom_rate ( tuple ) – zoom ratio. If use random transformation, zoom_rate can be an interval (lower bound > 1.0). If you want to specify the range, you could use tuple (min, max)
  • random ( bool ) – If True, apply random transformation.
  • labels ( ndarray ) – rectangle labels(2-dimensional array). ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets (for rectangle transformation)
Returns:

Images(4 dimension) of zoom transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.zoom import zoom
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> zoom_image = zoom(image, zooom_rate=2, random=True)
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(zoom_image[0] / 255); axes[1].set_title("Zoom One Image")
>>> plt.show()
class renom.utility.image.data_augmentation.zoom. Zoom ( zoom_rate=(1 , 1) )

Apply zoom in transformation to the input x.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional Images
  • zoom_rate ( tuple ) – zoom ratio. If use random transformation, zoom_rate can be an interval (lower bound > 1.0). If you want to specify the range, you could use tuple (min, max)
transform ( x , random=False , labels=None , num_class=0 )

Performs a Zoom transformation of a Numpy Images. if x is a Batch, apply Zoom transform to Batch. needs zoom_rate (has to be > 1.0). If you use Random transformation, Zoom will be done randomly for values between the two limits given by the tuple or from 1 to zoom_rate.

Parameters:
  • x ( ndarray ) – 3 or 4(batch) dimensional Image
  • random ( bool ) – If True, apply random transformation.
  • labels ( ndarray ) – rectangle labels(2-dimensional array). ex:) np.array([[center x, center y, x_top_left, height, 0, 0, 0, 1, 0]])
  • num_class ( int ) – number of class of datasets (for rectangle transformation)
Returns:

Images(4 dimension) of zoom transformed. If including labels, return with transformed labels

Return type:

(ndarray)

Example

>>> from renom.utility.image.data_augmentation.zoom import Zoom
>>> from PIL import Image as im
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> image = im.open(image path) # ex:) "./image_folder/camera.jpg"
>>> image = np.array(image).astype(np.float32)
>>> zo = Zoom(zoom_rate=2)
>>> zoom_image = zo.transform(image, random=True)
>>> fig, axes = plt.subplots(2, 1)
>>> axes[0].imshow(image/255); axes[0].set_title("Original Image")
>>> axes[1].imshow(zoom_image[0] / 255); axes[1].set_title("Zoom One Image")
>>> plt.show()