필터 지우기
필터 지우기

Way around using rasread with a uint 16 sun raster file

조회 수: 4 (최근 30일)
Benjamin
Benjamin 2012년 6월 27일
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에서 Elementary Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by