MATLAB: How to convert image (bmp,jpg….) to .bin file

write image to .bin file

I have a colour image and I want convert it to binary such as .bin (without losing color). In C code, I can easly use 'fopen' but it can't work in matlab. Anybody help me please.
Sorry my E is not good.

Best Answer

dao - if you have read the image from file (as a bmp or jpg) using imread, then you can use fopen and fwrite to write the data to a binary file. For example,
% read the image from file
myImage = imread('someImage.jpg');
% open a file to write to
fid = fopen('myBin.bin','w+');
if fid>0
% write the data to file
fwrite(fid,myImage,'uint8');
% close the file
fclose(fid);
end
In the above, we read in some image and open a file for writing (using w+ to indicate that we wish to open or create a new file for writing). It is assumed that the data type for the image is uint8 so we use that in our precision field of the fwrite function.