Accessing a MIL buffer directly

If needed, a MIL buffer’s contents can be accessed directly. For instance, if you want to calculate the average value of the pixels of your image, you could create a custom algorithm. The algorithm could be applied directly to the buffer without having to copy the contents of the MIL buffer into a user-allocated array (MbufAlloc…()) by using MbufGet() and MbufPut(). To do so would be more efficient and might improve the performance of the custom algorithm.

In order to access the MIL buffer directly, the buffer’s address and pitch must be known. Once you know this, you will be able to access them directly for optimum performance.

사용자 삽입 이미지

The address of a parent or child buffer can be returned using MbufInquire(). Selecting M_HOST_ADDRESS will return a logical address, while M_PHYSICAL_ADDRESS will return a physical address. In either case, the first address of the buffer you are specifying will be the top left-most pixel in the image. Knowing the pitch and the depth of the buffer will tell you the address of the following row.

The pitch of a buffer is the number of units between the beginnings of any two adjacent lines of the buffer’s data and can be measured in pixels or bytes. Note that in some instances, the pitch in bytes will be more accurate than in pixels. If the last pixel falls outside of a 32-bit boundary (required by Windows), the start of the next row will be located at the beginning of the next 32-bit boundary; this process is called internal padding. When measuring the pitch in pixels, the padding can be counted as “extra” pixels, depending on the depth of the pixels. This will result in an inaccurate pitch.


Hello, I'm Dr.kchris, a neuroscience researcher. I love studying and trying new things and also love challenging myself. Have a great day! :)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.