TMO_CCTF.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # import
  2. # ------------------------------------------------------------------------------------------
  3. from . import Processing
  4. from .. import image
  5. import colour, copy
  6. # ------------------------------------------------------------------------------------------
  7. # MIAM project 2020
  8. # ------------------------------------------------------------------------------------------
  9. # author: remi.cozot@univ-littoral.fr
  10. # ------------------------------------------------------------------------------------------
  11. class TMO_CCTF(Processing.Processing):
  12. """description of class"""
  13. def __init__(self):
  14. pass
  15. def compute(self, img, **kwargs):
  16. """
  17. CCTF tone mapping operator
  18. @params:
  19. img - Required : hdr image (miam.image.Image)
  20. kwargs - Optionnal : optionnal parameter (dict)
  21. 'function' : 'sRGB' (string)
  22. """
  23. if not kwargs:
  24. function = 'sRGB'
  25. elif 'function' in kwargs:
  26. function = kwargs['function']
  27. else:
  28. function = 'sRGB'
  29. res = copy.deepcopy(img)
  30. # can tone map HDR only
  31. if (img.type == image.imageType.imageType.HDR):
  32. # encode
  33. imgRGBprime = colour.cctf_encoding(res.colorData,function=function)
  34. # update attributes
  35. res.colorData = imgRGBprime
  36. res.type = image.imageType.imageType.SDR
  37. res.linear = False
  38. res.scalingFactor = 1.0
  39. res.colorSpace = colour.models.RGB_COLOURSPACES[function].copy()
  40. return res.clip()