Beginner needs a short macro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Beginner needs a short macro

D Williams
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
Reply | Threaded
Open this post in threaded view
|

Re: Beginner needs a short macro

Thomas Pengo
Hi Deane

Actually if you have the Image Expression Parser plugin (comes with Fiji
http://fiji.sc/, a distribution of ImageJ, very recommended), you can
achieve this in one line (supposing the two images' window titles are
Image1 and Image2):

run("Image Expression Parser (Macro)", "expression=(A-B)/(A+B) a=[Image1]
b=[Image2] c=[(A - B) / (A + B)]");

Cheers
Thomas



On 7 June 2017 at 14:32, D Williams <[hidden email]> 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
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Beginner needs a short macro

Michael Schmid
In reply to this post by D Williams
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