Hier die Skripte.
So, hier noch die Skripte in voller Hässlichkeit:
Code: calc_mask.ijm
// extract mask
// get relevant data for output file name
title = getTitle();
path = getInfo("image.directory");
file_name_no_extension = File.getNameWithoutExtension(title);
// calculate coordinates for central selection rectangle
image_width = getWidth();
image_center = image_width / 2;
mask_width = image_width / 8;
// select central part of image and copy to clipboard
//setTool("rectangle");
makeRectangle(image_center - mask_width / 2, image_center - mask_width / 2, mask_width, mask_width);
setBackgroundColor(255, 255, 255);
run("Copy");
// paste from Internal Clipboard
run("Internal Clipboard");
// save file
saveAs("PNG", path + file_name_no_extension+"_mask.png");
// close both files
close();
Alles anzeigen
Code: calc_diff.ijm
// calculate diffraction pattern of file
// output is a series of files
// get relevant data for output file name
title = getTitle();
path = getInfo("image.directory");
file_name_no_extension = File.getNameWithoutExtension(title);
// different maximal intensity can be selected. Scale is in -mag (astronomical magnitude)
max_intensity = 0;
//max_intensity = 2;
//max_intensity = 5;
// create output directory from intensity
output_path = path + max_intensity + File.separator;
File.makeDirectory(output_path);
// calculate coordinates for central selection rectangle
image_width = getWidth();
image_center = image_width / 2;
PSF_width = image_width / 8;
// calculate PSF from input file.
run("FFT Options...", "raw do");
selectWindow("PS of "+title);
// select central part of image and copy to clipboard
//setTool("rectangle");
makeRectangle(image_center - PSF_width / 2, image_center - PSF_width / 2, PSF_width, PSF_width);
setBackgroundColor(255, 255, 255);
run("Copy");
// paste from Internal Clipboard
run("Internal Clipboard");
// get minimum and maximum values
resetMinAndMax();
getMinAndMax(min, max);
// scale image so max value is 1.0
run("Divide...", "value="+max);
// save image as 32bit TIFF
saveAs("TIFF", output_path+file_name_no_extension+"_diff.tif");
// calculate log (log_base_e) of image
run("Log");
// scale for -mag (astronomical magnitude)
scale_factor = 5 / log(100);
run("Multiply...", "value="+scale_factor);
// again scale intensity so max value is 0mag
resetMinAndMax();
getMinAndMax(min, max);
run("Subtract...", "value="+max);
// only show intensity values from 15mag to 0mag
setMinAndMax(-15 - max_intensity, 0 - max_intensity);
// use "Thermal" LUT for better visualisation
//run("Apply LUT");
run("Thermal");
// save as 8 bit PNG file
saveAs("PNG", output_path+file_name_no_extension+"_diff.png");
// create 3D Surface Plot from file and save as PNG file
run("3D Surface Plot", "plotType=3 smooth=0 colorType=0 scale=0.9 snapshot=1 rotationZ=45");
saveAs("PNG", output_path+file_name_no_extension+"_sp.png");
// select line from center to right edge
selectWindow(file_name_no_extension+"_diff.png");
makeLine(PSF_width / 2, PSF_width / 2, PSF_width - 1, PSF_width / 2);
// create intensity plot across line
run("Plot Profile");
Plot.setLogScaleY(false);
// only show values from 15mag to 0mag and only 11th maximum (ring n to ring n+1 = 17px)
Plot.setLimits(0.0,191.0,-15.0,0.0);
Plot.setFontSize(12.0);
Plot.setStyle(0, "blue,none,2.0,Line");
Plot.setXYLabels("Distance (pixels)", "Relative mag");
Plot.setFormatFlags("11001100111111");
// save plot as PNG
saveAs("PNG", output_path+file_name_no_extension+"_plot.png");
// export plot data as CSV
run("Clear Results");
Plot.getValues(xpoints, ypoints);
for (i=0; i<xpoints.length; i++)
setResult("Value", i, ypoints[i]);
updateResults();
saveAs("Results", output_path+file_name_no_extension+"_values.csv");
run("Close");
selectWindow(file_name_no_extension+"_plot.png");
close();
// now create polar visualisation (needs Polar Transformer Plugin)
// select central part of diffraction pattern
// calculate coordinates for central selection rectangle
selectWindow(file_name_no_extension+"_diff.png");
image_width = getWidth();
image_center = image_width / 2;
PSF_width = image_width / 4;
// select central part of image and copy to clipboard
//setTool("rectangle");
makeRectangle(image_center - PSF_width / 2, image_center - PSF_width / 2, PSF_width, PSF_width);
setBackgroundColor(255, 255, 255);
run("Copy");
run("Internal Clipboard");
run("Select All");
// calculate min value for later rescaling intensity
getMinAndMax(min, max);
minmin=-255/min;
setOption("ScaleConversions", true);
// polar transformation only works in 8-bit or 16-bit mode
run("8-bit");
run("Polar Transformer", "method=Polar degrees=360 default_center for_polar_transforms,");
run("Thermal");
run("Rotate 90 Degrees Right");
// change back to 32-bit mode and rescale intensity to -mag
run("32-bit");
run("Subtract...", "value="+255);
run("Divide...", "value="+minmin);
resetMinAndMax();
// only use data within circle of 180px
makeRectangle(0, 0, 359, 179);
setBackgroundColor(255, 255, 255);
run("Copy");
run("Internal Clipboard");
// save as PNG
saveAs("PNG", output_path+file_name_no_extension+"_pol.png");
// create ROI (regions of interest) table. We are interested in the first 11 diffraction rings
run("ROI Manager...");
for(i=1; i < 12; i++) {
makeLine(0, 10*i + 7, 359, 10*i + 7);
roiManager("Add"); }
// selectWindow("Profiles");
roiManager("Multi Plot");
Plot.setStyle(0, "gray,none,2.0,Line");
Plot.setStyle(1, "red,none,2.0,Line");
Plot.setStyle(2, "green,none,2.0,Line");
Plot.setStyle(3, "blue,none,2.0,Line");
Plot.setStyle(4, "magenta,none,2.0,Line");
Plot.setStyle(5, "cyan,none,2.0,Line");
Plot.setStyle(6, "yellow,none,2.0,Line");
Plot.setStyle(7, "orange,none,2.0,Line");
Plot.setStyle(8, "Red,none,2.0,Line");
Plot.setStyle(9, "Green,none,2.0,Line");
Plot.setStyle(10, "Blue,none,2.0,Line");
Plot.setLogScaleY(false);
Plot.setLimits(0.0,360.0,-15.0,0.0);
Plot.setFontSize(12.0);
Plot.setXYLabels("Distance (pixels)", "Value");
Plot.setFormatFlags("11001100111111");
// save polar visualisation as PNG
saveAs("PNG", output_path+file_name_no_extension+"_angular_psf.png");
// create plot from ROI data and save as CSV
Plot.showValues();
saveAs("Results", output_path+file_name_no_extension+"_apsf.csv");
// clean up and close as open files
run("Close");
close("ROI Manager");
//close("*");
close();
close();
close();
close();
close();
close();
close();
close();
Alles anzeigen