// DD Macro. 2011.11.30 by Jeffrey N. Murphy // For use with ImageJ, available at http://rsbweb.nih.gov/ij/ // The license for this code (the "MIT License") is appended at the end of the file. // An ImageJ macro for modifying SEM images of plantinum nanostructures // to permit the visual differentiation between (1) the substrate background, // (2) the "dim" lines templated by the lower cylinders, and (3) the "bright" // lines templated by the upper cylinders. // Smooth to Reduce Noise run("Duplicate...", "title=copy"); run("Median...", "radius=2"); img1 = getImageID(); // Auto-Adjust Brightness and Contrast dCount = 0.25; // Fraction of pixels which will be set to 0. "dark Count" bCount = 0.03; // Fraction of pixels which wil be set to 255. "bright Count" nBins = 256; w = getWidth(); h = getHeight(); pixelCount = w*h; getHistogram(values, counts, nBins); pxFraction = newArray(nBins); sum = 0; hist_min = 0; hist_max = 255; d_off = 0; b_off = 0; DC = dCount; BC = 1-bCount; for(i=0; i=DC){hist_min=i; d_off=1;}} if(b_off==0){if(pxFraction[i]>=BC){hist_max=i; b_off=1;}} } setMinAndMax(hist_min,hist_max); run("Apply LUT"); // Find Pixel Value for Lower Cylinders getStatistics(area, mean, min, max, std, histogram); getHistogram(val, cts, nBins); v_mean = round(mean); // User Choice for Middle Peak run("Histogram"); enter_mean = v_mean; Dialog.create("User Input Required"); Dialog.addMessage("Enter a value. The macro will use this to equalize the histogram. :"); Dialog.addNumber("Current value:",enter_mean); Dialog.show(); enter_mean = Dialog.getNumber; // Apply Bi-Linear Equalization selectImage(img1); run("Duplicate...", "title=Final_Image"); img2 = getImageID(); setBatchMode(true); ctr = enter_mean; disp = 128-ctr; for(y=0; yctr){ s = (255-a)/(255-ctr); } else { s = 1; } setPixel(x,y,a+disp*s); } } setBatchMode(false); print("Minimum: "+hist_min+" Maximum: "+hist_max+" Peak: "+enter_mean); // This code is licensed using the "MIT License", available at http://www.opensource.org/licenses/mit-license.php // // Copyright (c) 2011 Jeffrey N. Murphy // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.