8-bit image data

112 views
Skip to first unread message

Eric

unread,
Nov 23, 2016, 12:55:17 PM11/23/16
to ArrayFire Users
I'm creating a MEX version of a Matlab algorithm.  I have a number of sizable images collected from an instrument.  The raw data files are uint8 grayscale. The total amount of memory from all images in a data set is about 0.5 GB, so I'd like to transfer them to/from the device as uint8 if possible.  What's the best way to work with data that is in a uint8_t array? It seems the smallest integer supported by ArrayFire is u16 in which case I'm doubling my memory requirement.  Any thoughts are appreciated.

Thanks,
Eric

Shehzan Mohammed

unread,
Nov 23, 2016, 1:00:13 PM11/23/16
to ArrayFire Users
Hi Eric

You can load images as uint8 (u8/uchar in ArrayFire) using the loadImageNative function. With this function, the image is loaded as is and there are no changes made to the data (as opposed to the loadImage function which always returns floats).
All functions that support u32/u16 will also support u8 types. When using certain functions like reductions etc, since there may be a need for a larger number, u32 type arrays may be returned for some functions.
Is there any specific function that support u32/u16 but not u8 that you have found?

-Shehzan

Eric

unread,
Nov 23, 2016, 1:13:51 PM11/23/16
to ArrayFire Users
I was trying to work with the data that's already in Matlab rather than the native data files.  I can get them into C++ as uint8_t arrays but am not sure how to transfer them to the device that way.  Right now I'm assuming they're passed as uint16 instead. It's not the end of the world, but I was looking for a way to keep the memory transfer to a minimum.

You bring up a good point, though.  My images are all from BMP files that ArrayFire could load rather than Matlab. I'll think about if I can re-write my code to do that.  I was originally trying to write a single MEX function to work as a drop-in replacement for a Matlab class member function. When this function is called the data are already in memory, having been loaded by the class constructor.  The more elegant solution, which I will probably get to at some point, would be to re-write the entire class in C++. I've written my Matlab code with an eye to doing that at some point, but right now I'm just trying to bite off a smaller chunk. This function is relatively slow in Matlab but will be rather fast in ArrayFire.

Thanks,
Eric

Shehzan Mohammed

unread,
Nov 23, 2016, 1:18:41 PM11/23/16
to ArrayFire Users
I'm not sure why you say the array's are being created as u16. If the type is uchar, then the array type will also be uchar.
An example:
unsigned char hA[] ={1, 2, 3, 4};
af
:array A(4, hA); // Like every other array created from host data
printf
("%d\n", A.getType()); // Should be 7 according to https://github.com/arrayfire/arrayfire/blob/devel/include/af/defines.h#L203

-Shehzan

Pavan Yalamanchili

unread,
Nov 23, 2016, 1:18:42 PM11/23/16
to Eric, ArrayFire Users

Hi Eric arrayfire supports 8 bit integers. You just need to cast uint8 pointers  to unsigned char pointers. The relevant arrayfire data type is u8.


--
You received this message because you are subscribed to the Google Groups "ArrayFire Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arrayfire-use...@googlegroups.com.
To post to this group, send email to arrayfi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/arrayfire-users/ed13da28-a16d-4ea6-9ede-a5056095b03e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric

unread,
Nov 23, 2016, 1:21:01 PM11/23/16
to ArrayFire Users
So I actually looked at the link you provided for loadImageNative and it references a u8 data type.  I had been looking at the "Supported Data Types" section of the "Getting Started" page which does not list this data type. So my question was probably rather confusing.  ArrayFire does indeed support u8, which is exactly what I need.

I also forgot to answer your other question: I'm just starting out and haven't found anything that does not currently support u8.

Thanks again,
Eric

Shehzan Mohammed

unread,
Nov 23, 2016, 1:22:24 PM11/23/16
to ArrayFire Users
Right, I saw that too as I was answering. We'll have if fixed in the documentation.
Reply all
Reply to author
Forward
0 new messages