Posted by
adam@ajblake.info on
Aug 21, 2014; 8:54am
URL: http://imagej.273.s1.nabble.com/Calculating-atan2-on-pixels-from-two-input-images-in-a-macro-tp5007758p5009285.html
I thought I would give some followup for anyone who might be running into a similar problem.
I was able to get the beanshell code from bnorthan working. This code ran much faster than for loops in the macro language but still required several minutes for a ~12 megapixel image. I was able to find a java plugin performing a similar calculation here (
http://www.physics.umanitoba.ca/~westjl/thesis/chapter0.pdf, Appendix 2, pg 200). I was able to modify the code to serve my needs. This code runs in less than a second. I have posted the modified code below.
import ij.*;
import ij.process.*;
import java.awt.*;
import ij.plugin.filter.*;
/**
* Produces a polarized intensity or polarization angle image given
* Stokes Q and Stokes U images as input
*/
public class atan_ implements PlugInFilter {
ImagePlus imp;
public int setup(String arg, ImagePlus imp) {
this.imp = imp;
return DOES_ALL;
}
public void run(ImageProcessor ip) {
ImageProcessor ipQ = WindowManager.getImage("Q").getProcessor();
ImageProcessor ipU = WindowManager.getImage("U").getProcessor();
double ratio =0;
double value =0;
int offset, i, x, y;
int width = ipQ.getWidth();
int height = ipQ.getHeight();
ImageProcessor newIp = new FloatProcessor(width, height);
for (y=0; y<height; y++) {
for (x=0; x<width; x++) {
value = 0.5*Math.atan2
(ipU.getPixelValue(x,y),
ipQ.getPixelValue(x,y));
newIp.putPixelValue(x,y,value);
}
}
String imTitle = "a1";
ImagePlus newImp = new ImagePlus(imTitle, newIp);
newImp.show();
}
}