Skip to content

Commit

Permalink
Add check script for KMeansColorQuantization
Browse files Browse the repository at this point in the history
  • Loading branch information
aleju committed Jul 7, 2019
1 parent 7d462bb commit 30c98e6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
* Added `augmenters.color.KMeansColorQuantization` and corresponding
`augmenters.color.quantize_colors_kmeans()`. Both deal with quantizing
similar colors using k-Means clustering. #347
* Added a check script for `KMeansColorQuantization` under
`checks/check_kmeans_color_quantization.py`.

## Fixes

Expand Down
31 changes: 31 additions & 0 deletions checks/check_kmeans_color_quantization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import print_function, division
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa


def main():
image = ia.quokka_square((256, 256))
image_q2 = iaa.quantize_colors_kmeans(image, 2)
image_q16 = iaa.quantize_colors_kmeans(image, 16)
ia.imshow(np.hstack([image_q2, image_q16]))

from_cs = "RGB"
to_cs = ["RGB", "Lab"]
kwargs = {"from_colorspace": from_cs, "to_colorspace": to_cs}
augs = [
iaa.KMeansColorQuantization(2, **kwargs),
iaa.KMeansColorQuantization(4, **kwargs),
iaa.KMeansColorQuantization(8, **kwargs),
iaa.KMeansColorQuantization((2, 16), **kwargs),
]

images_aug = []
for aug in augs:
images_aug.extend(aug(images=[image]*8))

ia.imshow(ia.draw_grid(images_aug, cols=8))


if __name__ == "__main__":
main()

0 comments on commit 30c98e6

Please sign in to comment.