[Top][All Lists]

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

printing from octave; loading images

From: Steve Mann
Subject: printing from octave; loading images
Date: Sat, 23 Dec 2000 18:56:31 -0500

I noticed that imread doesn't work right unless the image is a bmp,
so I wrote the following file "loadpnm.m" that might be of use to
others.  Please consider this GPL Version 2, if a "license" is needed
to distribute or use it.

I left in some lines (commented out) showing how I arrived at the
current embodiment.

Also, I noticed that there is no "print" or "gpp" command to print
the whatever figure is on the screen.

Although I could do a screen grab of the plot, it would be nicer
to have a Matlab-like "print" or "gpp" command to make a PostScript file
of a graph appearing on the screen, rather than using a poor resolution
bitmap screen capture.

Is there a print command in octave yet, or should I write that as well?

% loadpnm.m is based on an earlier cmex program I wrote for Matlab before
% it was able to deal with images -- address@hidden
% this crude implementation (quick hack) DOESNT PROPERLY HANDLE COMMENTS
% feel free to add that feature (fscanf past "#" signs up to "ŠÜn")
function [R G B]=loadpnm(filename)
[fp err]=fopen(filename,"r");
magicnumber=fscanf(fp, "P%d",1); %
[imagesize]=fscanf(fp, "%d %d",2); % must pass number of arguments wanted or
                                   % keeps reading and may read into image if
                                   % pixel values are in range of ascii numbers

%carriagereturnisagarbagebyte=fscanf(fp, "ŠÜn",1);
%imagedepth=fscanf(fp, "%dŠÜn",1);
imagedepth=fscanf(fp, "%d",1);

M=imagesize(2); N=imagesize(1); % reversed convention
fprintf(stderr,"loadpnm: magic=%d;  M=%d, N=%d;  

if magicnumber == 5 % reading a pgm
  if nargoutŠþ=1
    error("magic number of a single output argument must now be P5; P7, P9, 
etc. not yet supported")
%%  [r mycount]=fread(fp,M*N,"uchar");
%  R=reshape(r,M,N);
%%  R=reshape(r,N,M).';
%  [R mycount]=fread(fp,[M N],"uchar");
%  [R mycount]=fread(fp,[N M],"uchar").';% can't transpose list
  R=fread(fp,[N M],"uchar").'; % must not read mycount!!!
if magicnumber == 6 % reading a ppm
  if nargoutŠþ=3
    error("magic number of a single output argument must now be P5; P7, P9, 
etc. not yet supported")
  [rgb mycountrgb]=fread(fp,3*M*N,"uchar");


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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