How is the plot profile calculated?



If I draw a line in ImageJ and then choose: Analyze, plot profile, I get a plot of gray values vs. the distance from the beginning of the line. How is this profile calculated, i.e., which pixels do the y-values in the plot represent? Because quite often, when I put a mouse over the pixels of the line in the image, the grayvalues don’t match the ones from the plot profile.



Good day Avital,

there are several ways to answer your question …

  • First, the results depend on which options you’ve checked in the “Plot Options” dialog.

  • Second, you may have a look at the source code, e.g. here:

  • Third, you may use a simple test image and find out from the results what is going on. I recommend a 16x16 8bit image filled with “ramp” and a diagonal selection line.




Thanks, Herbie - as you suggested, I made a ramp image and drew a line across it. I understand that when I draw a horizontal line from the beginning of a pixel, the values in the plot are simply the values of the pixels. And if I start out from the middle of a pixel, the values in the plot are the average of the two adjacent pixels.

As for a horizontal line, I didn’t understand how the values in the plot are obtained vs. the image values. I am using the default plot settings.




I don’t really understand your reply.

There is no “beginning of a pixel”, because a pixel is a number and a number has no spatial extension!

Why didn’t you use a diagonal line selection through the ramp image?
It could help …




Thanks, Herbie - I can understand that in the ramp image, the values are a weighted average of the two adjacent pixels, depending on how close I am to each pixel. But I’m not sure how it would work if I had squares. I tried to simulate it, but I found it confusing, especially because the line length in the plot varies abruptly from 1.5 to 2.0.


Good evening Avital!

“But I’m not sure how it would work if I had squares”

What squares?




Thanks, Herbie - what I mean is that in the ramp image, the grayvalues change in the horizontal direction but not in the vertical direction. I’m not sure what would happen if the grayvalues changed both in the horizontal and vertical directions.


Dear Avital,

here is perhaps not perfectly what you want but it may help with your investigations in interpolation schemes.

Original 16x16


Have fun



Cool - thanks a lot :slight_smile:



Please provide a small macro that demonstrates the problem. This one, for example, works as expected:

newImage(“Untitled”, “8-bit ramp”, 16, 16, 1);
makeLine(0, 8, 16, 8);
run(“Plot Profile”);


Hi Wayne,
When I draw a line above and below a white square, I get different behavior:

imp = IJ.createImage("imgSymm", "8-bit black", 16, 16, 1);
IJ.setBackgroundColor(255, 255, 255);, "Clear", "slice");
imp.setRoi(0,8,1,1);, "Clear", "slice");
imp.setRoi(new Line(0,0,0,6));, "Plot Profile", "");
imp.setRoi(new Line(0,15,0,9));, "Plot Profile", "");;

Why would this happen? And what do the y-values in the plot profile represent with respect to the image’s x,y coordinates and grayvalues? (we find it very useful to draw plot profiles, therefore, we’d like to completely understand it)



Dear Avital,

I’ve just run your script and both resulting profiles are identical. They consist of zeros only.
(Ij 1.50h2, Java 1.6.0_65, 64bit, OSX 10.8.5)

BTW, the image seems to have two pixels set to 255, i.e. I don’t see any square.




Thanks, Herbie - here is another attempt to generate the type of asymmetric behavior we observed: (white squares = pixels with a grayvalue of 255)


imp = IJ.createImage(“imgSymm”, “8-bit black”, 16, 16, 1);
imp = IJ.getImage();
imp.setRoi(new Line(0,15,0,8));, “Plot Profile”, “”);
imp.setRoi(new Line(0,7,0,0));, “Plot Profile”, “”);


And my version of Fiji is: 2.0.0-rc-43/1.50e Build: 49b669f9aa



sorry but I don’t see what your new script is supposed to do.

BTW, for various reasons I neither use Fiji nor ImageJ-2 but plain ImageJ-1.




Your script creates two all zero plots because neither line selection touches the two white (255) pixels. Here is a version of your script that creates a line that crosses the two white pixels, and it creates a plot with two 255 values, as expected.

imp = IJ.createImage(“imgSymm”, “8-bit black”, 16, 16, 1);_
IJ.setBackgroundColor(255, 255, 255);_
imp.setRoi(0,7,1,2);_, “Clear”, “slice”);_
imp.setRoi(new Line(0,0,0,16));_, “Plot Profile”, “”);_;

Note that in ImageJ and Java, pixels are to the right and below integer coordinates.


Thanks, Wayne and Herbie! The strange behavior seems to take place when I move a line around with the graphical user interface. The scripts’ behavior seems to make perfect sense. Emmanuel and I are both using macs. (if it has anything to do with it)



just curious: How do you get gray values displayed while moving a line selection with the cursor?

What I get are the coordinates and the line properties angle and length.

Indeed somehow strange



You can use the Live mode in the profile plot window:


If I use the following code:


imp = IJ.createImage("rand", "8-bit random", 16, 16, 1);
imp.setRoi(new Line(3.25,1.25,3.25,10.25));, "Plot Profile", "");

How will the grayvalue of the first point be calculated? What weights will the grayvalues of the pixels with the coordinates: (3,1),(3,2),(4,1) and (4,2) get?