Blend.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # import
  2. # ------------------------------------------------------------------------------------------
  3. from . import Processing
  4. from . import ColorSpaceTransform
  5. from .. import image
  6. import colour, copy, skimage
  7. import numpy as np
  8. # ------------------------------------------------------------------------------------------
  9. # MIAM project 2020
  10. # ------------------------------------------------------------------------------------------
  11. # author: remi.cozot@univ-littoral.fr
  12. # ------------------------------------------------------------------------------------------
  13. class Blend(Processing.Processing):
  14. """description of class"""
  15. def __init__(self):
  16. pass
  17. def compute(self, img, **kwargs):
  18. """
  19. Blend([img], {'alpha':alpha})
  20. len([img]) = 2 / alpha in [0,1]
  21. img[0]*alpha + img[1]*(1 - alpha)
  22. """
  23. # kwargs
  24. alpha = 0.5
  25. if kwargs and ('alpha' in kwargs) :
  26. alpha = kwargs['alpha']
  27. if isinstance(img,list) :
  28. if len(img) == 2: # two images in the list
  29. img0, img1 = img[0], img[1]
  30. res = img0*alpha + img1*(1-alpha)
  31. # HDR or SDR
  32. if img0.isHDR() or img1.isHDR():
  33. res.type = image.imageType.imageType.HDR
  34. else: # not two images in the list
  35. return copy.deepcopy(img[0])
  36. else: # not list
  37. res = copy.deepcopy(img)
  38. return res