lightnessTMO_all.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # import
  2. # ------------------------------------------------------------------------------------------
  3. import os
  4. import multiprocessing as mp
  5. import matplotlib.pyplot as plt
  6. import numpy as np
  7. import easygui
  8. import colour
  9. # miam import
  10. import miam.image.Image as MIMG
  11. import miam.processing.TMO_Lightness as TMO_L
  12. import miam.utils
  13. # ------------------------------------------------------------------------------------------
  14. # MIAM project 2020
  15. # ------------------------------------------------------------------------------------------
  16. # author: remi.cozot@univ-littoral.fr
  17. # ------------------------------------------------------------------------------------------
  18. def pfun(f):
  19. path, name, ext = miam.utils.splitFileName(f)
  20. current = mp.current_process()
  21. print('core:', current.name,"(",current._identity,")","::",name)
  22. # load image and remove zeros
  23. img = MIMG.Image.readImage(f).removeZeros().removeZeros(0.5)
  24. img.name = name
  25. # tonemap
  26. tmImg = img.process(TMO_L.TMO_Lightness())
  27. tmImg.name = img.name+"_Lightness_TMO"
  28. # sve tone mapped image
  29. tmImg.writeImage("../lightness_TMO/"+tmImg.name)
  30. print('core:', current.name,"(",current._identity,")","::",tmImg.name,":: done n saved")
  31. return None
  32. if __name__ == '__main__':
  33. print("MIAM: lightness tone all hdr images")
  34. nbCpu = mp.cpu_count()
  35. print(" ---- found:", nbCpu, "cpu cores")
  36. srcPath = "../../../photos/HDR-DB/HDR/"
  37. hdrfiles = os.listdir(srcPath)
  38. todo = []
  39. respath = "../lightness_TMO/"
  40. for h in hdrfiles:
  41. path, name, ext = miam.utils.splitFileName(h)
  42. jfile = respath+name+"_Lightness_TMO.json"
  43. tmofile = respath+name+"_Lightness_TMO.jpg"
  44. jfileOk = os.path.isfile(jfile)
  45. tmofileOK = os.path.isfile(tmofile)
  46. if ((not jfileOk) or (not tmofileOK)): todo.append(h)
  47. listFiles = list(map(lambda x : srcPath+x, todo))
  48. print(" ---- number of images:",len(listFiles))
  49. for f in listFiles: print(" ---- file:", f)
  50. print(" ---- launch tone mapping !")
  51. _pool = mp.Pool()
  52. result = _pool.map(pfun, listFiles)
  53. print(" ---- tone mapping all done !")