Image representation in ImageJ

Hi there,

In Matlab a image is represented by a 2D array (Matrix). Similar in ImageJ how a image is represented? I hope you got the question.


Good day,

I fear there are not many alternatives to 2D arrays …

AFAIK, Matlab follows a different convention regarding the orientation of the y-axis.

ImageJ: down = positive (can be changed in the options section)
Matlab: up = positive

Because ImageJ is open source you, may investigate the whole source code and convince yourself.



Thank you very much. :slight_smile:

In fact, ImageJ1 internally represents each image plane as a 1-dimensional array of values, together with the information of width and height to display it. See for example the source code of ByteProcessor:

You won’t find a 2D array in the Java source of imagej/imagej1 to represent image data, if I am not mistaken.

The reason for using 1-dimensional array is because, in Java, processing these (i.e. iterating over the pixels) is much more performant than processing 2-dimensional or multi-dimensional arrays.

For ImageJ2 (which is included in the Fiji distribution, and is backed by ImgLib2 data structures), the internal representaion of an image varies depending on which type of Img implementation is used (from the javadoc):

  • ArrayImg

    This Img stores an image in a single linear array of basic types.

  • PlanarImg

    A NativeImg that stores data in an list of primitive arrays, one per image plane.
    The PlanarImg provides access to the underlying data arrays via the getPlane(int) method.

  • CellImg

    Img types that divide their underlying data into cells.

  • NTreeImg

    This is used for sparse data representations, e.g. sparse labelings; see this topic for some discussion.

For general information about ImgLib2, see also the publication:

ImgLib2 - generic image processing in Java


Dear Jan,

these are ways of realizing 2D arrays. But in fact we speak of an image matrix, independent of the way it is internally realized.

BTW, the advantage of 1D arrays over 2D arrays very much depends on the compiler/interpreter. But I must admit that I have no idea how the current Java-machines rank with this respect.

Thanks anyway for your detailed contribution


Please note that this is incorrect. For images, Matlab uses the same convention as ImageJ and other image processing tools:

For pixel indices, the row increases downward, while the column increases to the right. Pixel indices are integer values, and range from 1 to the length of the row or column.


Note however that the row and column counting are different. Matlab starts counting with 1, while ImageJ (and most programming languages) use 0-based indices for arrays as well as images.


Dear Jan,

my memory seems to vanish. What I had in mind was this thread on the list:

Because I never used Matlab I could not check it myself and so I wrote “AFAIK”. However, the above thread doesn’t actually state what I thought to remember.

Sorry for the confusion


Just for the record, here is another post
that deals with images in Matlab and ImageJ. It appears to conform with the list posts linked above.


Thank you very much guys. for this valuable discussion. I hope this will help lot of guys…!