noise.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from ipfml.filters import noise as nf
  2. def get_noise_result(_image, _n, _noise_choice, _identical=False, _p=None):
  3. """Return image with applied noise using choice
  4. Args:
  5. image: image to convert
  6. _n: importance of noise expected [1, 999]
  7. _noise_choice: choise of noise filter to apply
  8. _identical: specify if the distribution is the same or not for each chanel
  9. _p: optional parameter for salt_pepper noise
  10. Returns:
  11. Noisy image with noise filter applied
  12. """
  13. noise_method = None
  14. function_name = _noise_choice + '_noise'
  15. try:
  16. noise_method = getattr(nf, function_name)
  17. except AttributeError:
  18. raise NotImplementedError("Noise filter `{}` not implement `{}`".format(nf.__name__, function_name))
  19. if _p:
  20. if _noise_choice != 'salt_pepper':
  21. raise ValueError("p parameter is only used for salt pepper noise...")
  22. return noise_method(_image, _n, identical=_identical, p=_p)
  23. else:
  24. return noise_method(_image, _n, identical=_identical)