如何将 Dicom 目录(一系列 dicom 图像)转换为 3D 体积图像?
How can I convert Dicom directory (series of dicom images) to 3D volume image?
我在一个文件夹中有将近 80 张 dicom 图像。现在,我想将这些系列的 dicom 图像转换为 3d 体积。
下面是加载 MRI 数据、形成计数器切片然后生成 3d 体积的代码。但是,它会加载内置的 MRI 图像。
如何更改此程序以从我的文件夹加载 dicom 图像并显示 3d 体积?
load mri
D = squeeze(D);
%figure
colormap(map)
image_num = 8;
image(D(:,:,image_num))
axis image
x = xlim;
y = ylim;
cm = brighten(jet(length(map)),-.5);
figure
colormap(cm)
contourslice(D,[],[],image_num)
axis ij
xlim(x)
ylim(y)
daspect([1,1,1])
figure
colormap(cm)
contourslice(D,[],[],[1,12,19,27],8);
view(3);
axis tight
figure
colormap(map)
Ds = smooth3(D);
hiso = patch(isosurface(Ds,5),...
'FaceColor',[1,.75,.65],...
'EdgeColor','none');
isonormals(Ds,hiso)
hcap = patch(isocaps(D,5),...
'FaceColor','interp',...
'EdgeColor','none');
view(35,30)
axis tight
daspect([1,1,.4])
lightangle(45,30);
lighting gouraud
hcap.AmbientStrength = 0.6;
hiso.SpecularColorReflectance = 0;
hiso.SpecularExponent = 50;
我们可以使用 fullfile
其中 returns 包含文件完整路径的字符串。和 dir
其中 returns 与字符串名称匹配的文件和文件夹列表。当 name 是文件夹时,dir 列出文件夹的内容。使用绝对或相对路径名指定名称。名称可以包含通配符 (*)。
其余的东西在程序中都有很好的评论。
clear all;
close all;
clc;
fileFolder = fullfile('series 9');
files = dir ( fullfile (fileFolder, '*.dcm'));
fileNames = {files.name};
%examine file header (metadata , from dicom stack)
info = dicominfo(fullfile(fileFolder,fileNames{1}));
%extract size info from metadata
voxel_size = [info.PixelSpacing;info.SliceThickness];
%read one file to get size
I = dicomread(fullfile(fileFolder,fileNames{1}));
classI = class(I);
sizeI = size(I);
numImages = length(fileNames);
%read slice images populate 3d matrix
hWaitBar = waitbar(0,'reading dicom files');
%create array
mri= zeros(sizeI(1),sizeI(2), numImages , classI );
for i=length(fileNames):-1:1
fname = fullfile(fileFolder, fileNames{i});
mri(:,:,i) = uint16(dicomread(fname));
waitbar((length(fileNames)-i+1)/length(fileNames))
end
delete(hWaitBar);
我在一个文件夹中有将近 80 张 dicom 图像。现在,我想将这些系列的 dicom 图像转换为 3d 体积。
下面是加载 MRI 数据、形成计数器切片然后生成 3d 体积的代码。但是,它会加载内置的 MRI 图像。
如何更改此程序以从我的文件夹加载 dicom 图像并显示 3d 体积?
load mri
D = squeeze(D);
%figure
colormap(map)
image_num = 8;
image(D(:,:,image_num))
axis image
x = xlim;
y = ylim;
cm = brighten(jet(length(map)),-.5);
figure
colormap(cm)
contourslice(D,[],[],image_num)
axis ij
xlim(x)
ylim(y)
daspect([1,1,1])
figure
colormap(cm)
contourslice(D,[],[],[1,12,19,27],8);
view(3);
axis tight
figure
colormap(map)
Ds = smooth3(D);
hiso = patch(isosurface(Ds,5),...
'FaceColor',[1,.75,.65],...
'EdgeColor','none');
isonormals(Ds,hiso)
hcap = patch(isocaps(D,5),...
'FaceColor','interp',...
'EdgeColor','none');
view(35,30)
axis tight
daspect([1,1,.4])
lightangle(45,30);
lighting gouraud
hcap.AmbientStrength = 0.6;
hiso.SpecularColorReflectance = 0;
hiso.SpecularExponent = 50;
我们可以使用 fullfile
其中 returns 包含文件完整路径的字符串。和 dir
其中 returns 与字符串名称匹配的文件和文件夹列表。当 name 是文件夹时,dir 列出文件夹的内容。使用绝对或相对路径名指定名称。名称可以包含通配符 (*)。
其余的东西在程序中都有很好的评论。
clear all;
close all;
clc;
fileFolder = fullfile('series 9');
files = dir ( fullfile (fileFolder, '*.dcm'));
fileNames = {files.name};
%examine file header (metadata , from dicom stack)
info = dicominfo(fullfile(fileFolder,fileNames{1}));
%extract size info from metadata
voxel_size = [info.PixelSpacing;info.SliceThickness];
%read one file to get size
I = dicomread(fullfile(fileFolder,fileNames{1}));
classI = class(I);
sizeI = size(I);
numImages = length(fileNames);
%read slice images populate 3d matrix
hWaitBar = waitbar(0,'reading dicom files');
%create array
mri= zeros(sizeI(1),sizeI(2), numImages , classI );
for i=length(fileNames):-1:1
fname = fullfile(fileFolder, fileNames{i});
mri(:,:,i) = uint16(dicomread(fname));
waitbar((length(fileNames)-i+1)/length(fileNames))
end
delete(hWaitBar);