Skip to content

Commit

Permalink
Merge pull request #469 from aleju/improve_invert
Browse files Browse the repository at this point in the history
Extend invert methods
  • Loading branch information
aleju committed Nov 13, 2019
2 parents d9f553b + d91913b commit 326315e
Show file tree
Hide file tree
Showing 4 changed files with 883 additions and 58 deletions.
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()

0 comments on commit 326315e

Please sign in to comment.