Convert an Image to a binary (.bin) file

13 vues (au cours des 30 derniers jours)
Dimitris M
Dimitris M le 16 Sep 2013
Hello
I am trying to convert an image to a binary file (not binary image) for further processing in another software. I have tried the following code but does not seems to work as the file I am creating is zero bytes !
I= imread('cameraman.bin','w')
fid=fopen ('cameraman.bin','w');
fwrite(fid,I,'float32');
Can someone advice me on how to do this correctly ?
Thank you

Réponse acceptée

Image Analyst
Image Analyst le 16 Sep 2013
As far as I know there is no defined format for .bin. It's like .raw - you can basically define it however you want. You need to find out what format that other software package wants.

Plus de réponses (1)

David Sanchez
David Sanchez le 16 Sep 2013
Try this out:
I= imread('cameraman.tif');
level = .5;
BW = im2bw(I, level);
%choose your own options when writing to txt file
dlmwrite('myfile.txt', BW)
dlmwrite('myfile.txt', BW, 'delimiter', '\t', 'precision', 6)
  2 commentaires
Dimitris M
Dimitris M le 16 Sep 2013
Hello
I am not sure exactly what is the outcome of the process ! I am trying to open the text file after creating it and it seems to be non-readable!
Is this a binary file as well ? What it the difference when compared with bin files ?
Thanks again for your time
Image Analyst
Image Analyst le 16 Sep 2013
He said he didn't want a binary image anyway.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by