// Version 1.0 // 23/11/08 Mike Downey // Use the Nikon software to convert a NEF into a 16 bit uncompressed TIF // Requires the Calculator Plus plugin // Default parameters for the dodging/burning method. var burn = 1; // amount to reduce brightness etc. var dodge = 2; // amount to increase shadows. var blur = 0.9; // radius for the gaussian blur var shadow = 25; // Lighten this % of shadows var highlight = 75; // Darken anything above this % for highlights var saturated = 1; // % saturation for histogram adjustment. Dialog.create("HDR Image Creator"); Dialog.addMessage("Type in the highlight and\nshadow values as percentage\nof the dynamic range"); Dialog.addNumber("shadow",shadow); Dialog.addNumber("highlight",highlight); Dialog.addMessage("Type in the amount of dodging and\nburning to do"); Dialog.addNumber("dodge",dodge); Dialog.addNumber("burn",burn); Dialog.addMessage("Size of the blur in pixels for\nthe dodging and burning 'mask'"); Dialog.addNumber("blur",blur); Dialog.addMessage("What percentage of pixels do we\nset to maximum black/white?"); Dialog.addNumber("saturate",saturated); Dialog.show(); shadow = Dialog.getNumber(); highlight = Dialog.getNumber(); dodge = Dialog.getNumber(); burn = Dialog.getNumber(); blur = Dialog.getNumber(); saturated = Dialog.getNumber(); showProgress(0.1); params = "s"+shadow+" h"+highlight+" d"+dodge+" b"+burn+" blur"+blur+" sat"+saturated; setBatchMode(true); run("Duplicate...", "title=original duplicate"); run("32-bit"); // Prepare a copy which will be used for creating the mask. run("Duplicate...", "title=copy duplicate"); // If our image is a stack of 3, assume it is RGB and sum the slices if(nSlices() == 3){ run("Stack to Images"); // add greyscale stacks together imageCalculator("Add 32-bit", "Red","Green"); imageCalculator("Add 32-bit", "Result of Red","Blue"); // might need to do some scaling on these so that blue contributes less etc. // now close the images we don't need any more selectWindow("Red"); close(); selectWindow("Result of Red"); close(); selectWindow("Green"); close(); selectWindow("Blue"); close(); selectWindow("Result of Result"); } rename("greySum"); showProgress(0.2); getStatistics(area, mean, min, max, std, histogram); width = getWidth(); height = getHeight(); range = max - min; showProgress(0.3); lower = -1; upper = -1; pixelCount = 0; // Calculate the percentile values from the histogram. for (i = 0; i <= 255; i ++){ pixelCount += histogram[i]; percentile = pixelCount*100/(width*height); if (lower == -1 && percentile >= shadow){ lower = min + i * (range/256); } if (upper == -1 && percentile >= highlight){ upper = min + i * (range/256); } } showProgress(0.4); // Create a new 32 bit image which holds some sort of scaling factor selectWindow("greySum"); run("Duplicate...", "title=upper"); run("Subtract...", "value=" + upper); run("Min...", "value=0"); run("Divide...", "value=" + (range/burn)); run("Add...", "value=1"); // to prevent divide by zero showProgress(0.5); selectWindow("greySum"); run("Duplicate...", "title=lower"); run("Max...","value="+lower); run("Subtract...","value="+min); run("Divide...", "value=" + (range/dodge)); run("Add...", "value=1"); // to prevent divide by zero showProgress(0.6); imageCalculator("Divide 32-bit","upper","lower"); showProgress(0.7); rename("scaleMask"); run("Gaussian Blur...", "sigma="+blur); run("Calculator Plus", "i1=scaleMask i2=original operation=[Multiply: i2 = (i1*i2) x k1 + k2] k1=1 k2=0 create"); selectWindow("greySum"); close(); selectWindow("upper"); close(); selectWindow("lower"); close(); selectWindow("original"); close(); selectWindow("scaleMask"); close(); showProgress(0.8); setBatchMode("exit and display"); run("Enhance Contrast", "saturated="+saturated); run("8-bit"); // If we are dealing with a stack, convert to RGB. if (nSlices() == 3)run("RGB Color"); rename(params); showProgress(0.9); exit();