Way around using rasread with a uint 16 sun raster file

1 view (last 30 days)
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 Comment
Benjamin
Benjamin on 27 Jun 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

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 27 Jun 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 Comments
Walter Roberson
Walter Roberson on 28 Jun 2012
I would think it likely that the existing program could be modified. That isn't something I have time to look at this week.
Benjamin
Benjamin on 28 Jun 2012
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);

Sign in to comment.

More Answers (0)

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!