[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);
newlinegarbage=fread(fp,1,"uchar");
M=imagesize(2); N=imagesize(1); % reversed convention
fprintf(stderr,"loadpnm: magic=%d; M=%d, N=%d;
depth=%dÜn",magicnumber,M,N,imagedepth);
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")
end%if
%% [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!!!
end%if
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")
end%if
[rgb mycountrgb]=fread(fp,3*M*N,"uchar");
RGB=reshape(rgb,3,M*N);
R=reshape(RGB(1,:),N,M).';
G=reshape(RGB(2,:),N,M).';
B=reshape(RGB(3,:),N,M).';
end%if
fclose(fp);
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- printing from octave; loading images,
Steve Mann <=