The dicom files can be correctly recognized as multiple components image by ITK-SNAP
:
The proof is : I can change the component/view of the dicom file:
But when I extract nii.gz file from the dicom series, the views/components are concatenated together, just like:
Are there any problems of my python code? Could you help me to extract the nii.gz file from the dicom series by a correct way?
here is my python code:
def read_dicom(src_dir, out_dir):
if not os.path.exists(out_dir):
os.mkdir(out_dir)
PixelType = itk.ctype("signed short")
Dimension = 3
ImageType = itk.Image[PixelType, Dimension]
namesGenerator = itk.GDCMSeriesFileNames.New()
namesGenerator.SetUseSeriesDetails(True)
namesGenerator.SetGlobalWarningDisplay(False)
namesGenerator.SetDirectory(src_dir)
seriesUID = namesGenerator.GetSeriesUIDs()
if len(seriesUID) < 1:
print("No DICOMs in: " + src_dir)
sys.exit(1)
for uid in seriesUID:
seriesIdentifier = uid
fileNames = namesGenerator.GetFileNames(seriesIdentifier)
reader = itk.ImageSeriesReader[ImageType].New()
dicomIO = itk.GDCMImageIO.New()
dicomIO.LoadPrivateTagsOn()
reader.SetImageIO(dicomIO)
reader.SetFileNames(fileNames)
reader.ForceOrthogonalDirectionOff()
image = reader.GetOutput()
print("IMage Size: ", image.GetLargestPossibleRegion().GetSize())
writer = itk.ImageFileWriter[ImageType].New()
writer.SetFileName("./results.nii.gz")
writer.UseCompressionOn()
writer.SetInput(image)
writer.Update()
Thanks for your help!!! Please!!!