-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 #347 from aleju/color_quantization
Add color quantization
- Loading branch information
Showing
13 changed files
with
1,323 additions
and
98 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
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,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() |
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,25 @@ | ||
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)) | ||
ia.imshow( | ||
ia.draw_grid([ | ||
iaa.quantize_colors_uniform(image, 2), | ||
iaa.quantize_colors_uniform(image, 4), | ||
iaa.quantize_colors_uniform(image, 8), | ||
iaa.quantize_colors_uniform(image, 16), | ||
iaa.quantize_colors_uniform(image, 32), | ||
iaa.quantize_colors_uniform(image, 64) | ||
], cols=6) | ||
) | ||
|
||
aug = iaa.UniformColorQuantization((2, 16)) | ||
ia.imshow(ia.draw_grid(aug(images=[image] * 16))) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.