前言: 在医学图像处理中,数据保存可以是raw数据格式,即里面都是纯像素数据,mhd则是关于非图像像素的数据,可以用记事本打开,以下打开一个mhd文件格式,其中内容如下: ObjectType = Image NDims = 3 BinaryData = True BinaryDataByteOrderMSB = False CompressedData = False TransformMatrix = 1 0 0 0 1 0 0 0 1 Offset = 0 0 0 CenterOfRotation = 0 0 0 ElementSpacing = 0.585938 0.585938 0.625 DimSize = 512 512 10 AnatomicalOrientation = ??? ElementType = MET_SHORT ElementDataFile = 4.raw
打开matlab,键入以下代码:
id = fopen('4.raw'); img = fread(id,'short');%以'short'数据类型打开,因为本人存储的raw数据是以short保存的 imgsize = size(img);%读出的图像的size为n*1大小 rows = 512;%根据mhd文件的图像大小设定 clos =512; nums = imgsize(1)/rows/clos; %计算得到图像张数 img = reshape(img,[rows,clos,nums]); single_image = reshape(img(:,:,3),[rows,clos]);%显示第3张 single_show = uint8(single_image);%转化为uint8显示 imshow(single_show)