如何从脑网重新定位原始图像的轴心轴

时间:2015-08-13 14:02:49

标签: matlab image-processing matrix computer-vision

我有一张原始图像,其中包含

等信息
image dimensions: zspace yspace xspace
    dimension name         length         step        start
    --------------         ------         ----        -----
    zspace                    181            1          -72
    yspace                    217            1         -126
    xspace                    181            1          -90

应解释如下:

the file scans the 3D image volume such that the 'X' coordinate changes fastest, and the 'Z' changes slowest.
the image sizes along the X-Y-Z axes are 181x217x181 voxels (pixels).
the voxel sizes along the X-Y-Z axes are 1x1x1 mm.

每个体素使用一个(无符号)字节,并对数据进行缩放,使其使用整个0 ... 255范围的值。

目前,我使用下面的代码来读取该原始文件。它可以读取原始图像并显示为右图。但是,它看起来不像我的预期结果,其中图像重新定向为轴心轴。

你能帮我解决一下Matlab代码吗?

filepath=strcat('t1_icbm_normal_1mm_pn5_rf20.rawb');
fid = fopen(filepath,'r');    
rima=zeros(dim(1:3));
for z=1:dim(3),    
  rima(:,:,z) = fread(fid,dim(1:2),'uchar');  
end;
fclose(fid);
imshow(rima(:,:,91),[]); %% Show slice 91th

enter image description here

参考链接为http://brainweb.bic.mni.mcgill.ca/about_data_formats.html。 输入文件可以从herebrainweb

下载

1 个答案:

答案 0 :(得分:2)

之所以如此,是因为当MATLAB读入数据时,它会将数据置于列主要顺序。这意味着您通过行读取的数据将放在列中。因此,外观会使您的图像旋转90度并反射。

一个简单的解决方案是采用矩阵并单独转置每个切片。对permute的简单调用应该可以解决问题:

rima = permute(rima, [2 1 3]);

上面的代码在矩阵的每个切片上交换第二个和第一个维度,有效地独立地执行每个切片的转置。我也注意到,当你这样做时,水平轴上会有一个反射。拨打flipdim来解决此问题:

rima = flipdim(permute(rima, [2 1 3]), 1);

要重现,我已下载文件并在我的计算机上运行代码。我在permuteflipdim之前和之后显示第91个切片:

filepath=strcat('t1_icbm_normal_1mm_pn5_rf20.rawb');
fid = fopen(filepath,'r'); 
dim = [181 217 281]; %// Added for code to run   
rima=zeros(dim(1:3));
for z=1:dim(3),    
  rima(:,:,z) = fread(fid,dim(1:2),'uchar');  
end;
fclose(fid);
imshow(rima(:,:,91),[]); %% Show slice 91th

%// New - Permute dimensions and flip rows
rima = flipdim(permute(rima, [2 1 3]), 1);
figure;
imshow(rima(:,:,91),[]); %%// Show corrected slice

以下是我们之前和之后的结果:

enter image description here

enter image description here