How to convert xml file to RT Struct

조회 수: 13 (최근 30일)
mohd akmal masud
mohd akmal masud 2025년 6월 5일
댓글: mohd akmal masud 2025년 6월 17일
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

답변 (1개)

Deepak
Deepak 2025년 6월 17일
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
mohd akmal masud
mohd akmal masud 2025년 6월 17일
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);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Read and Write Image Data from Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by