How to convert xml file to RT Struct

9 visualizaciones (últimos 30 días)
mohd akmal masud
mohd akmal masud el 5 de Jun. de 2025
Comentada: mohd akmal masud el 17 de Jun. de 2025
Dear Expert,
I have xml file (xml folder) that I done contouring on that file. The original file also I have as attached. Both file can get here: https://drive.google.com/drive/folders/1GkDmQO9M5vZlQ4WIGsvpZoPlo1taRmTJ?usp=sharing or as attached.
Anyone can help me to convert xml file to RT Struct.
Please help me

Respuestas (1)

Deepak
Deepak el 17 de Jun. de 2025
I understand that you are looking to convert contour data from an XML file (exported by HybridViewer) into a DICOM RT Structure Set (RT Struct) using MATLAB. The XML file contains multiple VOIs (structures), each with 2D contours defined at specific Z-slices. You can extract these contours in MATLAB using "xmlread", and match the Z-values with the slices in the reference DICOM image using metadata from "dicominfo".
Below is a sample MATLAB code to achieve the same:
info = dicominfo('original_file.dcm'); % Load DICOM metadata
doc = xmlread('contours.xml'); % Read the XML
cont = dicomContours(info); % Create contour container
vois = doc.getElementsByTagName('voi');
for i = 0:vois.getLength-1
voi = vois.item(i);
name = char(voi.getElementsByTagName('title').item(0).getTextContent());
rois = voi.getElementsByTagName('roi');
for j = 0:rois.getLength-1
coords = rois.item(j).getElementsByTagName('coordinate');
pts = zeros(coords.getLength, 3);
for k = 0:coords.getLength-1
c = coords.item(k);
pts(k+1,1) = str2double(c.getElementsByTagName('x').item(0).getTextContent());
pts(k+1,2) = str2double(c.getElementsByTagName('y').item(0).getTextContent());
pts(k+1,3) = str2double(c.getElementsByTagName('z').item(0).getTextContent());
end
cont = addContour(cont, i+1, name, pts, 'CLOSED_PLANAR', [255;0;0]);
end
end
infoRT = convertToInfo(cont); % Create RT Struct metadata
dicomwrite([], 'RTSTRUCT.dcm', infoRT, 'CreateMode','copy');
This will generate a valid RTSTRUCT.dcm file, compatible with radiotherapy planning systems, from your XML and DICOM inputs.
Please find attached documentation of functions used for reference:
I hope this helps.
  1 comentario
mohd akmal masud
mohd akmal masud el 17 de Jun. de 2025
Dear @Deepak,
The error pop up when for this line:
>> cont = dicomContours(info); % Create contour container
Error using dicomContours>validateMetadata (line 201)
Invalid SOPClassUID for DICOM-RT Structure Set.
Error in dicomContours (line 17)
validateMetadata(metadata, obj.Dictionary);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by