Converting 4D- Dynamic Contrast Enhanced MRI (DCE-MRI) MATLAB Data into DICOM

20 views (last 30 days)
With the following code I try to convert the matlab data into dicom data. The data was converted into dicom but when I want to visualize this dicom data in another software environment such as : MITK ( a software like 3D Slicer) it is showing only 1 axial slice amd only 1 time point. Though I have 15 slice and 85 different timepoints in original.
so the original overall size is = 64x64x15x84 (rows x col x slice x timepoints )
in software the size is = 64x
% Load the .mat file
matFile = 'M132_D0_E25_dce.mat';
load(matFile); % Load the data from the .mat file
% Extract the 4D dynamic DCE MRI data
dceData = dce_struct.dceDyn;
% Get the dimensions of the 4D data
[rows, cols, slices, timePoints] = size(dceData);
% Define the DICOM output directory
outputDir = 'dicom_output';
if ~exist(outputDir, 'dir')
mkdir(outputDir);
end
% Normalize and scale the data for better quality before DICOM conversion
% Find the global minimum and maximum values in the 4D data
minValue = min(dceData(:)); % Global minimum
maxValue = max(dceData(:)); % Global maximum
% Normalize the data to a range of 0 to 4294967295 (for uint32)
dceDataScaled = (dceData - minValue) ./ (maxValue - minValue); % Normalize between 0 and 1
dceDataScaled = uint32(dceDataScaled * 4294967295); % Scale to full uint32 range
% Loop through time points (t), slices (z), and save each slice for each time point
for t = 1:timePoints % Loop over time points
for z = 1:slices % Loop over slices
% Create the DICOM filename, including time and slice information
dicomFileName = fullfile(outputDir, sprintf('time_%02d_slice_%03d.dcm', t, z));
% Extract the 2D slice data for the current time point and slice
sliceData = dceDataScaled(:,:,z,t); % Extract the 2D slice for this time and slice
% Write the current slice to a DICOM file
dicomwrite(dceDataScaled, dicomFileName);
end
end
disp('4D DICOM conversion completed with axial slices and time points saved.');
  1 Comment
Gayathri
Gayathri on 5 Sep 2024
I think you have mistakenly written
dicomwrite(dceDataScaled, dicomFileName);
instead of
dicomwrite(sliceData, dicomFileName);
This will help you solve the issue.

Sign in to comment.

Answers (0)

Categories

Find more on DICOM Format in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!