Problem with profile plot


for test purposes I created an image with the following macro: if ((x%4) > 1) v=32000; else v = 0

The image has vertical stripes of width 2 with alternating values 0 and 32000. This is what I wanted.
However, if I plot a profile along a horizontal line, I get this:
This is obviously not the correct profile I was expecting. What did I do wrong?


Hello Hermann-Josef -

I suspect that your line isn’t quite horizontal and therefore
the values in your profile plot are interpolated pixel values.
When I try to repeat your experiment with a line that I am
careful to make exactly horizontal, I can’t reproduce your

Here is a jython script that illustrates what I think is happening:

from ij import IJ
from ij.gui import Line
imp = IJ.createImage ("stripes", "16-bit black", 128, 128, 1)
# impId = imp.getID()
ip = imp.getProcessor()
for  x in range (128):
  for  y in range (128):
    if  x % 4 > 1:
      ip.putPixel (x, y, 0)
      ip.putPixel (x, y, 32000)
imp.setRoi (Line (32, 64, 85, 64))
imp.setTitle ('horizontal roi') ('Plot Profile')
IJ.selectWindow (imp.getID())
imp.setRoi (Line (32, 64, 77, 32))
imp.setTitle ('slanted roi') ('Plot Profile')

And here are the profile plots it produces:

Plot of horizontal roi.png:

Plot of slanted roi.png:

“Plot of horizontal roi” shows the expected values of 0 and
32000, alternating back and forth. “Plot of slanted roi” looks
more like your plot with some of the values falling in between
0 and 32000.

Thanks, mm


Thank you very much for your effort. I am very embarrassed to admit that I had forgotten an essential piece of information. I am very sorry for this!

The image was binned 3x3 for the plot. If I plot the original, the graph is perfectly okay. I marked the ROI as a line with the shift-key pressed, i.e. it is exactly horizontal. The strange behaviour only shows with the binned image and contradicts what I read off from the image with the cursor.


Hello Hermann-Josef -

Well, this is perplexing.

If I run the script I posted above to create the striped image, and
then run Image > Transform > Bin... and do a 3x3 average,
I get the binned image I would expect. If I select a horizontal line
and run Analyze > Plot Profile (on the binned image), I get
the expected profile plot and the values in the plot agree with the
values I read off the (binned) image (using the cursor and reading
the values from the Fiji status bar).

I’m not able to reproduce what you are describing.

I am running a recently auto-updated stock Fiji install, “ImageJ
2.0.0-rc-69/1.52n” running on ubuntu 16.04 LTS.

Could you post a sample image (ideally both unbinned and binned,
as a .png’s) and step-by-step instructions (or, better still, a script)
that reproduces what you see? Right now, I’m stuck.

Thanks, mm


Thank you so much for looking into this.

I have put both the original and the binned image into my Adobe fog for retrieval.

I am using imageJ .52n on a Win10 64bit system. There is no need for a script. I just set up a linear, horizontal ROI and plot the profile with “Analyze – plot profile”. That’s all.


Hello Hermann-Josef -

I’m still not able to reproduce your issue.

For browser convenience, here is a .png of the binned image you
linked to above:


(The original unbinned and binned .tif images appear below.)

This image has (as I would expect) pixel values of 10667 and
21333. Here is what I get for your original binned .tif image using
Analyze > Histogram:


And here is what I get running Analyze > Plot Profile after
selecting on the .tif image a horizontal line:


I just don’t see how you can get the profile plot you did. Regardless
of the specific pattern of pixel values, your profile plot shows pixel
values that go to the min and max of your unbinned image – way
outside the min and max of your binned image.

(I tried playing around with the Interpolate line profiles
and Sub-pixel resolution "Profile Plot Options: under
Edit > Options > Plots..., but, for this use case, they
had no effect.)

For forum convenience, I’ve uploaded the .tif images from your
adobe link:

Binning_Streifen.tif (128.2 KB)

Binning_Streifen_IJ_Ergebnis.tif (14.3 KB)

(In my browser, at least, the .tif images don’t display, but curious
minds can download them using the above links.)

I just don’t see what you’re seeing, and it appears that we’re using
(more or less) the same version of ImageJ.

Thanks, mm

Hello Hermann-Josef,
I’m sorry to butt-in, the profile plot is a continuous line plot, so when it goes from the center of the white stripe (top) to the center of the black stripe (bottom) it has to form a diagonal line as you are obtaining.
If it were a bar plot it would look exactly as you expected, so you are not doing anything wrong just visualizing the output different than you expected.

Good morning @mountain_man and @smith_robertj,

Thanks for your replies. I have found the solution! The plot of the binned image is correct only, when the image is not zoomed or zoomed with a small factor. Since it is a small image I zoomed in heavily to read the cursor values more easily. And then on the zoomed image, the plot is as shown in my first contribution – not correct.

Original binned image with no zoom:

If I just zoom in and leave the ROI untouched, the plot remains correct. If I delete the ROI and create a new ROI (straight horizontal line) I get the wrong plot:

The zoom factor has to be quite large to produce the wrong plot.


Hello Hermann-Josef -

Yes, that appears to be it. I can confirm that zooming causes the
profile plot issue.

I tried zooming (a lot) both your unbinned and binned images.
I then add a horizontal line selection and run Plot Profile.
When I do this, I get incorrect results, similar to what you see.

Looks like a bug in Plot Profile to me. I guess, somehow,
the zooming is causing it to interpolate pixel values, or something.
I do note that the zoomed image, as displayed on my screen,
shows no hint of interpolated pixel values. So the problem seems
to be in Plot Profile itself, not in pixel values it’s getting from
the zoomed image.

(I think the binning was a red herring. As I noted, I can reproduce
the problem with your unbinned image.)

Thanks, mm


Thanks a lot for the verification.


Hello Hermann-Josef -

To correct some of my earlier comments, I don’t think this
is a bug, and it can be viewed as expected behavior.

First, I was wrong when I said that Edit > Options > Plots... /
Interpolate line profiles had no effect.

Turning this option off turns off the behavior you described,
and turning it back on restores that behavior.

Second, it is possible to have horizontal Line Rois that
don’t correspond to integer pixel locations. It’s these
non-integer Lines that trigger this behavior. However, I
believe that it is not possible to draw such a non-integer
Roi with the line tool on an unzoomed image. This would
explain why you only saw this with a zoomed image.

This behavior can be demonstrated as follows:

First, check the Interpolate line profiles check box
to turn this option on.

Run File > Open Samples > Striped Circles, and then
run Image > Type > 8-bit. (This opens a striped sample
image, and, for convenience, converts it to grayscale. You could
also open one of Hermann-Josef’s striped example images.)

Zoom the image to 150% (<Ctrl> +).

Use the (horizontal) “Straight” drawing tool to select a
non-integer selection. To do this, watch the Fiji status
bar, and stop drawing the Roi when the value of “length”
is not a round integer. (For example, I started my Roi
at “x=100” and stopped with “length=10.67”. Also, make
sure that “angle=0.0” by holding the <Shift> key.)

Run Analyze > Plot Profile.

Leave the image and its Roi unchanged, turn
Interpolate line profiles off, and rerun
Analyze > Plot Profile.

Here are the two profile plots:

With interpolation on:

and with interpolation off:

Although I was initially surprised by this behavior, I
no longer see it as a bug. I could see times when you
would want to interpolate the pixel values, and if you
don’t want interpolation, you can turn that option off.

Thanks, mm



Thanks a lot for the clarification.