function [X,map] = rawread(filename,n,m);
% RAWREAD Read a Portable Bitmap file, or a raw file.
% RAWREAD('imagefile.raw', xsize, ysize) reads a "raw" image file
% RAWREAD('imagefile.pgm') reads a "pgm" (portable gray map) image
% [X,map] = RAWREAD('imagefile.raw') returns both the image and a
% color map, so that
% [X,map] = rawread('imagefile.raw',sx,sy);
% or [X,map] = rawread('imagefile.pgm');
% image(X)
% colormap(map)
% will display the result with the proper colors.
%
% NOTE : map is optional and could be replaced during the display by
% the "colormap('gray')" command
%
% See also IMWRITE, IMREAD, IMAGE, COLORMAP.
dot = max(find(filename == '.'));
suffix = filename(dot+1:dot+3);
if strcmp(suffix,'pgm') | strcmp(suffix,'raw')
% disp(sprintf('\nopens %s file\n',filename));
fp = fopen(filename,'rb','b'); % "Big-endian" byte order.
if (fp<0)
error(['Cannot open ' filename '.']);
end
if strcmp(suffix,'pgm')
% Read and crack the header
head = fread(fp,2,'uchar'); % pgm magic number : P5
if ~strcmp(head,'P5'),
% fprintf(1,'\n Magic Number : %s\n',head);
else
% fprintf(1,'\n Bad Magic Number : %s\n',head);
error('cannot continue this way, good bye cruel world');
end
c = fread(fp,1,'uchar'); %reads the carriage return separating P5 from the creator
precreator = fread(fp,1,'uchar'); % look for a '#' character preceeding a creator signature
if precreator == '#',
c = setstr(20); % any character except carriage return
cr = setstr(10); % defines a carriage return
while c ~= cr,
c = fread(fp,1,'uchar');
creator = [creator,c];
end;
% fprintf(1,'\n creator : %s\n',creator);
else
% fprintf('\n No creator signature\n');
fseek(fp,-1,'cof'); % return one char before
end;
end
if nargin <2,
if strcmp(suffix,'raw')
% assume image size is 256x256
% disp('RAW file without size : assume image size is 256x256');
n = 256;
m = 256;
else % for PGM files
% reads the size and depth
% disp(' reads sizes');
n = fscanf(fp,'%d',1);
tn = num2str(n);
% disp([' xsize = ' tn]);
m = fscanf(fp,'%d',1);
tm = num2str(m);
% disp([' ysize = ' tm]);
p = fscanf(fp,'%d',1);
tp = num2str(p);
% disp([' depth = ' tp]);
c = fread(fp,1,'uchar'); %reads the last carriage return
end;
end
% Creates a gray palette and scale it to [0,1].
% disp(' create gray palette');
for i=1:256,
map(i,[1:3])=[i/256,i/256,i/256];
end;
% Read the image
% disp(' Reads image data ...');
[X,l] = fread(fp,[n,m],'uchar');
if l ~= m*n, l, error('HSI image file is wrong length'), end
% Image elements are colormap indices, so start at 1.
X = X'+1;
fclose(fp);
% disp('end');
else
error('Image file name must end in ''raw'' or ''pgm''.')
end
没有合适的资源?快使用搜索试试~ 我知道了~
GVF-snake.zip_SNAKE matlab 分割_matlab 医学_snake 医学_分割算法_医学matlab
共57个文件
m:39个
mat:10个
pgm:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 50 浏览量
2022-07-14
01:58:53
上传
评论 1
收藏 2.25MB ZIP 举报
温馨提示
基于matlab的医学图像GVF算法分割,主要实现对2D医学图像的分割
资源详情
资源评论
资源推荐
收起资源包目录
GVF-snake.zip (57个子文件)
图像分割(GVF snake)
toolbox
BoundMirrorExpand.m 699B
snakeindex.m 190B
BoundMirrorShrink.m 488B
xconv2.m 913B
snakeinterp1.m 1KB
gaussianMask.m 255B
gaussianBlur.m 500B
snakedeform2.m 2KB
dt.m 608B
snakeinterp.m 2KB
rawwrite.m 1KB
snakeinit.m 894B
snakedisp.m 551B
Contents.m 1KB
snakedeform.m 1KB
GVF.m 2KB
BoundMirrorEnsure.m 916B
rawread.m 3KB
imdisp.m 252B
images
heart.mat 934B
test_chest.mat 711KB
chest.mat 1KB
chest.pgm 46KB
heart1.mat 962B
heart.pgm 25KB
room.pgm 4KB
test_heart.mat 383KB
U64.pgm 4KB
new
BoundMirrorExpand.m 699B
snakeindex.m 186B
images
heart.mat 934B
test_chest.mat 711KB
chest.mat 1KB
chest.pgm 46KB
heart1.mat 962B
heart.pgm 25KB
room.pgm 4KB
test_heart.mat 383KB
U64.pgm 4KB
BoundMirrorShrink.m 488B
DETFchest.m 993B
VETF.m 290B
ISAF.m 458B
snakeinterp.m 805B
GVETF.m 372B
GVFchest.m 989B
ISAFchest.m 993B
snakedeform.m 1KB
GVF.m 510B
BoundMirrorEnsure.m 916B
rawread.m 2KB
chest.m 990B
GGVF.m 350B
GGVFchest.m 990B
imdisp.m 270B
heart.m 1KB
chest.m 1KB
共 57 条
- 1
Kinonoyomeo
- 粉丝: 72
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1