From e15129c8cac39ab67226a33b9236f4f8f1dfdf84 Mon Sep 17 00:00:00 2001 From: ansuman chand Date: Fri, 3 Aug 2018 12:20:22 +0530 Subject: [PATCH 1/3] modified doc string for HSV --- Augmentor/Operations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Augmentor/Operations.py b/Augmentor/Operations.py index d49b2c4..248b377 100644 --- a/Augmentor/Operations.py +++ b/Augmentor/Operations.py @@ -1811,7 +1811,7 @@ 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) From 1cdf4033e601e52a3af69c771f1c241085691a4c Mon Sep 17 00:00:00 2001 From: AnsumanChand Date: Fri, 3 Aug 2018 12:28:41 +0530 Subject: [PATCH 2/3] modified doc string for HSV (#1) --- Augmentor/Operations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Augmentor/Operations.py b/Augmentor/Operations.py index d49b2c4..248b377 100644 --- a/Augmentor/Operations.py +++ b/Augmentor/Operations.py @@ -1811,7 +1811,7 @@ 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) From d08668eca98cc520f8c82d0d6072e7c086a72ffd Mon Sep 17 00:00:00 2001 From: ansuman chand Date: Mon, 6 Aug 2018 12:20:46 +0530 Subject: [PATCH 3/3] HSV Shifting Functionality Added --- Augmentor/Operations.py | 18 ++++++++++++++---- Augmentor/Pipeline.py | 9 +++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Augmentor/Operations.py b/Augmentor/Operations.py index 248b377..a98efdf 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,10 @@ def do(image): class HSVShifting(Operation): + """ Implementing HSV shifting augmentation to augmentor. + Work in Progress. """ def __init__(self, probability, hue_shift, saturation_scale, saturation_shift, value_scale, value_shift): Operation.__init__(self, probability) @@ -1824,11 +1827,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 +1843,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