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.
Best
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.
Best
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.
Regards
Herbie
Thank you very much.
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):
This
Img
stores an image in a single linear array of basic types.
A
NativeImg
that stores data in an list of primitive arrays, one per image plane.
ThePlanarImg
provides access to the underlying data arrays via the getPlane(int) method.
Img
types that divide their underlying data into cells.
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
https://doi.org/10.1093/bioinformatics/bts543
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
Herbie
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.
See https://www.mathworks.com/help/images/image-coordinate-systems.html
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:
http://imagej.1557.x6.nabble.com/Problem-with-ImageJ-and-Matlab-image-analysis-td5019978.html
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
Herbie
PS:
Just for the record, here is another post
http://forum.image.sc/t/convert-imagelib-image-to-matlab-and-vice-versa/5232/5?u=herbie
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â€¦!