1

This is a follow-up question to another SO question of mine.

I have a large array of 8 bit binary values that I want to convert back to uint8.

I have used Amro's lookupTable solution from the previous question. Now I want to do the reverse. I wanted to do a lookup table but sadly I am unable to.

What I managed to do is the following:

temp = ones([(TotalPixel),1], 'uint8');

for iter2 = 1 : TotalPixel,
     temp(iter2,1) = sum(Data(iter2,1:8).*2.^(7:-1:0));   
end 

But the for loop is too slow as it takes 2 seconds to convert a [76800 x 1] array. Is there a better/faster way to do this?

1 Answer 1

3

Try this:

temp = uint8(Data*(2.^(7:-1:0))');

Note that this answer is basically the same as an edit I made to an answer I gave to a previous question you asked. You had asked there about just converting a single row of 12-bit values, but I had added an extra discussion of how you would extend it to converting multiple values at once using a matrix multiply. The difference between that answer and this is simply the number of bits and the inclusion of UINT8 to change the variable type.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.