# run cr2hdr with different options, render each one with ufraw-batch and extract a relevant crop window # at the end, make a montage with all the crop windows, showing what options was used for each crop # by default, crops are 700x700 # for each picture, you should specify: file name, exposure, and one or more crop windows import os, sys import commands cropw, croph = 700, 700 ufraw_options = "--wb=auto --grayscale=mixer --grayscale-mixer=1,0.6,0.1" cr2hdr = "cr2hdr-20bit" options = [ "--cs2x2", # default, but need a non-empty string "--no-cs", "--no-cs --mean23", "--no-cs --mean23 --no-alias-map", "--no-cs --mean23 --no-alias-map --no-fullres", "--no-cs --mean23 --no-alias-map --no-fullres --no-stripe-fix", ] pics = [ ('_MG_2269', 5, [(2200, 3200)]), ]; def run(cmd): print cmd return commands.getstatusoutput(cmd)[1] def change_ext(file, newext): return os.path.splitext(file)[0] + newext run("mkdir tmp") for pic, expo, crops in pics: for option in options: rebuild = False for cropx, cropy in crops: peep = "%s-%d-%d" % (pic, cropx, cropy) file = "%s/%s.jpg" % (peep, option) if not os.path.isfile(file) or os.path.getsize(file) < 20000: print "" print "" print "" print "Rendering", file print "*******************************************************" rebuild = True break else: print "Skipping", file if not rebuild: continue run("rm '%s'" % change_ext(pic, ".DNG")) r = os.system("%s '%s' %s" % (cr2hdr, change_ext(pic, ".CR2"), option)) if r == 0 and os.path.isfile(change_ext(pic, ".DNG")): run("ufraw-batch '%s' --exposure=%f --out-type=ppm --overwrite %s " % (change_ext(pic, ".DNG"), expo, ufraw_options)) else: print "cr2hdr failed" print change_ext(pic, ".DNG"), r, os.path.isfile(change_ext(pic, ".DNG")) run("convert dummy.png %s" % change_ext(pic, ".jpg")); run("rm 'tmp/%s'" % change_ext(pic, ".ppm")) run("mv '%s' tmp/" % change_ext(pic, ".DNG")) run("mv '%s' tmp/" % change_ext(pic, ".ppm")) for cropx, cropy in crops: peep = "%s-%d-%d" % (pic, cropx, cropy) file = "'%s/%s.jpg'" % (peep, option) run("mkdir %s" % peep) run("convert 'tmp/%s' -quality 100 -crop %dx%d+%d+%d %s" % (change_ext(pic, ".ppm"), cropw, croph, cropx, cropy, file)) run("convert %s -fill white -pointsize 14 -annotate +10+25 '%s' %s " % (file, option, file)) for pic, expo, crops in pics: for cropx, cropy in crops: peep = "%s-%d-%d" % (pic, cropx, cropy) run("montage %s/*.jpg -geometry %dx%d+5+5 %s.jpg" % (peep, cropw, croph, peep))