MATLAB: How to read 12bit raw data faster

image processing

This is my way to read 12bit raw image file.
data = fread(p,[768,1024],'ubit12=>uint32',4,'l');
But it takes very long time, is there any other way to speed up the processing time?
Thanks!

Best Answer

You can read all 16 bits and set the upper 4 bits to zero:
data = fread(p, [768,1024], 'uint16');
b = uint32(rem(data, 4096));
I assume you can use the format 'uint16=>uint32' directly - please test if this is faster and if rem works on UINT32 arrays.