-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from marl/augment
Add augmentation for audio and images from L3 paper and add use of validation set
- Loading branch information
Showing
3 changed files
with
177 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import numpy as np | ||
import skimage | ||
import skimage.color | ||
|
||
def adjust_saturation(rgb_img, factor): | ||
""" | ||
Adjust the saturation of an RGB image | ||
Args: | ||
rgb_img: RGB image data array | ||
factor: Multiplicative scaling factor to be applied to saturation | ||
Returns: | ||
adjusted_img: RGB image with adjusted saturation | ||
""" | ||
hsv_img = skimage.color.rgb2hsv(rgb_img) | ||
hsv_img[:,:,1] = np.clip(hsv_img[:,:,1] * factor, 0.0, 1.0) | ||
return skimage.color.hsv2rgb(hsv_img) | ||
|
||
|
||
def adjust_brightness(rgb_img, delta): | ||
""" | ||
Adjust the brightness of an RGB image | ||
Args: | ||
rgb_img: RGB image data array | ||
delta: Additive (normalized) gain factor applied to each pixel | ||
Returns: | ||
adjusted_img: RGB image with adjusted saturation | ||
""" | ||
imin, imax = skimage.dtype_limits(rgb_img) | ||
# Convert delta into the range of the image data | ||
delta = rgb_img.dtype.type((imax - imin) * delta) | ||
|
||
return np.clip(rgb_img + delta, imin, imax) | ||
|
||
def horiz_flip(rgb_img): | ||
""" | ||
Horizontally flip the given image | ||
Args: | ||
rgb_img: RGB image data array | ||
Returns: | ||
flipped_img: Horizontally flipped image | ||
""" | ||
return rgb_img[:,::-1,:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters