How is the plot profile calculated?


#1

Hi,
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.

Thanks,
Avital


#2

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:
    https://github.com/imagej/imagej1/blob/master/ij/gui/ProfilePlot.java

  • 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.

Best

Herbie


#3

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.

Thanks,
Avital


#4

Avital,

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 …

HTH

Herbie


#5

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.


#6

Good evening Avital!

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

What squares?

Best

Herbie


#7

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.


#8

Dear Avital,

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

Original 16x16

Enlarged

Have fun

Herbie


#9

Cool - thanks a lot :slight_smile:

Avital


#10

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”);


#11

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.setTool("rectangle");
imp.setRoi(0,7,1,1);
IJ.setBackgroundColor(255, 255, 255);
IJ.run(imp, "Clear", "slice");
imp.setRoi(0,8,1,1);
IJ.run(imp, "Clear", "slice");
//IJ.setTool("line");
imp.setRoi(new Line(0,0,0,6));
IJ.run(imp, "Plot Profile", "");
imp.setRoi(new Line(0,15,0,9));
IJ.run(imp, "Plot Profile", "");
imp.show();

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)

Thanks,
Avital


#12

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.

Best

Herbie


#13

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

importClass(Packages.ij.IJ);
importClass(Packages.ij.gui.Line);

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


#14

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


#15

DearAvital,

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.

Clueless

Herbie


#16

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);_
IJ.run(imp, “Clear”, “slice”);_
imp.setRoi(new Line(0,0,0,16));_
IJ.run(imp, “Plot Profile”, “”);_
imp.show();

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


#17

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)


#18

Avital,

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

Herbie


#19

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


#20

If I use the following code:

importClass(Packages.ij.IJ);
importClass(Packages.ij.gui.Line);

imp = IJ.createImage("rand", "8-bit random", 16, 16, 1);
imp.setRoi(new Line(3.25,1.25,3.25,10.25));
IJ.run(imp, "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?

Thanks,
Avital