Batch creation of mrml scenes

I have a series of 3D ultrasounds that I converted to mhd+raw files.

I want to automate the creation of mrml scenes for all my files (> 500 files), to make it easier to visualize by others.

Goal: import mhd+raw -> save as .mrml

Is there any script I can use/adapt?

Thank you,
Mariana

1 Like

These examples in the script repository should help:

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Load_volume_from_file

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Save_the_scene_into_a_single_MRB_file

source_dir='C:\\mhddir\\'
for parent, dirnames, filenames in os.walk(source_dir):
    for filename in filenames:
        mhdfile = os.path.join(parent, filename)
        if mhdfile.endswith(".mhd"):
            [success, mhdNode] = slicer.util.loadVolume(mhdfile, returnNode=True)

sceneSaveFilename ="c:\\test.mrb"
slicer.util.saveScene(sceneSaveFilename)

I haven’t tested this code
I don’t know if I understand what you mean