NuMRI/codes/MATLAB/load_dicom.m

126 lines
3.9 KiB
Mathematica
Raw Normal View History

2020-01-17 16:24:10 +01:00
clear all ; close all
% Load dicom
name = 'Ronald' ;
if strcmp(name, 'Ronald')
path_all = [
'/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190909_Ronald/FH/DICOM/IM_0001',
'/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190909_Ronald/AP/DICOM/IM_0001',
'/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190909_Ronald/RL/DICOM/IM_0001'
] ;
end
if strcmp(name, 'Jeremias')
path_all = [
'/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190909_Jeremias/FH/DICOM/IM_0001',
'/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190909_Jeremias/AP/DICOM/IM_0001',
'/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190909_Jeremias/RL/DICOM/IM_0001'
] ;
end
if strcmp(name, 'Hugo')
path_all = [
'/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190924_Hugo/Dicom/DICOM/IM_0013',
'/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190924_Hugo/Dicom/DICOM/IM_0009',
'/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190924_Hugo/Dicom/DICOM/IM_0005'
] ;
end
for i=1:3
if i==1
%path = '/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190924_Paloma/Dicom/DICOM/IM_0013'
disp('Reading the FH component from ...')
path = path_all(1,:)
end
if i==2
%path = '/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190924_Paloma/Dicom/DICOM/IM_0009' ;
disp('Reading the AP component from ...')
path = path_all(2,:)
end
if i==3
%path = '/home/yeye/Desktop/PhD/MEDICAL_DATA/DatosSEPT2019/20190924_Paloma/Dicom/DICOM/IM_0005' ;
disp('Reading the RL component from ...')
path = path_all(3,:)
end
I_info = dicominfo(path);
I = double(dicomread(path));
VENC = eval(['I_info.PerFrameFunctionalGroupsSequence.Item_1.MRVelocityEncodingSequence.Item_1.VelocityEncodingMaximumValue']) ;
heart_rate = eval(['I_info.PerFrameFunctionalGroupsSequence.Item_1.Private_2005_140f.Item_1.HeartRate']);
MAG = zeros(size(I,1),size(I,2),I_info.Private_2001_1018,I_info.Private_2001_1017);
PHASE = zeros(size(I,1),size(I,2),I_info.Private_2001_1018,I_info.Private_2001_1017);
for n=1:size(I,4)
RI = eval(['I_info.PerFrameFunctionalGroupsSequence.Item_',num2str(n),'.Private_2005_140f.Item_1.RescaleIntercept']); % intercept
RS = eval(['I_info.PerFrameFunctionalGroupsSequence.Item_',num2str(n),'.Private_2005_140f.Item_1.RescaleSlope']); % slope
cp = eval(['I_info.PerFrameFunctionalGroupsSequence.Item_',num2str(n),'.Private_2005_140f.Item_1.Private_2001_1008']); %cp
slc = eval(['I_info.PerFrameFunctionalGroupsSequence.Item_',num2str(n),'.Private_2005_140f.Item_1.Private_2001_100a']); %scl
id = eval(['I_info.PerFrameFunctionalGroupsSequence.Item_',num2str(n),'.Private_2005_140f.Item_1.Private_2005_106e']); % PCA o FFE
if strcmp(id,'FFE')==1
MAG(:,:,slc,cp) = I(:,:,1,n)*RS + RI;
else
PHASE(:,:,slc,cp) = I(:,:,1,n)*RS + RI;
end
end
MASK = double(abs((PHASE==PHASE(1,1,1,1))-1));
PHASE = PHASE.*MASK;
if i==1
MR_FFE_FH = MAG;
MR_PCA_FH = VENC*PHASE/pi/100;
end
if i==2
MR_FFE_AP = MAG;
MR_PCA_AP = VENC*PHASE/pi/100;
end
if i==3
MR_FFE_RL = MAG;
MR_PCA_RL = VENC*PHASE/pi/100;
end
end
disp('Saving the data ...')
spaceslices = eval(['I_info.PerFrameFunctionalGroupsSequence.Item_1.PixelMeasuresSequence.Item_1.SpacingBetweenSlices']);
pixelspacing = eval(['I_info.PerFrameFunctionalGroupsSequence.Item_1.PixelMeasuresSequence.Item_1.PixelSpacing']);
disp('voxel-size recognized:')
voxel_MR = [pixelspacing(1),pixelspacing(1),spaceslices]
data = [];
data.MR_FFE_AP = MR_FFE_AP;
data.MR_FFE_RL = MR_FFE_RL;
data.MR_FFE_FH = MR_FFE_FH;
data.MR_PCA_AP = MR_PCA_AP;
data.MR_PCA_RL = MR_PCA_RL;
data.MR_PCA_FH = MR_PCA_FH;
data.type = 'DAT';
data.VENC = VENC ;
data.voxel_MR = voxel_MR;
data.heart_rate = heart_rate;
save('/home/yeye/Desktop/data.mat','data','-v7.3');
disp('data saved')