MATLAB Image Matrix Representation subscript

Source: Internet
Author: User

I am always used to C ++ programming. The sequence of access to three-dimensional image data is as follows: column, row, and layer. The symbols are X, Y, Z, I, J, and K.

This is also true for three-dimensional medical images.

For (INT z = 0; Z <nslice; Z ++)

For (INT y = 0; y <nheight, y ++)

For (INT x = 0; x <nwidth, X ++)


// Volume (z * nheight * nwidht + y * nwidht + x)



Of course, for common BMP images collected by CCD, two-dimensional, 768*576 (row * column), in order to cycle large layers, column loops are also available first.

For (int w = 0; W <nwidth; W ++)

For (INT h = 0; H <nheiht, H ++)


Pimage (H * nwidht + W)


In any case, C ++ stores data first.

But in MATLAB, it is the opposite ....

[H, w] = size (image ),
The first parameter is the row and the second parameter is the column. This applies to many cases (line,
Column. Remember not to reverse it.

I = zeros (H, W ),
It also produces H rows and W columns ....

The image matrix reads I (I, j), which is also the number of column J in row I.

I = rand (2, 4)

I =

0.8147 0.1270 0.6324 0.2785
0.9058 0.9134 0.0975 0.5469

> [H, w] = size (I)

H =


W =


In short, Matlab storage is first column storage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.