How to convert xml file to RT Struct
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Deepak
le 17 Juin 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:
dicomContours: www.mathworks.com/help/images/ref/dicomcontours.html
I hope this helps.
1 commentaire
Voir également
Catégories
En savoir plus sur Read and Write Image Data from Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!