Re: Convert image to binary file



"Hgbreton Hughes" <abc@xxxxxxxxx> writes:

Hi. I'm trying to use Matlab to convert a black and white
image into a sting of bits which can then be used as the
input to an artificial neural network. I have the code
below, but when I execute it the output file is blank.

BW = imread('image1.bmp');
fid = fopen('exp.txt', 'w');
count = fwrite(fid, BW);
fclose(fid);

Does anyone know what I am doing wrong? I need the matrix
to be read line by line into a string of bits with a space
between each bit. e.g. for a 2*2 image with a white pixel
in the top left hand corner the output should be 1 0 0 0.

If you want exp.txt to actually be a text file, then fwrite is the wrong
command, and in addition you need to open the file in text mode, for
correct line ending handling:

fopen('exp.txt', 'wt')

As it is, exp.txt is probably a binary file, which has a misleading
extension.

-Peter
.



Relevant Pages

  • parallel of "locate"
    ... is there something parallel to Linux "locate filename" ... (the command which finds files locations in linux) ...
    (comp.unix.solaris)
  • Re: Escaping Square Brackets in Sed
    ... Sting wrote: ... I'm looking at modifying a line in sendmail's submit.mc file using ... The command I use is: ... PS I'm no sed expert. ...
    (comp.unix.shell)