Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend invert methods #469

Merged
merged 11 commits into from
Nov 13, 2019
15 changes: 15 additions & 0 deletions changelogs/master/20191027_improve_invert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Improve Invert #469

* Improved performance of `imgaug.augmenters.arithmetic.invert()` and
`imgaug.augmenters.arithmetic.Invert` for `uint8` images.
* Added function `imgaug.augmenters.arithmetic.invert_()`, an in-place version
of `imgaug.augmenters.arithmetic.invert()`.
* Added parameters `threshold` and `invert_above_threshold` to
`imgaug.augmenters.arithmetic.invert()`
* Added parameters `threshold` and `invert_above_threshold` to
`imgaug.augmenters.arithmetic.Invert`.
* Added function `imgaug.augmenters.arithmetic.solarize()`, a wrapper around
`solarize_()`.
* Added function `imgaug.augmenters.arithmetic.solarize_()`, a wrapper around
`invert_()`.
* Added augmenter `imgaug.augmenters.Solarize`, a wrapper around `Invert`.
39 changes: 39 additions & 0 deletions checks/check_solarize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import print_function, division, absolute_import
import imgaug as ia
import imgaug.augmenters as iaa
import timeit


def main():
for size in [64, 128, 256, 512, 1024]:
for threshold in [64, 128, 192]:
time_iaa = timeit.timeit(
"iaa.solarize(image, %d)" % (threshold,),
number=1000,
setup=(
"import imgaug as ia; "
"import imgaug.augmenters as iaa; "
"image = ia.quokka_square((%d, %d))" % (size, size))
)
time_pil = timeit.timeit(
"np.asarray("
"PIL.ImageOps.solarize(PIL.Image.fromarray(image), %d)"
")" % (threshold,),
number=1000,
setup=(
"import numpy as np; "
"import PIL.Image; "
"import PIL.ImageOps; "
"import imgaug as ia; "
"image = ia.quokka_square((%d, %d))" % (size, size))
)
print("[size=%04d, thresh=%03d] iaa=%.4f pil=%.4f" % (
size, threshold, time_iaa, time_pil))

image = ia.quokka_square((128, 128))
images_aug = iaa.Solarize(1.0)(images=[image] * (5*5))
ia.imshow(ia.draw_grid(images_aug))


if __name__ == "__main__":
main()