[Index for tmp_for_tar/imgio]
[Return to Master Index]
readimagefile
(tmp_for_tar/imgio/readimagefile.m)
Function Synopsis
[im, isPpm, maxval] = readimagefile (fname, force_gray)
Help text
[im, isPpm, maxval] = readimagefile(fname, force_gray)
fname : string : name of image file.
force_gray : flag : (opt) if true, the returned image is a gray level
image, even if the file contained a color image.
(default: false)
im : matrix : an image. Note, that if force_gray == false, the
image might by a PPM representation of the image.
isPpm : flag : 1 : `im' is in PPM format.
0 : `im' is a graylevel matrix.
maxval : int : Maximum luminosity level (usually 255)
See also: readpnm, readfi, readjpg, readgif, splitppm.
readimagefile Read an image file of any supported image format.
The currently supported formats are:
PGM/PPM (both ascii and binary), FI, JFIF, IMG and GIF.
Created: August 1998
Modified: June 2000 by Etienne Grossmann <etienne@isr.ist.utl.pt>
Accepts GIF and IMG (octave's image format. indexed IMG's are
converted to gray or rgb)
Version: 1.0
Listing of function file tmp_for_tar/imgio/readimagefile.m
## [im, isPpm, maxval] = readimagefile(fname, force_gray)
##
## fname : string : name of image file.
## force_gray : flag : (opt) if true, the returned image is a gray level
## image, even if the file contained a color image.
## (default: false)
## im : matrix : an image. Note, that if force_gray == false, the
## image might by a PPM representation of the image.
## isPpm : flag : 1 : `im' is in PPM format.
## 0 : `im' is a graylevel matrix.
## maxval : int : Maximum luminosity level (usually 255)
##
## See also: readpnm, readfi, readjpg, readgif, splitppm.
##
## readimagefile Read an image file of any supported image format.
## The currently supported formats are:
## PGM/PPM (both ascii and binary), FI, JFIF, IMG and GIF.
##
## Copyright (C) 1998 Ariel Tankus
##
## This program is free software.
## This file is part of the Image Processing Toolbox for Octave
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
## Author: Ariel Tankus <arielt@math.tau.ac.il>
## Created: August 1998
## Modified: June 2000 by Etienne Grossmann <etienne@isr.ist.utl.pt>
## Accepts GIF and IMG (octave's image format. indexed IMG's are
## converted to gray or rgb)
## Version: 1.0
function [im, isPpm, maxval] = readimagefile (fname, force_gray)
if (nargin < 2)
force_gray = 0;
end
fname = file_in_path(IMAGEPATH, fname);
if isempty (fname),
error ("readimagefile : Can't find file '%s'",fname);
## im = [];
## isPpm = 0;
## return
end
[fid, magicnum] = getmagicnum(fname);
fclose(fid);
if (strcmp(magicnum, "P2") | strcmp(magicnum, "P5"))
## PGM
[im,isPpm,maxval] = readpnm(fname);
elseif (strcmp(magicnum, "P3") | strcmp(magicnum, "P6"))
## PPM
[im,isPpm,maxval] = readpnm(fname);
if (nargout > 1)
isPpm = 1;
end
# jpeg
elseif (strcmp(magicnum, "ÿØ"))
[im, isPpm,maxval] = readjpg(fname);
elseif (strcmp(magicnum, "FI"))
im = readfi(fname);
maxval = 0 ;
isPpm = 0 ;
elseif (strcmp(magicnum, "GI"))
## error("Probably a GIF file. Currently not supported.");
[im,isPpm,maxval] = readgif (fname);
# Probably IMG
elseif (strcmp(magicnum, "# "))
[im,map] = loadimage (fname);
# Gray
if all ((map(:,1)==map(:,2)) & (map(:,1)==map(:,3)) ),
isPpm = 0 ;
else
isPpm = 1;
end
# # Gray
# if all ( (map(:,1)==map(:,2)) & (map(:,1)==map(:,3)) ),
# im = ind2gray (im, map);
# isPpm = 0 ;
# else # Rgb
# [R,G,B] = ind2rgb (im, map);
# im = reshape ([R;G;B], rows(R), 3*columns(R)) ;
# isPpm = 1 ;
# end
# maxval = 1 ;
# jpeg
else
error("Unknow file type encountered.");
end
if isPpm && force_gray,
[r,g,b] = splitppm(im);
im = (r + g + b) / 3;
isPpm = 0 ;
end
endfunction
Produced by oct2html on Sat Sep 14 9:47:03 2002
Cross-Directory links are: ON