How to get line profile in Javascript

Hi,
I succeeded in doing this in a macro but not in Javascript - I am trying to get the x-values of an imageJ plot profile of a line selection. I used the following code:

importClass(Packages.ij.IJ);
importClass(Packages.ij.plugin.frame.RoiManager);
importClass(Packages.ij.io.OpenDialog);
importClass(Packages.ij.io.DirectoryChooser);
importClass(Packages.java.io.File);
importClass(Packages.ij.gui.GenericDialog);
importClass(Packages.ij.util.Tools);
importClass(Packages.ij.plugin.Duplicator);
importClass(Packages.ij.measure.ResultsTable);
importClass(Packages.ij.ImagePlus);
importClass(Packages.ij.process.ImageProcessor);
importClass(Packages.ij.util.ArrayUtil);
importClass(Packages.ij.gui.Overlay);
importClass(Packages.ij.plugin.filter.ParticleAnalyzer);
importClass(Packages.ij.gui.Roi);
importClass(Packages.ij.plugin.RGBStackMerge);
importClass(Packages.ij.process.ImageConverter);
importClass(Packages.ij.WindowManager);
importClass(Packages.ij.ImageStack);
importClass(Packages.ij.gui.ProfilePlot);
importClass(Packages.ij.gui.Line);
importPackage(java.awt);

imp = IJ.openImage("/Users/avitalsteinberg/RGB_FP_FOCI_Unsaturated/p41G-Im9-BFP-G4183_w3cf-2cam-RFP.tif");
IJ.run(imp, "Enhance Contrast", "saturated=0.35");
imp.setRoi(new Line(482,1383,508,1383));
//IJ.run(imp, "Plot Profile", "");
//imp.show();
prfl = ProfilePlot(imp); 
var profileYvals = prfl.getProfile();
var profileXvals = prfl.xValues;
print("The length of profileYvals is: " + profileYvals.length);
print("The length of profileXvals is: " + profileXvals.length);

But the following line gives an error:

var profileXvals = prfl.xValues;

The error is:

TypeError: Cannot read property "length" from undefined

Can anyone give me advice how to extract the x-values of the plot profile? I found a method to extract the y-values. I didn’t find a method to extract the x-values and when I tried to get it from the ProfilePlot object’s field, it didn’t work.

Thanks,
Avital

Yes, the ProfilePlot variable ‘xValues’ is protected as you can see here:

http://imagej.net/developer/api/ij/gui/ProfilePlot.html

Just a guess (without trying it). As you can see again in the ProfilePlot class you can get the Plot reference and extract the xValues there:

http://imagej.net/developer/api/ij/gui/Plot.html

http://imagej.net/developer/api/ij/gui/Plot.html#getXValues–

Something like:

prfl.getPlot().getXValues()

3 Likes

Thanks a lot - that solved my problem!

Avital