guiDisplayHDR.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # import
  2. # ------------------------------------------------------------------------------------------
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. import easygui
  6. import os
  7. # miam import
  8. import miam.image.Image as MIMG
  9. import miam.processing.TMO_Lightness as TMO_L
  10. import miam.histogram.Histogram as MHIST
  11. import miam.utils
  12. # ------------------------------------------------------------------------------------------
  13. # MIAM project 2020
  14. # ------------------------------------------------------------------------------------------
  15. # author: remi.cozot@univ-littoral.fr
  16. # ------------------------------------------------------------------------------------------
  17. if __name__ == '__main__':
  18. pathImage = easygui.fileopenbox(msg="select HDR image.")
  19. (path, name) =os.path.split(pathImage)
  20. print("selected image:", pathImage, "name:", name)
  21. # load image and remove zeros
  22. img = MIMG.Image.readImage(pathImage)
  23. img.name = name
  24. img = img.removeZeros().removeZeros(0.5)
  25. img.name = name
  26. print("dynamic range (0.5%):",img.getDynamicRange( percentile = 0.0, mode="f-stops"),"f-stops")
  27. hY = MHIST.Histogram.build(img,MIMG.channel.channel.Y,nbBins=50)
  28. # tonemap
  29. tmImg = img.process(TMO_L.TMO_Lightness())
  30. tmImg.name = img.name+"Lightness_TMO"
  31. htmL = MHIST.Histogram.build(tmImg,MIMG.channel.channel.L,nbBins=50)
  32. # sve tone mapped image
  33. tmImg.writeImage("../images/"+tmImg.name.split('.')[0]+"_Lightness_TMO")
  34. # plot
  35. fig, ax = plt.subplots(2,2)
  36. img.plot(ax[0,0])
  37. hY.plot(ax[0,1])
  38. tmImg.plot(ax[1,0])
  39. htmL.plot(ax[1,1])
  40. plt.show(block=True)
  41. # just Y
  42. #import miam.processing.ColorSpaceTransform as MCST
  43. #Y = MCST.ColorSpaceTransform().compute(tmImg,dest='XYZ')
  44. #plt.figure()
  45. #plt.imshow(Y.colorData[:,:,1],cmap='gray')
  46. #plt.show(block=True)