Skip to content
Open
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
19 changes: 14 additions & 5 deletions Augmentor/Operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import os
import random
import warnings
import cv2

# Python 2-3 compatibility - not currently needed.
# try:
Expand Down Expand Up @@ -1810,8 +1811,9 @@ def do(image):


class HSVShifting(Operation):

"""
CURRENTLY NOT IMPLEMENTED.
Implementing HSV shifting augmentation to augmentor.
"""
def __init__(self, probability, hue_shift, saturation_scale, saturation_shift, value_scale, value_shift):
Operation.__init__(self, probability)
Expand All @@ -1824,19 +1826,26 @@ def __init__(self, probability, hue_shift, saturation_scale, saturation_shift, v
def perform_operation(self, images):

def do(image):
hsv = np.array(image.convert("HSV"), 'float64')
hsv /= 255.

image = image.convert("RGB")
image = np.array(image)

hsv = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
hsv = hsv/255

hsv[..., 0] += np.random.uniform(-self.hue_shift, self.hue_shift)
hsv[..., 1] *= np.random.uniform(1 / (1 + self.saturation_scale), 1 + self.saturation_scale)
hsv[..., 1] *= np.random.uniform(1 / (1 + self.saturation_scale), 1+ self.saturation_scale)
hsv[..., 1] += np.random.uniform(-self.saturation_shift, self.saturation_shift)
hsv[..., 2] *= np.random.uniform(1 / (1 + self.value_scale), 1 + self.value_scale)
hsv[..., 2] += np.random.uniform(-self.value_shift, self.value_shift)

hsv.clip(0, 1, hsv)
hsv = np.uint8(np.round(hsv * 255.))

return Image.fromarray(hsv, "HSV").convert("RGB")
hsv = cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR)
img = Image.fromarray(hsv)

return img

augmented_images = []

Expand Down
9 changes: 9 additions & 0 deletions Augmentor/Pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,15 @@ def greyscale(self, probability):
else:
self.add_operation(Greyscale(probability=probability))

def hsvshifting(self, probability, hue_shift, saturation_scale, saturation_shift, value_scale, value_shift):
"""
"""
if not 0 < probability <= 1:
raise ValueError(Pipeline._probability_error_text)
else:
self.add_operation(HSVShifting(probability = probability,hue_shift = hue_shift, saturation_scale = saturation_scale, saturation_shift = saturation_shift, value_scale = value_scale, value_shift = value_shift))


def black_and_white(self, probability, threshold=128):
"""
Convert images to black and white. In other words convert the image
Expand Down