m by 1 array of uint8 data to image

I want to display an image from my device. Currently i can read in the image using binblockread of type unit8 and print the image to a fie using fwrite and it displays fine.
However, I would like to display the image in MATLAB first for a user prompt i'm developing. The array is read into MATLAB as an m by 1 array ranging from 0 to 255. I have tried imshow, imagesc, and image. As well as playing with the different parameters but nothing wants to take.
Perhaps someone could help. I have attached the array I am reading into to matlab. THis is the same array i'm using to print to my .gif file.

5 Comments

Jason - you didn't attach your array file. Once you have chosen the file, you must press the Attach File button.
Is the data being read already in image file format? You mention it looking fine when you fwrite it, and fwrite does not add image file headers, suggesting that the data is already an image file.
If the data is already an image file, really the easiest thing to do is write it to disk and read it with imread() if you want to display it.
Hey Geoff, Sorry about that. I think you're right, I just forgot to click Attach File. It's attached now.
Hey Walter, I don't know enough about file formats, but I think your right. I think it is in image format and that's why I am able to fwrite it so easily. I am pulling a screen shot from my spectrum analyzer and the screenshot is already a .gif file.
I have included my code that performs this action below. My hope was to use the array to display the image before I write anything to the disk. But that may be the route I need to go.
Thanks so much guys.
sccap=binblockread(g,'uint8'); % g is my GPIB Object
fid=fopen('test.gif','w+');
fwrite(fid,sccap,'uint8');
Looking at that code, Yes, what you are receiving must already be in image file format. If you were to hunt around long enough you could probably find a Java or library that could accept an array of bytes that is the image file data, and which would decode the image file data into the pixel arrays so that you could display them... but it would be easier to write the file and read it with imread()
Hey Walter,
Thanks for the quick response. Yes I went ahead and did as you suggested. It is actually a fine solution. I don't see the delay or issues I was concerned about. Thanks so much.
I guess cause this was a comment I can't "accept" your answer. But I certainly do appreciate it. Thank you.
-Jason

Sign in to comment.

 Accepted Answer

Looking at that code, Yes, what you are receiving must already be in image file format. If you were to hunt around long enough you could probably find a Java or library that could accept an array of bytes that is the image file data, and which would decode the image file data into the pixel arrays so that you could display them... but it would be easier to write the file and read it with imread()

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!