Skip to content

Commit

Permalink
Merge pull request #462 from aleju/grayscale_some_colors
Browse files Browse the repository at this point in the history
Add augmenters for colorwise grayscaling
  • Loading branch information
aleju committed Nov 3, 2019
2 parents 6a8e09d + 016d8b5 commit 510c021
Show file tree
Hide file tree
Showing 6 changed files with 1,024 additions and 2 deletions.
8 changes: 8 additions & 0 deletions changelogs/master/added/20191019_colorwise_grayscaling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Colorwise Grayscaling #462

* Added `RemoveSaturation`, a shortcut for `MultiplySaturation((0.0, 1.0))`
with outputs similar to `Grayscale((0.0, 1.0))`.
* Added `GrayscaleColorwise`, which applies grayscaling to randomly
picked colors in the image.
* Added `RemoveSaturationColorwise`, which applies color saturation removal
to randomy picked colors in the image.
33 changes: 33 additions & 0 deletions checks/check_grayscale_colorwise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import imgaug as ia
import imgaug.augmenters as iaa
import imageio


def main():
urls = [
("https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/"
"Sarcophilus_harrisii_taranna.jpg/"
"320px-Sarcophilus_harrisii_taranna.jpg"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/"
"Vincent_van_Gogh_-_Wheatfield_with_crows_-_Google_Art_Project.jpg/"
"320px-Vincent_van_Gogh_-_Wheatfield_with_crows_-_Google_Art_Project"
".jpg"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/0/0c/"
"Galerella_sanguinea_Zoo_Praha_2011-2.jpg/207px-Galerella_sanguinea_"
"Zoo_Praha_2011-2.jpg"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/"
"Ambrosius_Bosschaert_the_Elder_%28Dutch_-_Flower_Still_Life_-_"
"Google_Art_Project.jpg/307px-Ambrosius_Bosschaert_the_Elder_%28"
"Dutch_-_Flower_Still_Life_-_Google_Art_Project.jpg")
]

image = imageio.imread(urls[1])

aug = iaa.GrayscaleColorwise(10, 0.1, alpha=[0.0, 1.0])
images_aug = aug(images=[image] * (5*5))

ia.imshow(ia.draw_grid(images_aug))


if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions checks/check_remove_saturation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import imgaug as ia
import imgaug.augmenters as iaa
import imageio


def main():
urls = [
("https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/"
"Sarcophilus_harrisii_taranna.jpg/"
"320px-Sarcophilus_harrisii_taranna.jpg"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/"
"Vincent_van_Gogh_-_Wheatfield_with_crows_-_Google_Art_Project.jpg/"
"320px-Vincent_van_Gogh_-_Wheatfield_with_crows_-_Google_Art_Project"
".jpg"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/0/0c/"
"Galerella_sanguinea_Zoo_Praha_2011-2.jpg/207px-Galerella_sanguinea_"
"Zoo_Praha_2011-2.jpg"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/"
"Ambrosius_Bosschaert_the_Elder_%28Dutch_-_Flower_Still_Life_-_"
"Google_Art_Project.jpg/307px-Ambrosius_Bosschaert_the_Elder_%28"
"Dutch_-_Flower_Still_Life_-_Google_Art_Project.jpg")
]

image = imageio.imread(urls[3])

aug = iaa.RemoveSaturation()
images_aug = aug(images=[image] * (5*5))

ia.imshow(ia.draw_grid(images_aug))


if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions checks/check_remove_saturation_colorwise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import imgaug as ia
import imgaug.augmenters as iaa
import imageio


def main():
urls = [
("https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/"
"Sarcophilus_harrisii_taranna.jpg/"
"320px-Sarcophilus_harrisii_taranna.jpg"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/"
"Vincent_van_Gogh_-_Wheatfield_with_crows_-_Google_Art_Project.jpg/"
"320px-Vincent_van_Gogh_-_Wheatfield_with_crows_-_Google_Art_Project"
".jpg"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/0/0c/"
"Galerella_sanguinea_Zoo_Praha_2011-2.jpg/207px-Galerella_sanguinea_"
"Zoo_Praha_2011-2.jpg"),
("https://upload.wikimedia.org/wikipedia/commons/thumb/9/96/"
"Ambrosius_Bosschaert_the_Elder_%28Dutch_-_Flower_Still_Life_-_"
"Google_Art_Project.jpg/307px-Ambrosius_Bosschaert_the_Elder_%28"
"Dutch_-_Flower_Still_Life_-_Google_Art_Project.jpg")
]

image = imageio.imread(urls[1])

aug = iaa.RemoveSaturationColorwise(10, 0.1, alpha=[0.0, 1.0])
images_aug = aug(images=[image] * (5*5))

ia.imshow(ia.draw_grid(images_aug))


if __name__ == "__main__":
main()

0 comments on commit 510c021

Please sign in to comment.