matlab读取raw文件

读文件

clc;clear all;
id = fopen('file.raw','r');
A = fread(id,'uint16');
imgsize = size(A);%读出的图像的size为n*1大小
rows = 512;%根据mhd文件的图像大小设定
clos =512;
nums = imgsize(1)/rows/clos; %计算得到图像张数
I = reshape(A,[rows,clos,nums]);
single_image = reshape(I(:,:,2),[rows,clos]);%显示第3张
B=uint16(single_image);%转化为unit8显示
B=B';%求图像
imtool(B);

循环读文件,判断数字是几位数字

for i = 0:730
   temp = num2str(i);
   if(length(temp) == 1)
       str1 = ['000',temp];
   elseif(length(temp) == 2)
       str1 = ['00',temp];
    elseif(length(temp) == 3)
       str1 = ['0',temp];
   end

    root = [obj_root,'\',str1,'.raw'];
    fileID = fopen(root,'r');
    A = fread(fileID,'uint16');
    fclose(fileID);
    rows = Slice;%根据mhd文件的图像大小设定
    clos = Detector_num;
    imgsize = size(A,1);%读出的图像的size为n*1大小
    single_image = reshape(A,[rows,clos]);
% %     single_image = reshape(A,[clos,rows]); wrong
% %     imtool(single_image);
    obj_I_120kv(i+1,:,:) = single_image;
end
  • 6
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值