[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BMP loading

From: A+A Adler
Subject: Re: BMP loading
Date: Thu, 16 Sep 1999 21:36:18 -0400 (EDT)

On 16 Sep 1999, Bostjan JERKO wrote:
> Anybody know of possibility to load BMP image in octave to get image
> data as matrix ?

Try this

   fid= popen('bmptoppm /path/to/file.bmp','r');
   strcmp( fgetl(fid),'P6') || error('bailing');
   [wid,len]=sscanf( fgetl(fid) , '%d %d' , 'C');
   data=  reshape( fread(fid), 3,  wid* len );
   red=   reshape( data(1,:), wid, len)';
   green= reshape( data(2,:), wid, len)';
   blue = reshape( data(3,:), wid, len)';


1. This has almost no error checking
2. This has not been debugged
3. You need to be on UNIX with the libgr tools installed
4. I've build a proper imread/imwrite functionality that
   will do this, I should be able to contribute it soon
   to octave-sources
Andy Adler,                               address@hidden

Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see
Instructions for unsubscribing:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]