import jmFijiGen as jmg



homDir     = os.environ['HOME']
edsDir     = os.environ['EDS_ROOT']
ePrjDir    = "QM14-04-04D1-Steele"
sampID     = "qm-04227-49G003-456-R-15-FIB"
mapID      = "7kV-map4"   
datDir     = "/Oxford/" + ePrjDir + "/reports/" + sampID + "/" + sampID + "-" + mapID
relWrk     = datDir + "/work"
wrkDir     = edsDir + relWrk

strROI = wrkDir + "/" + "ROI.png"
impRoi = IJ.openImage(strROI)

lName   = ["O-K","Cu-L", "P-K", "Pd-L", "Ag-L"]

for name in lName:
  strImg = wrkDir + "/" + name +".png"
  impExp = IJ.openImage(strImg)
  impOvr = jmg.makeFlattenedTransparentOverlay(impRoi, impExp, op=50)
  impOvr.show()
  strImg = wrkDir + "/" + name +"-ROI.png"
  if os.access(strImg, os.R_OK):
    os.remove(strImg)
  IJ.saveAs(impOvr, "PNG", strImg)
  impOvr.close()
  

# testHeadlessFlatten.py
import os
from ij import IJ
import jmFijiGen as jmg

imgDir = os.environ['IMG_ROOT']
edsDir = os.environ['EDS_ROOT']
relDir = "/Oxford/QM14-nn-nnA-Client/reports/qm-nnnnn-sampleID/qm-nnnnn-sampleID-nnkV-map1/work"
inDir  = edsDir + relDir

pthRoi = inDir + "/ROI.png"
pthCuL = inDir + "/Cu-L.png"

impRoi = IJ.openImage(pthRoi)
impCuL = IJ.openImage(pthCuL)

# headlessFlatten is built into jmg.makeFlattenedTransparentOverlay
impTol = jmg.makeFlattenedTransparentOverlay(impRoi, impCuL, op=50)
# flat = headlessFlatten(impTol)
impTol.show()

outPth = imgDir + "/tmp/foo-fl.png"
IJ.saveAs(impTol, "PNG", outPth)

# imp.show()
# impRoi.show()