[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
tv.m and tvs.m
From: |
Steve Mann |
Subject: |
tv.m and tvs.m |
Date: |
Sat, 23 Dec 2000 19:10:25 -0500 |
because imshow doesn't work for color images in octave,
here's a simple script i wrote that might be of use, since it's
a quick hack to display color images in octave (feel free to
use and consider GPL version 2 if desired).
i'll still be now working on a way to print from octave, unless
someone else has already come up with a quick hack to print form
octave.
% tv.m based on a Matlab cmex program I wrote to display images in Matlab,
% although this is a quick hack (e.g. tempfiles, system() to image viewer).
% inspired by pv-wave's "tv" command -- address@hidden
function tv(r,g,b);
fd = fopen("deleteme_deleteme.pnm","w"); % tempfile
[Mr Nr]=size(r);
if nargin==1
fprintf(fd,"P5Ün");
fprintf(fd,"%d %dÜn",Nr,Mr);
fprintf(fd,"255Ün");
% clip values beyond 255 to 255
r=round(max(min(r,255),0));
fwrite(fd,r',"uchar");
else%if
[Mg Ng]=size(g);
[Mb Nb]=size(b);
if (Mr==Mg) & (Mr==Mb) & (Nr==Ng) & (Nr==Nb)
M=Mr; N=Nr; % all the same
fprintf(fd,"P6Ün")
fprintf(fd,"%d %dÜn",N,M);
fprintf(fd,"255Ün")
% clip values beyond 255 to 255
r=round(max(min(r,255),0));
g=round(max(min(g,255),0));
b=round(max(min(b,255),0));
r = reshape(r',1,M*N);
g = reshape(g',1,M*N);
b = reshape(b',1,M*N);
fwrite(fd,[r;g;b],"uchar");
else%if
error("tvs.m: images must be same size")
end%if
end%if
fclose(fd);
system("xv deleteme_deleteme.pnm &");
and here's a front end for it that emulates pv-wave's "tvscl" function:
% tvs.m scaled version of tv()
% inspired by pv-wave function tvscl
function tvs(r,g,b);
[Mr Nr]=size(r);
if nargin==1
maxr=max(max(r));
minr=min(min(r));
r=round(255.0*(r-minr)/(maxr-minr));
tv(r);
else%if
maxr=max(max(r)); minr=min(min(r)); r=round(255.0*(r-minr)/(maxr-minr));
maxg=max(max(g)); ming=min(min(g)); g=round(255.0*(g-ming)/(maxg-ming));
maxb=max(max(b)); minb=min(min(b)); b=round(255.0*(b-minb)/(maxb-minb));
tv(r,g,b);
end%if
-------------------------------------------------------------
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
-------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- tv.m and tvs.m,
Steve Mann <=