Way around using rasread with a uint 16 sun raster file

So I downloaded the PNM tool box from the file exchange, which included rasread. I'm trying to read in and display sun raster files but when I try to use the program, i get this error message: "invalid bitdepth: 16". Is there a way to convert the sun raster file to not be uint 16 or is there a way to modify the program?

1 comentario

Benjamin
Benjamin el 27 de Jun. de 2012
using info = imfinfo(file_name)
I'm able to get:
info =
Filename: [1x131 char]
FileModDate: '21-Apr-2011 11:58:30'
FileSize: 46432544
Format: 'RAS'
FormatVersion: []
Width: 3552
Height: 6536
BitDepth: 16
ColorType: 'indexed'
FormatSignature: 1.5041e+009
Length: 46431744
Type: 1
MapType: 1
MapLength: 768
If this helps at all

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Jun. de 2012
I am not able to find any documentation that supports the possibility of 16 bits per pixel for Sun raster files. The values I can find documented are 1, 8, 24, and 32. See http://www.fileformat.info/format/sunraster/egff.htm . Note that this is the total number of bits per pixel including all channels.

4 comentarios

Benjamin
Benjamin el 27 de Jun. de 2012
Yeah, that's what I was afraid of. And if I remember correctly, those values (1, 8, 24, and 32) are the ones listed for RAS files in IMREAD() as well. Thanks Walter
Benjamin
Benjamin el 27 de Jun. de 2012
Do you think there would be a way to read the RAS file in as binary and display it from there?
I would think it likely that the existing program could be modified. That isn't something I have time to look at this week.
Walter, So i found this function randomly which is different from rasread, but when i use it, i get this error: Not a SUN raster file. When clearly i do in fact have sun raster files.
% function [X,map]=rastread(filename);
%RASTREAD Read a BMP SUN raster file
% [X,MAP]=RASTREAD('filename') reads the file
% 'filename' and returns the indexed image X and
% associated colormap MAP. If no extension is given
% for the filename, the extension '.rast' is assumed.
%
% See also: BMPREAD, BMPWRITE, GIFREAD, HDFREAD,
% PCXREAD, TIFFREAD, XWDREAD.
% Jeffery J. Faneuff March 29, 1994
% Copyright (c) 1994 by The MathWorks, Inc.
if nargin~=1 | isstr(filename)~=1
error('Requires a string filename as an argument.');
end;
if (isempty(findstr(filename,'.'))==1)
filename=[filename,'.ras'];
end;
fid=fopen(filename,'rb','l');
if (fid==-1)
disp('The file should have an extension of .ras ');
error(['Error opening ',filename,'.']);
end;
magicnum=fread(fid,1,'uint32');
if (magicnum~= hex2dec('59a66a95'))
fclose(fid);
error('Not a SUN raster file.');
end;
width = fread(fid,1,'uint32');
height = fread(fid,1,'uint32');
depth = fread(fid,1,'uint32');
length = fread(fid,1,'uint32');
type = fread(fid,1,'uint32');
maptype = fread(fid,1,'uint32');
maplength = fread(fid,1,'uint32');
if (type~=1)
fclose(fid);
error('Not a standard encoded SUN raster file. ');
end;
if (maptype==1)
rawmap = fread(fid,maplength,'uchar');
map = reshape(rawmap,maplength/3,3); % make a Nx3
% colormap
map = map./255; % normalize
% to 255
end
X = fread(fid,[width, height],'uchar');
fclose(fid);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by