How can i get viewable jpeg image from hex file ???

2 views (last 30 days)
Hi all, i captured image with camera on arduino and i send it to PC over Xbee, I get a file wich contain "FF D8 FF E0 00 .. .. .. .. D4 FF D9 " , now i want to reconstruct the original image, how can i proceed ??

Accepted Answer

Walter Roberson
Walter Roberson on 1 Jul 2016
YourFilename = 'AppropriateFileName.txt';
converted_file = uint8( sscanf( fileread(YourFileName) , '%2x') );
Now you should reshape() converted_file to have the appropriate number of rows and columns and color planes.
Depending on the order in which the values were sent, you might need to use permute() to rearrange the data into a color array suitable for displaying.
  3 Comments
Walter Roberson
Walter Roberson on 1 Jul 2016
You are being sent the content of a JPEG file, not the image data directly.
fid = fopen('AppropriateFileName.jpg', 'w');
fwrite(fid, converted_file, 'uint8');
fclose(fid);
Now you can examine the contents with any convenient image viewer, or you can
YourImage = imread('AppropriateFileName.jpg');
Looking at the image, it appears that you were sent a partial version of lena.jpg with most of it missing.
Chandler Timm Doloriel
Chandler Timm Doloriel on 30 Mar 2022
Edited: Chandler Timm Doloriel on 30 Mar 2022
@Walter Roberson This may be super late. But how can I do the same without using fopen, fwrite, fclose?
After it reads the converted_file ,it should show the RGB888 values without using fopen, fwrite, fclose? Is there other way?

Sign in to comment.

More Answers (1)

bejaoui sawssen
bejaoui sawssen on 13 Jul 2016
Hello, Thanks for the response. I have another question i would applicate an algorithme of face recognition to my image then if the result is positive i return 1 else 0. My goal is to do all of this automatically witout intervention : arduinosend image to matlab , matlab do the recognition and then return 1 or 0 to arduino. I would like to wait until the whole image be recieved than i complete the next but right now i dont do it 100% automatically , my code is divided in two sections . Can you help me to de this 100% automatically ?? Thanks
  1 Comment
Walter Roberson
Walter Roberson on 13 Jul 2016
I have no assistance to offer for the facial recognition part.
For the transmission of the file, there are various ways. If you have a perfectly reliable transfer mechanism then the easiest way is to first send a count of the number of bytes in the file and then send the bytes. Or always send the same number of bytes. If you do not have a perfectly reliable transfer mechanism then there have been a lot of different ways developed over the years, including XModem, YModel, ZModem, Kermit; or running using the serial line to run an IP protocol layer by using SLIP or PPP, and then using something like rcp or ftp over top of that.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!