Posted by
adam@ajblake.info on
May 15, 2014; 6:46pm
URL: http://imagej.273.s1.nabble.com/Calculating-atan2-on-pixels-from-two-input-images-in-a-macro-tp5007758.html
Hello all,
My Question:Is there a way of creating a new image (in a reasonable amount of time) from the atan2 value calculated from the pixel values of two input images, in an imageJ macro? Can this be done within a macro or will this require a script or plugin?
Background on what I'm doing and what I've attempted:I have been writing a macro to calculate intensity (
I), degree of linear polarization (
p), and angle of polarization (Ψ) from a set of four photographs taken with a polarizing filter at different angles (0, 45, 90, 135) (
addition info on polarimetry measurements). I have created the macro work on multiple sets of such images.
I am able to calculate
I &
p without to much trouble using the image calculator and the process>math functions. I have hit a roadblock with calculating Ψ though. The formula to calculate Ψ is:
Ψ = 0.5*atan(
U/
Q)
U & Q are stokes parameters calculated from intensity values from the images (see link above)
Unfortunately atan have different values depending on the sign of the two inputs, so I cannot simply divide U by Q and take the atan of the value like this:
imageCalculator("Divide create 32-bit", "U","Q");
selectWindow("Result of U");
run("Macro...", "code=v=0.5*atan(v)");
The atan2 function takes the different values into account but requires two inputs and must be iterated over each pixel. I've tried the code below but it is incredibly slow.
selectImage(U);
w = getWidth();
h = getHeight();
newImage("Ψ", "32-bit", w, h, 1)
for (y=0; y<h; y++) {
for (x=0; x<w; x++) {
selectImage(U)
Upixel=getPixel(x, y);
selectImage(Q)
Qpixel=getPixel(x, y);
setPixel(x, y, 0.5*atan2(Upixel, Qpixel))
}
}
updateDisplay();
Fiji has the Image Expression Parser which does exactly what I want (0.5*atan2(A,B)), but at least I haven't figured out a way to pass arguments to the Parser from a macro.
I know this is possible to calculate within a plugin, but I have yet to find one that I can incorporate into my macro. Any idea how to calculate this in my macro would be appreciated. Would this particular task be better suited to a script or plugin? I can post my code thus far if it would be helpful.
Thanks,
Adam Blake