Login  Register

Re: Beginner needs a short macro

Posted by Michael Schmid on Jun 08, 2017; 11:46am
URL: http://imagej.273.s1.nabble.com/Beginner-needs-a-short-macro-tp5018862p5018864.html

Hi Deane,

you can simply do the operation by hand and use Plugins>Macros>Record to
get the macro. In your case:

imageCalculator("Subtract create 32-bit", "image1","image2");
rename("difference");
imageCalculator("Add create 32-bit", "image1","image2");
selectWindow("Result of image1");
rename("sum");
imageCalculator("Divide create 32-bit", "difference","sum");
selectWindow("Result of difference");
rename("Result");
//make sure we fill the 16-bit range when converting from float
run("Conversions...", "scale weighted");
run("16-bit");
selectWindow("sum");
close();
selectWindow("difference");
close();
selectWindow("Result");

If your images are named differently, replace their names
"image1","image2" by variables and assign the correct name to the
variables. E.g.:

image1Name = "imgHorizontal.fit";
image2Name = "imgVertical.fit";
imageCalculator("Subtract create 32-bit", image1Name, image2Name);
rename("difference");
imageCalculator("Add create 32-bit", image1Name, image2Name);
etc.

You can also use ImageIDs instead of image names as arguments in the
macro; you get these with getImageID() for the current foreground image.
If there are only two open images, you can get the IDs like this:
   if (nImages != 2) exit("Error: Exactly two images required");
   id1 = getImageID(); //ID of currently open image
   selectImage(1);     //may select the current or other image
   if (getImageID()==id1) selectImage(2); //no it's the other
   id2 = getImageID();


Michael
________________________________________________________________
On 07/06/2017 21:32, D Williams wrote:
 > I would be grateful if someone would write a macro as show below.
 >
 > I've read the macro document but don't see a way to implement a math
 >
 > formula on two opened 16 bit .FIT images.
 >
 > The following method is used to calculate the Degree of Linear
Polarization
 > by
 >
 > working on two images: Image1 taken through a linear polarizer set to 0
 > degrees
 >
 > and Image2 set at 90 degrees.
 >
 > Calculate new values for each pixel as below:
 >
 > (Image1pixel value - Image2pixelvalue) / (Image1pixel value +
 > Image2pixelvalue)
 >
 > Then the resulting image is:
 >
 > Normalized and stretched so it fills the whole 16 bit range of pixel
 > brightness values.
 >
 >
 > Once I see how this works I will be able to modify it further as needed!
 >
 > Thanks!
 >
 >
 > Deane

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html