localEQ_all.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.ContrastControl as PCC
  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)
  24. img.name = name
  25. # tonemap
  26. leqImg = img.process(PCC.ContrastControl(),method='localEqualization', size=1500)
  27. leqImg.name = img.name+"_localEQ"
  28. # save tone mapped image
  29. leqImg.writeImage("../local_EQ/"+leqImg.name)
  30. print('core:', current.name,"(",current._identity,")","::",leqImg.name,":: done n saved")
  31. return None
  32. if __name__ == '__main__':
  33. print("MIAM: local equalization of all 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. tmopath = "../lightness_TMO/"
  40. leqpath = "../local_EQ/"
  41. for h in hdrfiles:
  42. path, name, ext = miam.utils.splitFileName(h)
  43. tmofile = tmopath+name+"_Lightness_TMO.jpg"
  44. leqfile = leqpath+name+"_Lightness_TMO"+"_localEQ.jpg"
  45. tmofileOK = os.path.isfile(tmofile)
  46. leqfileOK = os.path.isfile(leqfile)
  47. #print("source:", h,
  48. # "tmofile::",tmofile,"::", tmofileOK,
  49. # "leqfile::",leqfile,"::", leqfileOK,
  50. # )
  51. if (tmofileOK and (not leqfileOK)): todo.append(tmofile)
  52. listFiles = todo
  53. print(" ---- number of images:",len(listFiles))
  54. for f in listFiles: print(" ---- file:", f)
  55. print(" ---- launch local equalization !")
  56. _pool = mp.Pool()
  57. result = _pool.map(pfun, listFiles)
  58. print(" ---- local equalize all done !")