TMO_Linear.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_Linear(Processing.Processing):
  12. """description of class"""
  13. def __init__(self):
  14. pass
  15. def compute(self, img, **kwargs):
  16. """
  17. Linear tone mapping operator
  18. @params:
  19. img - Required : hdr image (miam.image.Image)
  20. kwargs - Optionnal : optionnal parameter (dict)
  21. 'min' : minimum value under which output is zero (float)
  22. 'max' : maximum value above which output is one (float)
  23. """
  24. minValue = 0.0
  25. maxValue = 1.0
  26. if not kwargs:
  27. kwargs = {'min': 0.0, 'max': 1.0}
  28. # min value
  29. if 'min' in kwargs:
  30. minValue = kwargs['min']
  31. else:
  32. minValue = 0.0
  33. # max value
  34. if 'max' in kwargs:
  35. maxValue = kwargs['max']
  36. else:
  37. maxValue = 1.0
  38. res = copy.deepcopy(img)
  39. # can tone map HDR only
  40. if (img.type == image.imageType.imageType.HDR):
  41. # value between [min,max] -> [0,1]
  42. imgRGB = (res.colorData-minValue)/(maxValue-minValue)
  43. imgRGB[imgRGB>=1.0] = 1.0
  44. imgRGB[imgRGB<=0.0] = 0.0
  45. # encode
  46. imgRGBprime = colour.cctf_encoding(imgRGB,function='sRGB')
  47. # update attributes
  48. res.colorData = imgRGBprime
  49. res.type = image.imageType.imageType.SDR
  50. res.linear = False
  51. res.scalingFactor = 1.0 # res.scalingFactor/(max-min)
  52. return res