imgcorruptlike.py 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178
  1. """
  2. Augmenters that wrap methods from ``imagecorruptions`` package.
  3. See `https://github.com/bethgelab/imagecorruptions`_ for the package.
  4. The package is derived from `https://github.com/hendrycks/robustness`_.
  5. The corresponding `paper <https://arxiv.org/abs/1807.01697>`_ is::
  6. Hendrycks, Dan and Dietterich, Thomas G.
  7. Benchmarking Neural Network Robustness to Common Corruptions and
  8. Surface Variations
  9. with the `newer version <https://arxiv.org/abs/1903.12261>`_ being::
  10. Hendrycks, Dan and Dietterich, Thomas G.
  11. Benchmarking Neural Network Robustness to Common Corruptions and
  12. Perturbations
  13. List of augmenters:
  14. * :class:`GaussianNoise`
  15. * :class:`ShotNoise`
  16. * :class:`ImpulseNoise`
  17. * :class:`SpeckleNoise`
  18. * :class:`GaussianBlur`
  19. * :class:`GlassBlur`
  20. * :class:`DefocusBlur`
  21. * :class:`MotionBlur`
  22. * :class:`ZoomBlur`
  23. * :class:`Fog`
  24. * :class:`Frost`
  25. * :class:`Snow`
  26. * :class:`Spatter`
  27. * :class:`Contrast`
  28. * :class:`Brightness`
  29. * :class:`Saturate`
  30. * :class:`JpegCompression`
  31. * :class:`Pixelate`
  32. * :class:`ElasticTransform`
  33. .. note::
  34. The functions provided here have identical outputs to the ones in
  35. ``imagecorruptions`` when called using the ``corrupt()`` function of
  36. that package. E.g. the outputs are always ``uint8`` and not
  37. ``float32`` or ``float64``.
  38. Example usage::
  39. >>> # Skip the doctests in this file as the imagecorruptions package is
  40. >>> # not available in all python versions that are otherwise supported
  41. >>> # by imgaug.
  42. >>> # doctest: +SKIP
  43. >>> import imgaug as ia
  44. >>> import imgaug.augmenters as iaa
  45. >>> import numpy as np
  46. >>> image = np.zeros((64, 64, 3), dtype=np.uint8)
  47. >>> names, funcs = iaa.imgcorruptlike.get_corruption_names("validation")
  48. >>> for name, func in zip(names, funcs):
  49. >>> image_aug = func(image, severity=5, seed=1)
  50. >>> image_aug = ia.draw_text(image_aug, x=20, y=20, text=name)
  51. >>> ia.imshow(image_aug)
  52. Use e.g. ``iaa.imgcorruptlike.GaussianNoise(severity=2)(images=...)`` to
  53. create and apply a specific augmenter.
  54. Added in 0.4.0.
  55. """
  56. from __future__ import print_function, division, absolute_import
  57. import warnings
  58. import numpy as np
  59. import imgaug as ia
  60. from .. import dtypes as iadt
  61. from .. import random as iarandom
  62. from .. import parameters as iap
  63. from . import meta
  64. # TODO add optional dependency
  65. _MISSING_PACKAGE_ERROR_MSG = (
  66. "Could not import package `imagecorruptions`. This is an optional "
  67. "dependency of imgaug and must be installed manually in order "
  68. "to use augmenters from `imgaug.augmenters.imgcorrupt`. "
  69. "Use e.g. `pip install imagecorruptions` to install it. See also "
  70. "https://github.com/bethgelab/imagecorruptions for the repository "
  71. "of the package."
  72. )
  73. # Added in 0.4.0.
  74. def _clipped_zoom_no_scipy_warning(img, zoom_factor):
  75. from scipy.ndimage import zoom as scizoom
  76. with warnings.catch_warnings():
  77. warnings.filterwarnings("ignore", ".*output shape of zoom.*")
  78. # clipping along the width dimension:
  79. ch0 = int(np.ceil(img.shape[0] / float(zoom_factor)))
  80. top0 = (img.shape[0] - ch0) // 2
  81. # clipping along the height dimension:
  82. ch1 = int(np.ceil(img.shape[1] / float(zoom_factor)))
  83. top1 = (img.shape[1] - ch1) // 2
  84. img = scizoom(img[top0:top0 + ch0, top1:top1 + ch1],
  85. (zoom_factor, zoom_factor, 1), order=1)
  86. return img
  87. def _call_imgcorrupt_func(fname, seed, convert_to_pil, *args, **kwargs):
  88. """Apply an ``imagecorruptions`` function.
  89. The dtype support below is basically a placeholder to which the
  90. augmentation functions can point to decrease the amount of documentation.
  91. Added in 0.4.0.
  92. **Supported dtypes**:
  93. * ``uint8``: yes; indirectly tested (1)
  94. * ``uint16``: no
  95. * ``uint32``: no
  96. * ``uint64``: no
  97. * ``int8``: no
  98. * ``int16``: no
  99. * ``int32``: no
  100. * ``int64``: no
  101. * ``float16``: no
  102. * ``float32``: no
  103. * ``float64``: no
  104. * ``float128``: no
  105. * ``bool``: no
  106. - (1) Tested by comparison with function in ``imagecorruptions``
  107. package.
  108. """
  109. # import imagecorruptions, note that it is an optional dependency
  110. try:
  111. # imagecorruptions sets its own warnings filter rule via
  112. # warnings.simplefilter(). That rule is the in effect for the whole
  113. # program and not just the module. So to prevent that here
  114. # we use catch_warnings(), which uintuitively does not by default
  115. # catch warnings but saves and restores the warnings filter settings.
  116. with warnings.catch_warnings():
  117. import imagecorruptions.corruptions as corruptions
  118. except ImportError:
  119. raise ImportError(_MISSING_PACKAGE_ERROR_MSG)
  120. # Monkeypatch clip_zoom() as that causes warnings in some scipy versions,
  121. # and the implementation here suppresses these warnings. They suppress
  122. # all UserWarnings on a module level instead, which seems very exhaustive.
  123. corruptions.clipped_zoom = _clipped_zoom_no_scipy_warning
  124. image = args[0]
  125. iadt.gate_dtypes(
  126. image,
  127. allowed=["uint8"],
  128. disallowed=["bool",
  129. "uint16", "uint32", "uint64", "uint128", "uint256",
  130. "int8", "int16", "int32", "int64", "int128", "int256",
  131. "float16", "float32", "float64", "float96", "float128",
  132. "float256"],
  133. augmenter=None)
  134. input_shape = image.shape
  135. height, width = input_shape[0:2]
  136. assert height >= 32 and width >= 32, (
  137. "Expected the provided image to have a width and height of at least "
  138. "32 pixels, as that is the lower limit that the wrapped "
  139. "imagecorruptions functions use. Got shape %s." % (image.shape,))
  140. ndim = image.ndim
  141. assert ndim == 2 or (ndim == 3 and (image.shape[2] in [1, 3])), (
  142. "Expected input image to have shape (height, width) or "
  143. "(height, width, 1) or (height, width, 3). Got shape %s." % (
  144. image.shape,))
  145. if ndim == 2:
  146. image = image[..., np.newaxis]
  147. if image.shape[-1] == 1:
  148. image = np.tile(image, (1, 1, 3))
  149. if convert_to_pil:
  150. import PIL.Image
  151. image = PIL.Image.fromarray(image)
  152. with iarandom.temporary_numpy_seed(seed):
  153. if ia.is_callable(fname):
  154. image_aug = fname(image, *args[1:], **kwargs)
  155. else:
  156. image_aug = getattr(corruptions, fname)(image, *args[1:], **kwargs)
  157. if convert_to_pil:
  158. image_aug = np.asarray(image_aug)
  159. if ndim == 2:
  160. image_aug = image_aug[:, :, 0]
  161. elif input_shape[-1] == 1:
  162. image_aug = image_aug[:, :, 0:1]
  163. # this cast is done at the end of imagecorruptions.__init__.corrupt()
  164. image_aug = np.uint8(image_aug)
  165. return image_aug
  166. def get_corruption_names(subset="common"):
  167. """Get a named subset of image corruption functions.
  168. .. note::
  169. This function returns the augmentation names (as strings) *and* the
  170. corresponding augmentation functions, while ``get_corruption_names()``
  171. in ``imagecorruptions`` only returns the augmentation names.
  172. Added in 0.4.0.
  173. Parameters
  174. ----------
  175. subset : {'common', 'validation', 'all'}, optional.
  176. Name of the subset of image corruption functions.
  177. Returns
  178. -------
  179. list of str
  180. Names of the corruption methods, e.g. "gaussian_noise".
  181. list of callable
  182. Function corresponding to the name. Is one of the
  183. ``apply_*()`` functions in this module. Apply e.g.
  184. via ``func(image, severity=2, seed=123)``.
  185. """
  186. # import imagecorruptions, note that it is an optional dependency
  187. try:
  188. # imagecorruptions sets its own warnings filter rule via
  189. # warnings.simplefilter(). That rule is the in effect for the whole
  190. # program and not just the module. So to prevent that here
  191. # we use catch_warnings(), which uintuitively does not by default
  192. # catch warnings but saves and restores the warnings filter settings.
  193. with warnings.catch_warnings():
  194. import imagecorruptions
  195. except ImportError:
  196. raise ImportError(_MISSING_PACKAGE_ERROR_MSG)
  197. cnames = imagecorruptions.get_corruption_names(subset)
  198. funcs = [globals()["apply_%s" % (cname,)] for cname in cnames]
  199. return cnames, funcs
  200. # ----------------------------------------------------------------------------
  201. # Corruption functions
  202. # ----------------------------------------------------------------------------
  203. # These functions could easily be created dynamically, especially templating
  204. # the docstrings would save many lines of code. It is intentionally not done
  205. # here for the same reasons as in case of the augmenters. See the comment
  206. # further below at the start of the augmenter section for details.
  207. def apply_gaussian_noise(x, severity=1, seed=None):
  208. """Apply ``gaussian_noise`` from ``imagecorruptions``.
  209. Added in 0.4.0.
  210. **Supported dtypes**:
  211. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  212. Parameters
  213. ----------
  214. x : ndarray
  215. Image array.
  216. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  217. dtype ``uint8`` and a minimum height/width of ``32``.
  218. severity : int, optional
  219. Strength of the corruption, with valid values being
  220. ``1 <= severity <= 5``.
  221. seed : None or int, optional
  222. Seed for the random number generation to use.
  223. Returns
  224. -------
  225. ndarray
  226. Corrupted image.
  227. """
  228. return _call_imgcorrupt_func("gaussian_noise", seed, False, x, severity)
  229. def apply_shot_noise(x, severity=1, seed=None):
  230. """Apply ``shot_noise`` from ``imagecorruptions``.
  231. Added in 0.4.0.
  232. **Supported dtypes**:
  233. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  234. Parameters
  235. ----------
  236. x : ndarray
  237. Image array.
  238. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  239. dtype ``uint8`` and a minimum height/width of ``32``.
  240. severity : int, optional
  241. Strength of the corruption, with valid values being
  242. ``1 <= severity <= 5``.
  243. seed : None or int, optional
  244. Seed for the random number generation to use.
  245. Returns
  246. -------
  247. ndarray
  248. Corrupted image.
  249. """
  250. return _call_imgcorrupt_func("shot_noise", seed, False, x, severity)
  251. def apply_impulse_noise(x, severity=1, seed=None):
  252. """Apply ``impulse_noise`` from ``imagecorruptions``.
  253. Added in 0.4.0.
  254. **Supported dtypes**:
  255. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  256. Parameters
  257. ----------
  258. x : ndarray
  259. Image array.
  260. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  261. dtype ``uint8`` and a minimum height/width of ``32``.
  262. severity : int, optional
  263. Strength of the corruption, with valid values being
  264. ``1 <= severity <= 5``.
  265. seed : None or int, optional
  266. Seed for the random number generation to use.
  267. Returns
  268. -------
  269. ndarray
  270. Corrupted image.
  271. """
  272. return _call_imgcorrupt_func("impulse_noise", seed, False, x, severity)
  273. def apply_speckle_noise(x, severity=1, seed=None):
  274. """Apply ``speckle_noise`` from ``imagecorruptions``.
  275. Added in 0.4.0.
  276. **Supported dtypes**:
  277. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  278. Parameters
  279. ----------
  280. x : ndarray
  281. Image array.
  282. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  283. dtype ``uint8`` and a minimum height/width of ``32``.
  284. severity : int, optional
  285. Strength of the corruption, with valid values being
  286. ``1 <= severity <= 5``.
  287. seed : None or int, optional
  288. Seed for the random number generation to use.
  289. Returns
  290. -------
  291. ndarray
  292. Corrupted image.
  293. """
  294. return _call_imgcorrupt_func("speckle_noise", seed, False, x, severity)
  295. def apply_gaussian_blur(x, severity=1, seed=None):
  296. """Apply ``gaussian_blur`` from ``imagecorruptions``.
  297. Added in 0.4.0.
  298. **Supported dtypes**:
  299. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  300. Parameters
  301. ----------
  302. x : ndarray
  303. Image array.
  304. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  305. dtype ``uint8`` and a minimum height/width of ``32``.
  306. severity : int, optional
  307. Strength of the corruption, with valid values being
  308. ``1 <= severity <= 5``.
  309. seed : None or int, optional
  310. Seed for the random number generation to use.
  311. Returns
  312. -------
  313. ndarray
  314. Corrupted image.
  315. """
  316. return _call_imgcorrupt_func("gaussian_blur", seed, False, x, severity)
  317. def apply_glass_blur(x, severity=1, seed=None):
  318. """Apply ``glass_blur`` from ``imagecorruptions``.
  319. Added in 0.4.0.
  320. **Supported dtypes**:
  321. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  322. Parameters
  323. ----------
  324. x : ndarray
  325. Image array.
  326. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  327. dtype ``uint8`` and a minimum height/width of ``32``.
  328. severity : int, optional
  329. Strength of the corruption, with valid values being
  330. ``1 <= severity <= 5``.
  331. seed : None or int, optional
  332. Seed for the random number generation to use.
  333. Returns
  334. -------
  335. ndarray
  336. Corrupted image.
  337. """
  338. return _call_imgcorrupt_func(_apply_glass_blur_imgaug, seed, False, x,
  339. severity)
  340. # Added in 0.4.0.
  341. def _apply_glass_blur_imgaug(x, severity=1):
  342. # false positive on x_shape[0]
  343. # invalid name for dx, dy
  344. # pylint: disable=unsubscriptable-object, invalid-name
  345. # original function implementation from
  346. # https://github.com/bethgelab/imagecorruptions/blob/master/imagecorruptions/corruptions.py
  347. # this is an improved (i.e. faster) version
  348. from skimage.filters import gaussian
  349. # sigma, max_delta, iterations
  350. c = [
  351. (0.7, 1, 2),
  352. (0.9, 2, 1),
  353. (1, 2, 3),
  354. (1.1, 3, 2),
  355. (1.5, 4, 2)
  356. ][severity - 1]
  357. sigma, max_delta, iterations = c
  358. x = np.uint8(
  359. gaussian(np.array(x) / 255., sigma=sigma, multichannel=True) * 255)
  360. x_shape = np.array(x).shape
  361. # locally shuffle pixels
  362. nb_height = x_shape[0] - 2 * max_delta
  363. nb_width = x_shape[1] - 2 * max_delta
  364. for _ in range(iterations):
  365. dxxdyy = np.random.randint(-max_delta, max_delta,
  366. size=(nb_height, nb_width, 2,))
  367. dxxdyy = dxxdyy.astype(np.int16)
  368. # Rotate here, because imagecorruptions starts the replacement at the
  369. # bottom right, so the first generated sample should be placed in that
  370. # corner and not the top left corner.
  371. # We could avoid this with some fancy (but unreadable) indexing.
  372. dxxdyy = np.rot90(dxxdyy, 2, axes=(1, 0))
  373. # Pad the array to make things easier for us.
  374. # We could avoid this with a bit better indexing.
  375. dxxdyy = np.pad(
  376. dxxdyy,
  377. ((max_delta+1, max_delta-1), (max_delta+1, max_delta-1), (0, 0)),
  378. mode="constant")
  379. for h in range(x_shape[0] - max_delta, max_delta, -1):
  380. for w in range(x_shape[1] - max_delta, max_delta, -1):
  381. dx, dy = dxxdyy[h, w, :]
  382. h_prime, w_prime = h + dy, w + dx
  383. # swap
  384. x[h, w], x[h_prime, w_prime] = x[h_prime, w_prime], x[h, w]
  385. return np.clip(
  386. gaussian(x / 255., sigma=sigma, multichannel=True),
  387. 0, 1
  388. ) * 255
  389. def apply_defocus_blur(x, severity=1, seed=None):
  390. """Apply ``defocus_blur`` from ``imagecorruptions``.
  391. Added in 0.4.0.
  392. **Supported dtypes**:
  393. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  394. Parameters
  395. ----------
  396. x : ndarray
  397. Image array.
  398. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  399. dtype ``uint8`` and a minimum height/width of ``32``.
  400. severity : int, optional
  401. Strength of the corruption, with valid values being
  402. ``1 <= severity <= 5``.
  403. seed : None or int, optional
  404. Seed for the random number generation to use.
  405. Returns
  406. -------
  407. ndarray
  408. Corrupted image.
  409. """
  410. return _call_imgcorrupt_func("defocus_blur", seed, False, x, severity)
  411. def apply_motion_blur(x, severity=1, seed=None):
  412. """Apply ``motion_blur`` from ``imagecorruptions``.
  413. Added in 0.4.0.
  414. **Supported dtypes**:
  415. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  416. Parameters
  417. ----------
  418. x : ndarray
  419. Image array.
  420. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  421. dtype ``uint8`` and a minimum height/width of ``32``.
  422. severity : int, optional
  423. Strength of the corruption, with valid values being
  424. ``1 <= severity <= 5``.
  425. seed : None or int, optional
  426. Seed for the random number generation to use.
  427. Returns
  428. -------
  429. ndarray
  430. Corrupted image.
  431. """
  432. return _call_imgcorrupt_func("motion_blur", seed, False, x, severity)
  433. def apply_zoom_blur(x, severity=1, seed=None):
  434. """Apply ``zoom_blur`` from ``imagecorruptions``.
  435. Added in 0.4.0.
  436. **Supported dtypes**:
  437. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  438. Parameters
  439. ----------
  440. x : ndarray
  441. Image array.
  442. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  443. dtype ``uint8`` and a minimum height/width of ``32``.
  444. severity : int, optional
  445. Strength of the corruption, with valid values being
  446. ``1 <= severity <= 5``.
  447. seed : None or int, optional
  448. Seed for the random number generation to use.
  449. Returns
  450. -------
  451. ndarray
  452. Corrupted image.
  453. """
  454. return _call_imgcorrupt_func("zoom_blur", seed, False, x, severity)
  455. def apply_fog(x, severity=1, seed=None):
  456. """Apply ``fog`` from ``imagecorruptions``.
  457. Added in 0.4.0.
  458. **Supported dtypes**:
  459. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  460. Parameters
  461. ----------
  462. x : ndarray
  463. Image array.
  464. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  465. dtype ``uint8`` and a minimum height/width of ``32``.
  466. severity : int, optional
  467. Strength of the corruption, with valid values being
  468. ``1 <= severity <= 5``.
  469. seed : None or int, optional
  470. Seed for the random number generation to use.
  471. Returns
  472. -------
  473. ndarray
  474. Corrupted image.
  475. """
  476. return _call_imgcorrupt_func("fog", seed, False, x, severity)
  477. def apply_frost(x, severity=1, seed=None):
  478. """Apply ``frost`` from ``imagecorruptions``.
  479. Added in 0.4.0.
  480. **Supported dtypes**:
  481. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  482. Parameters
  483. ----------
  484. x : ndarray
  485. Image array.
  486. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  487. dtype ``uint8`` and a minimum height/width of ``32``.
  488. severity : int, optional
  489. Strength of the corruption, with valid values being
  490. ``1 <= severity <= 5``.
  491. seed : None or int, optional
  492. Seed for the random number generation to use.
  493. Returns
  494. -------
  495. ndarray
  496. Corrupted image.
  497. """
  498. return _call_imgcorrupt_func("frost", seed, False, x, severity)
  499. def apply_snow(x, severity=1, seed=None):
  500. """Apply ``snow`` from ``imagecorruptions``.
  501. Added in 0.4.0.
  502. **Supported dtypes**:
  503. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  504. Parameters
  505. ----------
  506. x : ndarray
  507. Image array.
  508. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  509. dtype ``uint8`` and a minimum height/width of ``32``.
  510. severity : int, optional
  511. Strength of the corruption, with valid values being
  512. ``1 <= severity <= 5``.
  513. seed : None or int, optional
  514. Seed for the random number generation to use.
  515. Returns
  516. -------
  517. ndarray
  518. Corrupted image.
  519. """
  520. return _call_imgcorrupt_func("snow", seed, False, x, severity)
  521. def apply_spatter(x, severity=1, seed=None):
  522. """Apply ``spatter`` from ``imagecorruptions``.
  523. Added in 0.4.0.
  524. **Supported dtypes**:
  525. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  526. Parameters
  527. ----------
  528. x : ndarray
  529. Image array.
  530. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  531. dtype ``uint8`` and a minimum height/width of ``32``.
  532. severity : int, optional
  533. Strength of the corruption, with valid values being
  534. ``1 <= severity <= 5``.
  535. seed : None or int, optional
  536. Seed for the random number generation to use.
  537. Returns
  538. -------
  539. ndarray
  540. Corrupted image.
  541. """
  542. return _call_imgcorrupt_func("spatter", seed, True, x, severity)
  543. def apply_contrast(x, severity=1, seed=None):
  544. """Apply ``contrast`` from ``imagecorruptions``.
  545. Added in 0.4.0.
  546. **Supported dtypes**:
  547. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  548. Parameters
  549. ----------
  550. x : ndarray
  551. Image array.
  552. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  553. dtype ``uint8`` and a minimum height/width of ``32``.
  554. severity : int, optional
  555. Strength of the corruption, with valid values being
  556. ``1 <= severity <= 5``.
  557. seed : None or int, optional
  558. Seed for the random number generation to use.
  559. Returns
  560. -------
  561. ndarray
  562. Corrupted image.
  563. """
  564. return _call_imgcorrupt_func("contrast", seed, False, x, severity)
  565. def apply_brightness(x, severity=1, seed=None):
  566. """Apply ``brightness`` from ``imagecorruptions``.
  567. Added in 0.4.0.
  568. **Supported dtypes**:
  569. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  570. Parameters
  571. ----------
  572. x : ndarray
  573. Image array.
  574. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  575. dtype ``uint8`` and a minimum height/width of ``32``.
  576. severity : int, optional
  577. Strength of the corruption, with valid values being
  578. ``1 <= severity <= 5``.
  579. seed : None or int, optional
  580. Seed for the random number generation to use.
  581. Returns
  582. -------
  583. ndarray
  584. Corrupted image.
  585. """
  586. return _call_imgcorrupt_func("brightness", seed, False, x, severity)
  587. def apply_saturate(x, severity=1, seed=None):
  588. """Apply ``saturate`` from ``imagecorruptions``.
  589. Added in 0.4.0.
  590. **Supported dtypes**:
  591. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  592. Parameters
  593. ----------
  594. x : ndarray
  595. Image array.
  596. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  597. dtype ``uint8`` and a minimum height/width of ``32``.
  598. severity : int, optional
  599. Strength of the corruption, with valid values being
  600. ``1 <= severity <= 5``.
  601. seed : None or int, optional
  602. Seed for the random number generation to use.
  603. Returns
  604. -------
  605. ndarray
  606. Corrupted image.
  607. """
  608. return _call_imgcorrupt_func("saturate", seed, False, x, severity)
  609. def apply_jpeg_compression(x, severity=1, seed=None):
  610. """Apply ``jpeg_compression`` from ``imagecorruptions``.
  611. Added in 0.4.0.
  612. **Supported dtypes**:
  613. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  614. Parameters
  615. ----------
  616. x : ndarray
  617. Image array.
  618. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  619. dtype ``uint8`` and a minimum height/width of ``32``.
  620. severity : int, optional
  621. Strength of the corruption, with valid values being
  622. ``1 <= severity <= 5``.
  623. seed : None or int, optional
  624. Seed for the random number generation to use.
  625. Returns
  626. -------
  627. ndarray
  628. Corrupted image.
  629. """
  630. return _call_imgcorrupt_func("jpeg_compression", seed, True, x, severity)
  631. def apply_pixelate(x, severity=1, seed=None):
  632. """Apply ``pixelate`` from ``imagecorruptions``.
  633. Added in 0.4.0.
  634. **Supported dtypes**:
  635. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  636. Parameters
  637. ----------
  638. x : ndarray
  639. Image array.
  640. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  641. dtype ``uint8`` and a minimum height/width of ``32``.
  642. severity : int, optional
  643. Strength of the corruption, with valid values being
  644. ``1 <= severity <= 5``.
  645. seed : None or int, optional
  646. Seed for the random number generation to use.
  647. Returns
  648. -------
  649. ndarray
  650. Corrupted image.
  651. """
  652. return _call_imgcorrupt_func("pixelate", seed, True, x, severity)
  653. def apply_elastic_transform(image, severity=1, seed=None):
  654. """Apply ``elastic_transform`` from ``imagecorruptions``.
  655. Added in 0.4.0.
  656. **Supported dtypes**:
  657. See :func:`~imgaug.augmenters.imgcorruptlike._call_imgcorrupt_func`.
  658. Parameters
  659. ----------
  660. image : ndarray
  661. Image array.
  662. Expected to have shape ``(H,W)``, ``(H,W,1)`` or ``(H,W,3)`` with
  663. dtype ``uint8`` and a minimum height/width of ``32``.
  664. severity : int, optional
  665. Strength of the corruption, with valid values being
  666. ``1 <= severity <= 5``.
  667. seed : None or int, optional
  668. Seed for the random number generation to use.
  669. Returns
  670. -------
  671. ndarray
  672. Corrupted image.
  673. """
  674. return _call_imgcorrupt_func("elastic_transform", seed, False, image,
  675. severity)
  676. # ----------------------------------------------------------------------------
  677. # Augmenters
  678. # ----------------------------------------------------------------------------
  679. # The augmenter definitions below are almost identical and mainly differ in
  680. # the names and functions used. It would be fairly trivial to write a
  681. # function that would create these augmenters dynamically (and one is listed
  682. # below as a comment). The downside is that in these cases the documentation
  683. # would also be generated dynamically, which leads to numerous problems:
  684. # (1) users couldn't easily read the documentation while scrolling through
  685. # the code file, (2) IDEs might not be able to use it for code suggestions,
  686. # (3) tools like pylint can't detect and validate it, (4) the imgaug-doc
  687. # tools to parse dtype support don't work with dynamically generated
  688. # documentation (and neither with dynamically generated classes).
  689. # Even though it's by far more code, it seems like the better choice overall
  690. # to just write it out.
  691. # Example function to dynamically generate augmenters, kept for possible
  692. # future uses:
  693. # def _create_augmenter(class_name, func_name):
  694. # func = globals()["apply_%s" % (func_name,)]
  695. #
  696. # def __init__(self, severity=1, name=None, deterministic=False,
  697. # random_state=None):
  698. # super(self.__class__, self).__init__(
  699. # func, severity, name=name, deterministic=deterministic,
  700. # random_state=random_state)
  701. #
  702. # augmenter_class = type(class_name,
  703. # (_ImgcorruptAugmenterBase,),
  704. # {"__init__": __init__})
  705. #
  706. # augmenter_class.__doc__ = """
  707. # Wrapper around ``imagecorruptions.corruptions.%s``.
  708. #
  709. # **Supported dtypes**:
  710. #
  711. # See :func:`~imgaug.augmenters.imgcorruptlike.apply_%s`.
  712. #
  713. # Parameters
  714. # ----------
  715. # severity : int, optional
  716. # Strength of the corruption, with valid values being
  717. # ``1 <= severity <= 5``.
  718. #
  719. # name : None or str, optional
  720. # See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  721. #
  722. # deterministic : bool, optional
  723. # See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  724. #
  725. # random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  726. # See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  727. #
  728. # Examples
  729. # --------
  730. # >>> import imgaug.augmenters as iaa
  731. # >>> aug = iaa.%s(severity=2)
  732. #
  733. # Create an augmenter around ``imagecorruptions.corruptions.%s``. Apply it to
  734. # images using e.g. ``aug(images=[image1, image2, ...])``.
  735. #
  736. # """ % (func_name, func_name, class_name, func_name)
  737. #
  738. # return augmenter_class
  739. # Added in 0.4.0.
  740. class _ImgcorruptAugmenterBase(meta.Augmenter):
  741. def __init__(self, func, severity=1,
  742. seed=None, name=None,
  743. random_state="deprecated", deterministic="deprecated"):
  744. super(_ImgcorruptAugmenterBase, self).__init__(
  745. seed=seed, name=name,
  746. random_state=random_state, deterministic=deterministic)
  747. self.func = func
  748. self.severity = iap.handle_discrete_param(
  749. severity, "severity", value_range=(1, 5), tuple_to_uniform=True,
  750. list_to_choice=True, allow_floats=False)
  751. # Added in 0.4.0.
  752. def _augment_batch_(self, batch, random_state, parents, hooks):
  753. if batch.images is None:
  754. return batch
  755. severities, seeds = self._draw_samples(len(batch.images),
  756. random_state=random_state)
  757. for image, severity, seed in zip(batch.images, severities, seeds):
  758. image[...] = self.func(image, severity=severity, seed=seed)
  759. return batch
  760. # Added in 0.4.0.
  761. def _draw_samples(self, nb_rows, random_state):
  762. severities = self.severity.draw_samples((nb_rows,),
  763. random_state=random_state)
  764. seeds = random_state.generate_seeds_(nb_rows)
  765. return severities, seeds
  766. # Added in 0.4.0.
  767. def get_parameters(self):
  768. """See :func:`~imgaug.augmenters.meta.Augmenter.get_parameters`."""
  769. return [self.severity]
  770. class GaussianNoise(_ImgcorruptAugmenterBase):
  771. """
  772. Wrapper around ``imagecorruptions.corruptions.gaussian_noise``.
  773. .. note::
  774. This augmenter only affects images. Other data is not changed.
  775. Added in 0.4.0.
  776. **Supported dtypes**:
  777. See :func:`~imgaug.augmenters.imgcorruptlike.apply_gaussian_noise`.
  778. Parameters
  779. ----------
  780. severity : int, optional
  781. Strength of the corruption, with valid values being
  782. ``1 <= severity <= 5``.
  783. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  784. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  785. name : None or str, optional
  786. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  787. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  788. Old name for parameter `seed`.
  789. Its usage will not yet cause a deprecation warning,
  790. but it is still recommended to use `seed` now.
  791. Outdated since 0.4.0.
  792. deterministic : bool, optional
  793. Deprecated since 0.4.0.
  794. See method ``to_deterministic()`` for an alternative and for
  795. details about what the "deterministic mode" actually does.
  796. Examples
  797. --------
  798. >>> # doctest: +SKIP
  799. >>> import imgaug.augmenters as iaa
  800. >>> aug = iaa.imgcorruptlike.GaussianNoise(severity=2)
  801. Create an augmenter around
  802. ``imagecorruptions.corruptions.gaussian_noise``.
  803. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  804. """
  805. # Added in 0.4.0.
  806. def __init__(self, severity=(1, 5),
  807. seed=None, name=None,
  808. random_state="deprecated", deterministic="deprecated"):
  809. super(GaussianNoise, self).__init__(
  810. apply_gaussian_noise, severity,
  811. seed=seed, name=name,
  812. random_state=random_state, deterministic=deterministic)
  813. class ShotNoise(_ImgcorruptAugmenterBase):
  814. """
  815. Wrapper around ``imagecorruptions.shot_noise``.
  816. .. note::
  817. This augmenter only affects images. Other data is not changed.
  818. Added in 0.4.0.
  819. **Supported dtypes**:
  820. See :func:`~imgaug.augmenters.imgcorruptlike.apply_shot_noise`.
  821. Parameters
  822. ----------
  823. severity : int, optional
  824. Strength of the corruption, with valid values being
  825. ``1 <= severity <= 5``.
  826. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  827. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  828. name : None or str, optional
  829. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  830. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  831. Old name for parameter `seed`.
  832. Its usage will not yet cause a deprecation warning,
  833. but it is still recommended to use `seed` now.
  834. Outdated since 0.4.0.
  835. deterministic : bool, optional
  836. Deprecated since 0.4.0.
  837. See method ``to_deterministic()`` for an alternative and for
  838. details about what the "deterministic mode" actually does.
  839. Examples
  840. --------
  841. >>> # doctest: +SKIP
  842. >>> import imgaug.augmenters as iaa
  843. >>> aug = iaa.imgcorruptlike.ShotNoise(severity=2)
  844. Create an augmenter around
  845. ``imagecorruptions.corruptions.shot_noise``.
  846. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  847. """
  848. # Added in 0.4.0.
  849. def __init__(self, severity=(1, 5),
  850. seed=None, name=None,
  851. random_state="deprecated", deterministic="deprecated"):
  852. super(ShotNoise, self).__init__(
  853. apply_shot_noise, severity,
  854. seed=seed, name=name,
  855. random_state=random_state, deterministic=deterministic)
  856. class ImpulseNoise(_ImgcorruptAugmenterBase):
  857. """
  858. Wrapper around ``imagecorruptions.corruptions.impulse_noise``.
  859. .. note::
  860. This augmenter only affects images. Other data is not changed.
  861. Added in 0.4.0.
  862. **Supported dtypes**:
  863. See :func:`~imgaug.augmenters.imgcorruptlike.apply_impulse_noise`.
  864. Parameters
  865. ----------
  866. severity : int, optional
  867. Strength of the corruption, with valid values being
  868. ``1 <= severity <= 5``.
  869. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  870. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  871. name : None or str, optional
  872. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  873. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  874. Old name for parameter `seed`.
  875. Its usage will not yet cause a deprecation warning,
  876. but it is still recommended to use `seed` now.
  877. Outdated since 0.4.0.
  878. deterministic : bool, optional
  879. Deprecated since 0.4.0.
  880. See method ``to_deterministic()`` for an alternative and for
  881. details about what the "deterministic mode" actually does.
  882. Examples
  883. --------
  884. >>> # doctest: +SKIP
  885. >>> import imgaug.augmenters as iaa
  886. >>> aug = iaa.imgcorruptlike.ImpulseNoise(severity=2)
  887. Create an augmenter around
  888. ``imagecorruptions.corruptions.impulse_noise``.
  889. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  890. """
  891. # Added in 0.4.0.
  892. def __init__(self, severity=(1, 5),
  893. seed=None, name=None,
  894. random_state="deprecated", deterministic="deprecated"):
  895. super(ImpulseNoise, self).__init__(
  896. apply_impulse_noise, severity,
  897. seed=seed, name=name,
  898. random_state=random_state, deterministic=deterministic)
  899. class SpeckleNoise(_ImgcorruptAugmenterBase):
  900. """
  901. Wrapper around ``imagecorruptions.corruptions.speckle_noise``.
  902. .. note::
  903. This augmenter only affects images. Other data is not changed.
  904. Added in 0.4.0.
  905. **Supported dtypes**:
  906. See :func:`~imgaug.augmenters.imgcorruptlike.apply_speckle_noise`.
  907. Parameters
  908. ----------
  909. severity : int, optional
  910. Strength of the corruption, with valid values being
  911. ``1 <= severity <= 5``.
  912. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  913. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  914. name : None or str, optional
  915. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  916. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  917. Old name for parameter `seed`.
  918. Its usage will not yet cause a deprecation warning,
  919. but it is still recommended to use `seed` now.
  920. Outdated since 0.4.0.
  921. deterministic : bool, optional
  922. Deprecated since 0.4.0.
  923. See method ``to_deterministic()`` for an alternative and for
  924. details about what the "deterministic mode" actually does.
  925. Examples
  926. --------
  927. >>> # doctest: +SKIP
  928. >>> import imgaug.augmenters as iaa
  929. >>> aug = iaa.imgcorruptlike.SpeckleNoise(severity=2)
  930. Create an augmenter around
  931. ``imagecorruptions.corruptions.speckle_noise``.
  932. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  933. """
  934. # Added in 0.4.0.
  935. def __init__(self, severity=(1, 5),
  936. seed=None, name=None,
  937. random_state="deprecated", deterministic="deprecated"):
  938. super(SpeckleNoise, self).__init__(
  939. apply_speckle_noise, severity,
  940. seed=seed, name=name,
  941. random_state=random_state, deterministic=deterministic)
  942. class GaussianBlur(_ImgcorruptAugmenterBase):
  943. """
  944. Wrapper around ``imagecorruptions.corruptions.gaussian_blur``.
  945. .. note::
  946. This augmenter only affects images. Other data is not changed.
  947. Added in 0.4.0.
  948. **Supported dtypes**:
  949. See :func:`~imgaug.augmenters.imgcorruptlike.apply_gaussian_blur`.
  950. Parameters
  951. ----------
  952. severity : int, optional
  953. Strength of the corruption, with valid values being
  954. ``1 <= severity <= 5``.
  955. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  956. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  957. name : None or str, optional
  958. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  959. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  960. Old name for parameter `seed`.
  961. Its usage will not yet cause a deprecation warning,
  962. but it is still recommended to use `seed` now.
  963. Outdated since 0.4.0.
  964. deterministic : bool, optional
  965. Deprecated since 0.4.0.
  966. See method ``to_deterministic()`` for an alternative and for
  967. details about what the "deterministic mode" actually does.
  968. Examples
  969. --------
  970. >>> # doctest: +SKIP
  971. >>> import imgaug.augmenters as iaa
  972. >>> aug = iaa.imgcorruptlike.GaussianBlur(severity=2)
  973. Create an augmenter around
  974. ``imagecorruptions.corruptions.gaussian_blur``.
  975. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  976. """
  977. # Added in 0.4.0.
  978. def __init__(self, severity=(1, 5),
  979. seed=None, name=None,
  980. random_state="deprecated", deterministic="deprecated"):
  981. super(GaussianBlur, self).__init__(
  982. apply_gaussian_blur, severity,
  983. seed=seed, name=name,
  984. random_state=random_state, deterministic=deterministic)
  985. class GlassBlur(_ImgcorruptAugmenterBase):
  986. """
  987. Wrapper around ``imagecorruptions.corruptions.glass_blur``.
  988. .. note::
  989. This augmenter only affects images. Other data is not changed.
  990. Added in 0.4.0.
  991. **Supported dtypes**:
  992. See :func:`~imgaug.augmenters.imgcorruptlike.apply_glass_blur`.
  993. Parameters
  994. ----------
  995. severity : int, optional
  996. Strength of the corruption, with valid values being
  997. ``1 <= severity <= 5``.
  998. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  999. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1000. name : None or str, optional
  1001. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1002. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1003. Old name for parameter `seed`.
  1004. Its usage will not yet cause a deprecation warning,
  1005. but it is still recommended to use `seed` now.
  1006. Outdated since 0.4.0.
  1007. deterministic : bool, optional
  1008. Deprecated since 0.4.0.
  1009. See method ``to_deterministic()`` for an alternative and for
  1010. details about what the "deterministic mode" actually does.
  1011. Examples
  1012. --------
  1013. >>> # doctest: +SKIP
  1014. >>> import imgaug.augmenters as iaa
  1015. >>> aug = iaa.imgcorruptlike.GlassBlur(severity=2)
  1016. Create an augmenter around
  1017. ``imagecorruptions.corruptions.glass_blur``.
  1018. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1019. """
  1020. # Added in 0.4.0.
  1021. def __init__(self, severity=(1, 5),
  1022. seed=None, name=None,
  1023. random_state="deprecated", deterministic="deprecated"):
  1024. super(GlassBlur, self).__init__(
  1025. apply_glass_blur, severity,
  1026. seed=seed, name=name,
  1027. random_state=random_state, deterministic=deterministic)
  1028. class DefocusBlur(_ImgcorruptAugmenterBase):
  1029. """
  1030. Wrapper around ``imagecorruptions.corruptions.defocus_blur``.
  1031. .. note::
  1032. This augmenter only affects images. Other data is not changed.
  1033. Added in 0.4.0.
  1034. **Supported dtypes**:
  1035. See :func:`~imgaug.augmenters.imgcorruptlike.apply_defocus_blur`.
  1036. Parameters
  1037. ----------
  1038. severity : int, optional
  1039. Strength of the corruption, with valid values being
  1040. ``1 <= severity <= 5``.
  1041. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1042. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1043. name : None or str, optional
  1044. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1045. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1046. Old name for parameter `seed`.
  1047. Its usage will not yet cause a deprecation warning,
  1048. but it is still recommended to use `seed` now.
  1049. Outdated since 0.4.0.
  1050. deterministic : bool, optional
  1051. Deprecated since 0.4.0.
  1052. See method ``to_deterministic()`` for an alternative and for
  1053. details about what the "deterministic mode" actually does.
  1054. Examples
  1055. --------
  1056. >>> # doctest: +SKIP
  1057. >>> import imgaug.augmenters as iaa
  1058. >>> aug = iaa.imgcorruptlike.DefocusBlur(severity=2)
  1059. Create an augmenter around
  1060. ``imagecorruptions.corruptions.defocus_blur``.
  1061. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1062. """
  1063. # Added in 0.4.0.
  1064. def __init__(self, severity=(1, 5),
  1065. seed=None, name=None,
  1066. random_state="deprecated", deterministic="deprecated"):
  1067. super(DefocusBlur, self).__init__(
  1068. apply_defocus_blur, severity,
  1069. seed=seed, name=name,
  1070. random_state=random_state, deterministic=deterministic)
  1071. class MotionBlur(_ImgcorruptAugmenterBase):
  1072. """
  1073. Wrapper around ``imagecorruptions.corruptions.motion_blur``.
  1074. .. note::
  1075. This augmenter only affects images. Other data is not changed.
  1076. Added in 0.4.0.
  1077. **Supported dtypes**:
  1078. See :func:`~imgaug.augmenters.imgcorruptlike.apply_motion_blur`.
  1079. Parameters
  1080. ----------
  1081. severity : int, optional
  1082. Strength of the corruption, with valid values being
  1083. ``1 <= severity <= 5``.
  1084. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1085. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1086. name : None or str, optional
  1087. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1088. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1089. Old name for parameter `seed`.
  1090. Its usage will not yet cause a deprecation warning,
  1091. but it is still recommended to use `seed` now.
  1092. Outdated since 0.4.0.
  1093. deterministic : bool, optional
  1094. Deprecated since 0.4.0.
  1095. See method ``to_deterministic()`` for an alternative and for
  1096. details about what the "deterministic mode" actually does.
  1097. Examples
  1098. --------
  1099. >>> # doctest: +SKIP
  1100. >>> import imgaug.augmenters as iaa
  1101. >>> aug = iaa.imgcorruptlike.MotionBlur(severity=2)
  1102. Create an augmenter around
  1103. ``imagecorruptions.corruptions.motion_blur``.
  1104. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1105. """
  1106. # Added in 0.4.0.
  1107. def __init__(self, severity=(1, 5),
  1108. seed=None, name=None,
  1109. random_state="deprecated", deterministic="deprecated"):
  1110. super(MotionBlur, self).__init__(
  1111. apply_motion_blur, severity,
  1112. seed=seed, name=name,
  1113. random_state=random_state, deterministic=deterministic)
  1114. class ZoomBlur(_ImgcorruptAugmenterBase):
  1115. """
  1116. Wrapper around ``imagecorruptions.corruptions.zoom_blur``.
  1117. .. note::
  1118. This augmenter only affects images. Other data is not changed.
  1119. Added in 0.4.0.
  1120. **Supported dtypes**:
  1121. See :func:`~imgaug.augmenters.imgcorruptlike.apply_zoom_blur`.
  1122. Parameters
  1123. ----------
  1124. severity : int, optional
  1125. Strength of the corruption, with valid values being
  1126. ``1 <= severity <= 5``.
  1127. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1128. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1129. name : None or str, optional
  1130. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1131. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1132. Old name for parameter `seed`.
  1133. Its usage will not yet cause a deprecation warning,
  1134. but it is still recommended to use `seed` now.
  1135. Outdated since 0.4.0.
  1136. deterministic : bool, optional
  1137. Deprecated since 0.4.0.
  1138. See method ``to_deterministic()`` for an alternative and for
  1139. details about what the "deterministic mode" actually does.
  1140. Examples
  1141. --------
  1142. >>> # doctest: +SKIP
  1143. >>> import imgaug.augmenters as iaa
  1144. >>> aug = iaa.imgcorruptlike.ZoomBlur(severity=2)
  1145. Create an augmenter around
  1146. ``imagecorruptions.corruptions.zoom_blur``.
  1147. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1148. """
  1149. # Added in 0.4.0.
  1150. def __init__(self, severity=(1, 5),
  1151. seed=None, name=None,
  1152. random_state="deprecated", deterministic="deprecated"):
  1153. super(ZoomBlur, self).__init__(
  1154. apply_zoom_blur, severity,
  1155. seed=seed, name=name,
  1156. random_state=random_state, deterministic=deterministic)
  1157. class Fog(_ImgcorruptAugmenterBase):
  1158. """
  1159. Wrapper around ``imagecorruptions.corruptions.fog``.
  1160. .. note::
  1161. This augmenter only affects images. Other data is not changed.
  1162. Added in 0.4.0.
  1163. **Supported dtypes**:
  1164. See :func:`~imgaug.augmenters.imgcorruptlike.apply_fog`.
  1165. Parameters
  1166. ----------
  1167. severity : int, optional
  1168. Strength of the corruption, with valid values being
  1169. ``1 <= severity <= 5``.
  1170. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1171. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1172. name : None or str, optional
  1173. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1174. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1175. Old name for parameter `seed`.
  1176. Its usage will not yet cause a deprecation warning,
  1177. but it is still recommended to use `seed` now.
  1178. Outdated since 0.4.0.
  1179. deterministic : bool, optional
  1180. Deprecated since 0.4.0.
  1181. See method ``to_deterministic()`` for an alternative and for
  1182. details about what the "deterministic mode" actually does.
  1183. Examples
  1184. --------
  1185. >>> # doctest: +SKIP
  1186. >>> import imgaug.augmenters as iaa
  1187. >>> aug = iaa.imgcorruptlike.Fog(severity=2)
  1188. Create an augmenter around
  1189. ``imagecorruptions.corruptions.fog``.
  1190. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1191. """
  1192. # Added in 0.4.0.
  1193. def __init__(self, severity=(1, 5),
  1194. seed=None, name=None,
  1195. random_state="deprecated", deterministic="deprecated"):
  1196. super(Fog, self).__init__(
  1197. apply_fog, severity,
  1198. seed=seed, name=name,
  1199. random_state=random_state, deterministic=deterministic)
  1200. class Frost(_ImgcorruptAugmenterBase):
  1201. """
  1202. Wrapper around ``imagecorruptions.corruptions.frost``.
  1203. .. note::
  1204. This augmenter only affects images. Other data is not changed.
  1205. Added in 0.4.0.
  1206. **Supported dtypes**:
  1207. See :func:`~imgaug.augmenters.imgcorruptlike.apply_frost`.
  1208. Parameters
  1209. ----------
  1210. severity : int, optional
  1211. Strength of the corruption, with valid values being
  1212. ``1 <= severity <= 5``.
  1213. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1214. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1215. name : None or str, optional
  1216. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1217. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1218. Old name for parameter `seed`.
  1219. Its usage will not yet cause a deprecation warning,
  1220. but it is still recommended to use `seed` now.
  1221. Outdated since 0.4.0.
  1222. deterministic : bool, optional
  1223. Deprecated since 0.4.0.
  1224. See method ``to_deterministic()`` for an alternative and for
  1225. details about what the "deterministic mode" actually does.
  1226. Examples
  1227. --------
  1228. >>> # doctest: +SKIP
  1229. >>> import imgaug.augmenters as iaa
  1230. >>> aug = iaa.imgcorruptlike.Frost(severity=2)
  1231. Create an augmenter around
  1232. ``imagecorruptions.corruptions.frost``.
  1233. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1234. """
  1235. # Added in 0.4.0.
  1236. def __init__(self, severity=(1, 5),
  1237. seed=None, name=None,
  1238. random_state="deprecated", deterministic="deprecated"):
  1239. super(Frost, self).__init__(
  1240. apply_frost, severity,
  1241. seed=seed, name=name,
  1242. random_state=random_state, deterministic=deterministic)
  1243. class Snow(_ImgcorruptAugmenterBase):
  1244. """
  1245. Wrapper around ``imagecorruptions.corruptions.snow``.
  1246. .. note::
  1247. This augmenter only affects images. Other data is not changed.
  1248. Added in 0.4.0.
  1249. **Supported dtypes**:
  1250. See :func:`~imgaug.augmenters.imgcorruptlike.apply_snow`.
  1251. Parameters
  1252. ----------
  1253. severity : int, optional
  1254. Strength of the corruption, with valid values being
  1255. ``1 <= severity <= 5``.
  1256. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1257. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1258. name : None or str, optional
  1259. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1260. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1261. Old name for parameter `seed`.
  1262. Its usage will not yet cause a deprecation warning,
  1263. but it is still recommended to use `seed` now.
  1264. Outdated since 0.4.0.
  1265. deterministic : bool, optional
  1266. Deprecated since 0.4.0.
  1267. See method ``to_deterministic()`` for an alternative and for
  1268. details about what the "deterministic mode" actually does.
  1269. Examples
  1270. --------
  1271. >>> # doctest: +SKIP
  1272. >>> import imgaug.augmenters as iaa
  1273. >>> aug = iaa.imgcorruptlike.Snow(severity=2)
  1274. Create an augmenter around
  1275. ``imagecorruptions.corruptions.snow``.
  1276. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1277. """
  1278. # Added in 0.4.0.
  1279. def __init__(self, severity=(1, 5),
  1280. seed=None, name=None,
  1281. random_state="deprecated", deterministic="deprecated"):
  1282. super(Snow, self).__init__(
  1283. apply_snow, severity,
  1284. seed=seed, name=name,
  1285. random_state=random_state, deterministic=deterministic)
  1286. class Spatter(_ImgcorruptAugmenterBase):
  1287. """
  1288. Wrapper around ``imagecorruptions.corruptions.spatter``.
  1289. .. note::
  1290. This augmenter only affects images. Other data is not changed.
  1291. Added in 0.4.0.
  1292. **Supported dtypes**:
  1293. See :func:`~imgaug.augmenters.imgcorruptlike.apply_spatter`.
  1294. Parameters
  1295. ----------
  1296. severity : int, optional
  1297. Strength of the corruption, with valid values being
  1298. ``1 <= severity <= 5``.
  1299. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1300. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1301. name : None or str, optional
  1302. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1303. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1304. Old name for parameter `seed`.
  1305. Its usage will not yet cause a deprecation warning,
  1306. but it is still recommended to use `seed` now.
  1307. Outdated since 0.4.0.
  1308. deterministic : bool, optional
  1309. Deprecated since 0.4.0.
  1310. See method ``to_deterministic()`` for an alternative and for
  1311. details about what the "deterministic mode" actually does.
  1312. Examples
  1313. --------
  1314. >>> # doctest: +SKIP
  1315. >>> import imgaug.augmenters as iaa
  1316. >>> aug = iaa.imgcorruptlike.Spatter(severity=2)
  1317. Create an augmenter around
  1318. ``imagecorruptions.corruptions.spatter``.
  1319. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1320. """
  1321. # Added in 0.4.0.
  1322. def __init__(self, severity=(1, 5),
  1323. seed=None, name=None,
  1324. random_state="deprecated", deterministic="deprecated"):
  1325. super(Spatter, self).__init__(
  1326. apply_spatter, severity,
  1327. seed=seed, name=name,
  1328. random_state=random_state, deterministic=deterministic)
  1329. class Contrast(_ImgcorruptAugmenterBase):
  1330. """
  1331. Wrapper around ``imagecorruptions.corruptions.contrast``.
  1332. .. note::
  1333. This augmenter only affects images. Other data is not changed.
  1334. Added in 0.4.0.
  1335. **Supported dtypes**:
  1336. See :func:`~imgaug.augmenters.imgcorruptlike.apply_contrast`.
  1337. Parameters
  1338. ----------
  1339. severity : int, optional
  1340. Strength of the corruption, with valid values being
  1341. ``1 <= severity <= 5``.
  1342. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1343. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1344. name : None or str, optional
  1345. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1346. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1347. Old name for parameter `seed`.
  1348. Its usage will not yet cause a deprecation warning,
  1349. but it is still recommended to use `seed` now.
  1350. Outdated since 0.4.0.
  1351. deterministic : bool, optional
  1352. Deprecated since 0.4.0.
  1353. See method ``to_deterministic()`` for an alternative and for
  1354. details about what the "deterministic mode" actually does.
  1355. Examples
  1356. --------
  1357. >>> # doctest: +SKIP
  1358. >>> import imgaug.augmenters as iaa
  1359. >>> aug = iaa.imgcorruptlike.Contrast(severity=2)
  1360. Create an augmenter around
  1361. ``imagecorruptions.corruptions.contrast``.
  1362. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1363. """
  1364. # Added in 0.4.0.
  1365. def __init__(self, severity=(1, 5),
  1366. seed=None, name=None,
  1367. random_state="deprecated", deterministic="deprecated"):
  1368. super(Contrast, self).__init__(
  1369. apply_contrast, severity,
  1370. seed=seed, name=name,
  1371. random_state=random_state, deterministic=deterministic)
  1372. class Brightness(_ImgcorruptAugmenterBase):
  1373. """
  1374. Wrapper around ``imagecorruptions.corruptions.brightness``.
  1375. .. note::
  1376. This augmenter only affects images. Other data is not changed.
  1377. Added in 0.4.0.
  1378. **Supported dtypes**:
  1379. See :func:`~imgaug.augmenters.imgcorruptlike.apply_brightness`.
  1380. Parameters
  1381. ----------
  1382. severity : int, optional
  1383. Strength of the corruption, with valid values being
  1384. ``1 <= severity <= 5``.
  1385. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1386. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1387. name : None or str, optional
  1388. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1389. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1390. Old name for parameter `seed`.
  1391. Its usage will not yet cause a deprecation warning,
  1392. but it is still recommended to use `seed` now.
  1393. Outdated since 0.4.0.
  1394. deterministic : bool, optional
  1395. Deprecated since 0.4.0.
  1396. See method ``to_deterministic()`` for an alternative and for
  1397. details about what the "deterministic mode" actually does.
  1398. Examples
  1399. --------
  1400. >>> # doctest: +SKIP
  1401. >>> import imgaug.augmenters as iaa
  1402. >>> aug = iaa.imgcorruptlike.Brightness(severity=2)
  1403. Create an augmenter around
  1404. ``imagecorruptions.corruptions.brightness``.
  1405. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1406. """
  1407. # Added in 0.4.0.
  1408. def __init__(self, severity=(1, 5),
  1409. seed=None, name=None,
  1410. random_state="deprecated", deterministic="deprecated"):
  1411. super(Brightness, self).__init__(
  1412. apply_brightness, severity,
  1413. seed=seed, name=name,
  1414. random_state=random_state, deterministic=deterministic)
  1415. class Saturate(_ImgcorruptAugmenterBase):
  1416. """
  1417. Wrapper around ``imagecorruptions.corruptions.saturate``.
  1418. .. note::
  1419. This augmenter only affects images. Other data is not changed.
  1420. Added in 0.4.0.
  1421. **Supported dtypes**:
  1422. See :func:`~imgaug.augmenters.imgcorruptlike.apply_saturate`.
  1423. Parameters
  1424. ----------
  1425. severity : int, optional
  1426. Strength of the corruption, with valid values being
  1427. ``1 <= severity <= 5``.
  1428. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1429. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1430. name : None or str, optional
  1431. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1432. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1433. Old name for parameter `seed`.
  1434. Its usage will not yet cause a deprecation warning,
  1435. but it is still recommended to use `seed` now.
  1436. Outdated since 0.4.0.
  1437. deterministic : bool, optional
  1438. Deprecated since 0.4.0.
  1439. See method ``to_deterministic()`` for an alternative and for
  1440. details about what the "deterministic mode" actually does.
  1441. Examples
  1442. --------
  1443. >>> # doctest: +SKIP
  1444. >>> import imgaug.augmenters as iaa
  1445. >>> aug = iaa.imgcorruptlike.Saturate(severity=2)
  1446. Create an augmenter around
  1447. ``imagecorruptions.corruptions.saturate``.
  1448. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1449. """
  1450. # Added in 0.4.0.
  1451. def __init__(self, severity=(1, 5),
  1452. seed=None, name=None,
  1453. random_state="deprecated", deterministic="deprecated"):
  1454. super(Saturate, self).__init__(
  1455. apply_saturate, severity,
  1456. seed=seed, name=name,
  1457. random_state=random_state, deterministic=deterministic)
  1458. class JpegCompression(_ImgcorruptAugmenterBase):
  1459. """
  1460. Wrapper around ``imagecorruptions.corruptions.jpeg_compression``.
  1461. .. note::
  1462. This augmenter only affects images. Other data is not changed.
  1463. Added in 0.4.0.
  1464. **Supported dtypes**:
  1465. See :func:`~imgaug.augmenters.imgcorruptlike.apply_jpeg_compression`.
  1466. Parameters
  1467. ----------
  1468. severity : int, optional
  1469. Strength of the corruption, with valid values being
  1470. ``1 <= severity <= 5``.
  1471. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1472. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1473. name : None or str, optional
  1474. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1475. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1476. Old name for parameter `seed`.
  1477. Its usage will not yet cause a deprecation warning,
  1478. but it is still recommended to use `seed` now.
  1479. Outdated since 0.4.0.
  1480. deterministic : bool, optional
  1481. Deprecated since 0.4.0.
  1482. See method ``to_deterministic()`` for an alternative and for
  1483. details about what the "deterministic mode" actually does.
  1484. Examples
  1485. --------
  1486. >>> # doctest: +SKIP
  1487. >>> import imgaug.augmenters as iaa
  1488. >>> aug = iaa.imgcorruptlike.JpegCompression(severity=2)
  1489. Create an augmenter around
  1490. ``imagecorruptions.corruptions.jpeg_compression``.
  1491. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1492. """
  1493. # Added in 0.4.0.
  1494. def __init__(self, severity=(1, 5),
  1495. seed=None, name=None,
  1496. random_state="deprecated", deterministic="deprecated"):
  1497. super(JpegCompression, self).__init__(
  1498. apply_jpeg_compression, severity,
  1499. seed=seed, name=name,
  1500. random_state=random_state, deterministic=deterministic)
  1501. class Pixelate(_ImgcorruptAugmenterBase):
  1502. """
  1503. Wrapper around ``imagecorruptions.corruptions.pixelate``.
  1504. .. note::
  1505. This augmenter only affects images. Other data is not changed.
  1506. Added in 0.4.0.
  1507. **Supported dtypes**:
  1508. See :func:`~imgaug.augmenters.imgcorruptlike.apply_pixelate`.
  1509. Parameters
  1510. ----------
  1511. severity : int, optional
  1512. Strength of the corruption, with valid values being
  1513. ``1 <= severity <= 5``.
  1514. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1515. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1516. name : None or str, optional
  1517. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1518. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1519. Old name for parameter `seed`.
  1520. Its usage will not yet cause a deprecation warning,
  1521. but it is still recommended to use `seed` now.
  1522. Outdated since 0.4.0.
  1523. deterministic : bool, optional
  1524. Deprecated since 0.4.0.
  1525. See method ``to_deterministic()`` for an alternative and for
  1526. details about what the "deterministic mode" actually does.
  1527. Examples
  1528. --------
  1529. >>> # doctest: +SKIP
  1530. >>> import imgaug.augmenters as iaa
  1531. >>> aug = iaa.imgcorruptlike.Pixelate(severity=2)
  1532. Create an augmenter around
  1533. ``imagecorruptions.corruptions.pixelate``.
  1534. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1535. """
  1536. # Added in 0.4.0.
  1537. def __init__(self, severity=(1, 5),
  1538. seed=None, name=None,
  1539. random_state="deprecated", deterministic="deprecated"):
  1540. super(Pixelate, self).__init__(
  1541. apply_pixelate, severity,
  1542. seed=seed, name=name,
  1543. random_state=random_state, deterministic=deterministic)
  1544. class ElasticTransform(_ImgcorruptAugmenterBase):
  1545. """
  1546. Wrapper around ``imagecorruptions.corruptions.elastic_transform``.
  1547. .. warning::
  1548. This augmenter can currently only transform image-data.
  1549. Batches containing heatmaps, segmentation maps and
  1550. coordinate-based augmentables will be rejected with an error.
  1551. Use :class:`~imgaug.augmenters.geometric.ElasticTransformation` if
  1552. you have to transform such inputs.
  1553. Added in 0.4.0.
  1554. **Supported dtypes**:
  1555. See :func:`~imgaug.augmenters.imgcorruptlike.apply_elastic_transform`.
  1556. Parameters
  1557. ----------
  1558. severity : int, optional
  1559. Strength of the corruption, with valid values being
  1560. ``1 <= severity <= 5``.
  1561. seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1562. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1563. name : None or str, optional
  1564. See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.
  1565. random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
  1566. Old name for parameter `seed`.
  1567. Its usage will not yet cause a deprecation warning,
  1568. but it is still recommended to use `seed` now.
  1569. Outdated since 0.4.0.
  1570. deterministic : bool, optional
  1571. Deprecated since 0.4.0.
  1572. See method ``to_deterministic()`` for an alternative and for
  1573. details about what the "deterministic mode" actually does.
  1574. Examples
  1575. --------
  1576. >>> # doctest: +SKIP
  1577. >>> import imgaug.augmenters as iaa
  1578. >>> aug = iaa.imgcorruptlike.ElasticTransform(severity=2)
  1579. Create an augmenter around
  1580. ``imagecorruptions.corruptions.elastic_transform``.
  1581. Apply it to images using e.g. ``aug(images=[image1, image2, ...])``.
  1582. """
  1583. # Added in 0.4.0.
  1584. def __init__(self, severity=(1, 5),
  1585. seed=None, name=None,
  1586. random_state="deprecated", deterministic="deprecated"):
  1587. super(ElasticTransform, self).__init__(
  1588. apply_elastic_transform, severity,
  1589. seed=seed, name=name,
  1590. random_state=random_state, deterministic=deterministic)
  1591. # Added in 0.4.0.
  1592. def _augment_batch_(self, batch, random_state, parents, hooks):
  1593. cols = batch.get_column_names()
  1594. assert len(cols) == 0 or (len(cols) == 1 and "images" in cols), (
  1595. "imgcorruptlike.ElasticTransform can currently only process image "
  1596. "data. Got a batch containing: %s. Use "
  1597. "imgaug.augmenters.geometric.ElasticTransformation for "
  1598. "batches containing non-image data." % (", ".join(cols),))
  1599. return super(ElasticTransform, self)._augment_batch_(
  1600. batch, random_state, parents, hooks)