Octave function to read raster image file PBM

I tried to create structure for 2D simulation using image raster, with image format PBM. What I did was to use GIMP and fortunately, GIMP is able to save onto PBM directly. Otherwise we would need netpbm to convert the image file.

You can open PBM image file and it will contain 0 or 1 depending on the color whether it is black or white. Now to open this PBM file in your octave and save it as an array is very simple. You simply use imfinfo and imread functions.

When you do

pbninfo=imfinfo('filename.pbm')

this will show you the information of the image file include the size of the pixels which is very useful (it will be the size of the matrix as well).

Now to read the image file simply type

data=imread('filename.pbm');

voila!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: