diff --git a/Augmentor/Operations.py b/Augmentor/Operations.py index d49b2c4..e5f65ab 100644 --- a/Augmentor/Operations.py +++ b/Augmentor/Operations.py @@ -35,6 +35,7 @@ import os import random import warnings +import cv2 # Python 2-3 compatibility - not currently needed. # try: @@ -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) @@ -1824,11 +1826,15 @@ 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) @@ -1836,7 +1842,10 @@ def do(image): 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 = [] diff --git a/Augmentor/Pipeline.py b/Augmentor/Pipeline.py index c7a58f8..b77a85c 100644 --- a/Augmentor/Pipeline.py +++ b/Augmentor/Pipeline.py @@ -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