如何重新定位为来自 brainweb 的原始图像的轴
How to reorientation as axial axis of raw image from brainweb
我有一张原始图像,其中包含
等信息
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
参考 link 是 http://brainweb.bic.mni.mcgill.ca/about_data_formats.html 。
输入文件可以从here or brainweb
下载
原因是因为当MATLAB读入数据时,它将数据按列主顺序放置。这意味着您通过行读取的数据被放置在列中。因此,这具有将您的图像旋转 90 度并反射出来的外观运行。
一个简单的解决方案是采用矩阵并运行单独放置每个切片。只需调用 permute
即可解决问题:
rima = permute(rima, [2 1 3]);
以上代码在矩阵的每个切片上交换第二维和第一维,有效地独立执行每个切片的 t运行spose。我还注意到,当您这样做时,水平轴上会出现反射。致电 flipdim
解决此问题:
rima = flipdim(permute(rima, [2 1 3]), 1);
为了重现,我已经在我的电脑上下载了文件和 运行 代码。我在 permute
和 flipdim
:
之前和之后显示第 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
这是我们得到的之前和之后的结果:
我有一张原始图像,其中包含
等信息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
参考 link 是 http://brainweb.bic.mni.mcgill.ca/about_data_formats.html 。 输入文件可以从here or brainweb
下载原因是因为当MATLAB读入数据时,它将数据按列主顺序放置。这意味着您通过行读取的数据被放置在列中。因此,这具有将您的图像旋转 90 度并反射出来的外观运行。
一个简单的解决方案是采用矩阵并运行单独放置每个切片。只需调用 permute
即可解决问题:
rima = permute(rima, [2 1 3]);
以上代码在矩阵的每个切片上交换第二维和第一维,有效地独立执行每个切片的 t运行spose。我还注意到,当您这样做时,水平轴上会出现反射。致电 flipdim
解决此问题:
rima = flipdim(permute(rima, [2 1 3]), 1);
为了重现,我已经在我的电脑上下载了文件和 运行 代码。我在 permute
和 flipdim
:
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
这是我们得到的之前和之后的结果: