#include "itkImage.h" #include "itkGDCMImageIO.h" #include "itkGDCMSeriesFileNames.h" #include "itkImageSeriesReader.h" #include "itkImageFileWriter. GetOutput ()) print ( "Writing: " + outFileName ) writer. join ( dirName, seriesIdentifier + ".nrrd" ) if args. ForceOrthogonalDirectionOff () writer = itk. GetFileNames ( seriesIdentifier ) reader = itk. series_name seriesFound = True print ( "Reading: " + seriesIdentifier ) fileNames = namesGenerator. exit ( 1 ) print ( "The directory: " + dirName ) print ( "Contains the following DICOM Series: " ) for uid in seriesUID : print ( uid ) seriesFound = False for uid in seriesUID : seriesIdentifier = uid if args. GetSeriesUIDs () if len ( seriesUID ) < 1 : print ( "No DICOMs in: " + dirName ) sys. SetDirectory ( dirName ) seriesUID = namesGenerator. SetGlobalWarningDisplay ( False ) namesGenerator. import SimpleITK as sitk mhd sitk.ReadImage (filename) origin mhd.GetOrigin () spacing mhd.GetSpacing () direction mhd. mhd file) but the only way I found to do it is to call ReadImage which is pretty slow as it loads the whole array into memory. AddSeriesRestriction ( "0008|0021" ) namesGenerator. Sometimes I need to access only the metadata (which is stored in a keyvalue. SetUseSeriesDetails ( True ) namesGenerator. ctype ( "signed short" ) Dimension = 3 ImageType = itk. parse_args () # current directory by default dirName = "." if args. add_argument ( "series_name", nargs = "?" ) args = parser. add_argument ( "output_image", nargs = "?" ) parser. add_argument ( "dicom_directory", nargs = "?", help = "If DicomDirectory is not specified, current directory is used", ) parser. ArgumentParser ( description = "Read DICOM Series And Write 3D Image." ) parser. When using the default settings for the ImageFileReader class or the ReadImage function you have minimal control over the reading. You can call EraseMetaData to remove the extraneous/redundant tags.#!/usr/bin/env python import sys import os import itk import argparse parser = argparse. With ITK, when an image if filtered the meta-data tags are not propagated, the this issue is not frequently encountered. The software is available from the 5 MATLAB Central File Exchange, and the most up-to-date version can be 6 downloaded from the public GitLab repository. I’m guessing that the itk::NifTiImageIO reader is trying to do something “smart” with the NifTi tags to preserve them. This paper describes the Medical Image Processing Toolbox for MAT- LAB (MIPROT), an open source, free software aiming at facilitating research and development with medical images. (sform_code_name) = "NIFTI_XFORM_UNKNOWN" (qform_code_name) = "NIFTI_XFORM_SCANNER_ANAT" datadirectory directory seriesIDs (datadirectory) if not seriesIDs: print ('ERROR: given directory \''+datadirectory+'\' does not contain a DICOM series.') sys. I did a test with NifTi and there were quite a lot of NifTi tags: In : import SimpleITK as sitk First obtain the series file names using the image series reader. When you first read an image in ITK, the Image may contain additional meta data tags from the reader. Print('\nGetImageFromArray, written with ITK') Nib.Nifti1Image(array, affine).to_filename(filepath_nib) With gzip.open(image_path, 'rb') as f_in: With NamedTemporaryFile(suffix='.nii') as f: mha file with a standard stream in byte mode, fetch only the first part that correspond to the header (it should be of constant size. If you want to only read the metadata, I think you can read the. Here’s some code to show what I mean, and the output: import gzip Hi GabrieleBelotti, As far as I know there is no easy way to access these information without fully reading the volume through an ImageFileReader. If I read and write and image with SimpleITK, the header is incorrect. When I create an image using GetImageFromArray, the written header is fine. qfac is the first value of the pixdim array in the header and is expected to be -1 or 1. NIfTI docs say that it “should not occur” that qfac is 0. I’m using SimpleITK 1.2.4 to read and write NIfTI images.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |