Way around using rasread with a uint 16 sun raster file

1 次查看(过去 30 天)
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 个评论
Benjamin
Benjamin 2012-6-27
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

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2012-6-27
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 个评论
Walter Roberson
Walter Roberson 2012-6-28
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 2012-6-28
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by