how to convert a cell array into an image?

44 views (last 30 days)
I fetched an image from sql database but its returning format is like i=[75839 int8] how can i convert it into image plz help me out

Accepted Answer

Guillaume on 5 Oct 2014
If the bytes you get are truly a jpg image, you may be able to decode it with java:
jimage =;
height = jimage.getHeight;
width = jimage.getWidth;
pixels = reshape(typecast(jimage.getData.getDataStorage, 'uint8'), [3,width,height]);
img = cat(3, ...
transpose(reshape(pixels(3,:,:), [width,height])), ...
transpose(reshape(pixels(2,:,:), [width,height])), ...
transpose(reshape(pixels(1,:,:), [width,height])));

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 4 Oct 2014
Edited: Image Analyst on 4 Oct 2014
You need to take the (badly-named) i and reshape it into a 2 or 3D array, but you need to know the number of rows and columns.
cellContents = cell2mat(i); % Convert from cell to double.
grayImage = reshape(cellContents, [rows, columns]);
imshow(grayImage, []);
kanwal on 6 Oct 2014
yeah u r right it was png. but its not decoding

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!