Reputation: 541
I really dont have much experience with matlab, so please excuse me, if this is a stupid question: I have Width*Height*3 Matrix, of uint16 values, which holds an Image, now I need to have a look on the Byte representation. To make clear what i want a little example, if it was 1x1x3 matrix, with the values 0x1234, 0x5678, and 0xABCD, i would want an array containing 6 uint8-Values: 0x12, 0x34, 0x56, 0x78, 0xAB, and 0xCD. So that i can get a correct histogram of it with 256 Bins, which shows me exactly which bytes occure how often.
Ofcourse i could go through the whole matrix and calculate the 2byte values of each uint16, but with my next-to-nothing matlab knowledge I would use 2 for-loops and some bit-shifting which would result in awful performance
Greetings Uzaku
Upvotes: 0
Views: 35
Reputation: 36710
I would not switch to a binary or hexal representation, in Matlab these representations are chars and not very useful for further calculation. I would use this:
first_bits=M./2^8
last_bits=mod(M,2^8)
It might be useful to put both together into a 4d-matrix
M2=cat(4,first_bits,last_bits)
First three dimension as known, last index either 1 for the first 8 bits or 2 for the last 8 bits.
Upvotes: 1