I am getting an RGB matrix from a microprocessor that outputs an image in RGB565 format. I want to read this into MATLAB, convert it to RGB24 format, and output the image. How do I do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You first have to read your data from the text file into a matrix in MATLAB. Since I don’t know what format your text file is in, I can only suggest that you will probably need to use the function
fscanfto read in all of your values (probably of typeuint16), then you will likely have to reshape the values into an N-by-M image matrix using the functionreshape.Let’s assume you’ve done all that, and you now have an N-by-M matrix
imgof unsigned 16-bit integers. First, you can use the functionbitandto extract the bits for the red, green, and blue components, whose positions in the 16-bit integer are illustrated here:Next, you can use the function
bitshiftand multiplication by a scale factor to scale the red, green, and blue values to a range of 0 to 255, then convert them to an unsigned 8-bit integer using the functionuint8. This will give you three color component matrices the same size asimg:Now you can use the function
catto put the three color components into an N-by-M-by-3 RGB image matrix, then save the image to an RGB24 bitmap file using the functionimwrite:EXAMPLE:
Using a randomly generated 100-by-100 matrix of uint16 values and applying the above conversions, here are the results: