

But I agree that it would be better if you got a more clear indication of error, such as returning an error code or throw an exception. Not creating a file at all is a robust way of indicating that something went wrong and SimpleITK may also log errors or set error codes somewhere. You need to generate new UIDs for some fields, while cross-referencing existing UIDs in other fields.


You need to provide lots of required metadata to have a chance of generating a valid DICOM file. And if I am doing something wrong, then I feel that I at least deserve some kind of notice like: “ERROR: We disabled writing DICOM because !”.Ĭreation of valid DICOM files is very complex and not done very often.

Overall, this is a very frustrating situation, because I had written a script that outputs DICOM files using SimpleITK (I am converting some MHDs to DICOM for further processing), and since SimpleITK is a part of Slicer, I assumed that I could run it in Slicer. ShNode.SetItemParent(volumeShItemID, studyItemID)Įxporter = DICOMScalarVolumePlugin.DICOMScalarVolumePluginClass()Įxportables = exporter.examineForExport(volumeShItemID) VolumeShItemID = shNode.GetItemByDataNode(volumeNode) StudyItemID = shNode.CreateStudyItem(patientItemID, "test study") PatientItemID = shNode.CreateSubjectItem(shNode.GetSceneItemID(), "test patient") # Create patient and study and put the volume under the study The only script example for exporting an image as DICOM is this, which starts with object types I don’t recognize and uses a bunch of functionality I was hoping to avoid: volumeNode = getNode("CTChest")
ITK METAIMAGE TO DICOM SERIES
mhd/.raw file pair to a DICOM series (I have the tags stored separately)?Ĭan someone please consider adding an error message to be printed when SimpleITK.WriteImage() fails? Is there a good way to export a SimpleITK image object as DICOM from Slicer? Or more generally to convert an. Has anyone else used SimpleITK ImageFileWriter/WriteImage to write DICOM files from Slicer scripts? Is there a way to fix the problem? Now I am afraid I will have to rewrite the script in order to use Slicer’s internal DICOM modules, which will require a few days of reading, probably.
ITK METAIMAGE TO DICOM INSTALL
The script works perfectly on my laptop with a standalone SimpleITK library, but on my work desktop I cannot install standalone SimpleITK (ugh) so I thought I would try to run it inside of Slicer, which I am allowed to install. And if I am doing something wrong, then I feel that I at least deserve some kind of notice like: “ERROR: We disabled writing DICOM because !”. # using sitk.ImageFileWriter().Execute() gives the same behavior, incidentally Sitk.WriteImage(slices, "C:\\Users\\username\\test\\0000.dcm") # does nothing, gives no error message, just does nothing Sitk.WriteImage(slices, "C:\\Users\\username\\test\\0000.nrrd") # works fine Sitk.WriteImage(slices, "C:\\Users\\username\\test\\0000.mhd") # works fine save (save_path + '/' + str (i ) + '.Here’s what’s happening (at the Slicer Python console): import SimpleITK as sitk fromarray (scan ) #Here is the extracted image data Make_dir (save_path ) for i in range (scan. shape ) #Image size print ( 'spacing: ', spacing ) #interval print ( '# slice: ', len (scan ) ) #Number of slices #plot_ct_scan(scan) GetArrayFromImage (data ) print ( 'scan.shape' ,scan. join (root ,path ) ) #Read mhd file #print(data) Plot = plots if num_row = 1 else plots ĭata =sitk. subplots (num_row, num_column, figsize = (num_column * 5, num_row * 5 ) ) for i in range ( 0, num_row *num_column ) : Num_row = (num_slices //jump + num_column - 1 ) // num_columnį, plots = plt. makedirs (save_path ) #Integrate all pictures of a patient into one picture and print it out def plot_ct_scan (scan, num_column = 4, jump = 1 ) : #Create empty directory def make_dir (save_path ) : if not os. #Get the name of the subfolder in the file def get_file_name (filename ) : for root, dirs, files in os. My data storage is roughly as follows E:/105casesMask_Seg is the total data folder, the Cxxx folder stores the mhd files of each patient, the file name is equivalent to the patient_name later #Import the required package import os
