def _load(self): self.files = _get_files(self.file_dir, self.file_pattern) self.stack = dicomSeries.read_files(self.files, showProgress=True, readPixelData=True)[0] if HAS_GIAS: self._make_scan()
def main(): args = getArguments(getParser()) # prepare logger logger = Logger.getInstance() if args.debug: logger.setLevel(logging.DEBUG) elif args.verbose: logger.setLevel(logging.INFO) # load dicom slices [series] = pydicom_series.read_files( args.input, False, True) # second to not show progress bar, third to retrieve data #print series.sampling # Note: The first value is the mean of all differences between ImagePositionPatient-values of the DICOM slices - of course total bullshit data_3d = series.get_pixel_array() # check parameters if args.dimension >= data_3d.ndim or args.dimension < 0: raise ArgumentError( 'The image has only {} dimensions. The supplied target dimension {} exceeds this number.' .format(data_3d.ndim, args.dimension)) if not 0 == data_3d.shape[args.dimension] % args.offset: raise ArgumentError( 'The number of slices {} in the target dimension {} of the image shape {} is not dividable by the supplied number of consecutive slices {}.' .format(data_3d.shape[args.dimension], args.dimension, data_3d.shape, args.offset)) # prepare empty target volume volumes_3d = data_3d.shape[args.dimension] / args.offset shape_4d = list(data_3d.shape) shape_4d[args.dimension] = volumes_3d data_4d = scipy.zeros([args.offset] + shape_4d, dtype=data_3d.dtype) logger.debug( 'Separating {} slices into {} 3D volumes of thickness {}.'.format( data_3d.shape[args.dimension], volumes_3d, args.offset)) # iterate over 3D image and create sub volumes which are then added to the 4d volume for idx in range(args.offset): # collect the slices for sl in range(volumes_3d): idx_from = [slice(None), slice(None), slice(None)] idx_from[args.dimension] = slice(idx + sl * args.offset, idx + sl * args.offset + 1) idx_to = [slice(None), slice(None), slice(None)] idx_to[args.dimension] = slice(sl, sl + 1) #print 'Slice {} to {}.'.format(idx_from, idx_to) data_4d[idx][idx_to] = data_3d[idx_from] # flip dimensions such that the newly created is the last data_4d = scipy.swapaxes(data_4d, 0, 3) # save resulting 4D volume save(data_4d, args.output, False, args.force) logger.info("Successfully terminated.")
def get3DRecon(data, path): """ Performs 3D reconstruction from the given DICOM data, and returns a voxel array and the pixel spacing factors. """ global ConstPixelSpacing # del(data[0]) # RefDs = data[0] # ConstPixelSpacing = (float(RefDs.PixelSpacing[0]), float( # RefDs.PixelSpacing[1]), float(RefDs.SliceThickness)) series = pydicom_series.read_files( path, False, True) # second to not show progress bar, third to retrieve data # print len(series) voxel_ndarray = series[0].get_pixel_array() print voxel_ndarray.shape voxel_ndarray = series[1].get_pixel_array() print voxel_ndarray.shape voxel_ndarray = series[2].get_pixel_array() print voxel_ndarray.shape # print voxel_ndarray.shape # assert False, "Stop" # info = series[1].info # try: # voxel_ndarray, ijk_to_xyz = dicom_numpy.combine_slices(data) # except dicom_numpy.DicomImportException as e: # # Invalid DICOM data # print("Handling incompatible dicom slices") # # voxel_ndarray, ijk_to_xyz = dicom_numpy.combine_slices(data) # try: # # makeCompatible(data, prec=5) # voxel_ndarray, ijk_to_xyz = dicom_numpy.combine_slices(data) # except: # print("Handling incompatible dicom slices") # voxel_ndarray = [] # for i in range(len(data)): # # print data[i].pixel_array.shape # # assert False, "Stop Code" # voxel_ndarray.append(data[i].pixel_array) # voxel_ndarray = np.stack(voxel_ndarray, axis=2) # # multi_slice_viewer(voxel_ndarray) # # plt.show() # ijk_to_xyz = np.eye(4) sliceSpacing = abs(data[0].ImagePositionPatient[2] - data[1].ImagePositionPatient[2]) ConstPixelSpacing = [ sliceSpacing, data[0].PixelSpacing[0], data[0].PixelSpacing[1] ] return voxel_ndarray, ConstPixelSpacing
def main(): args = getArguments(getParser()) # prepare logger logger = Logger.getInstance() if args.debug: logger.setLevel(logging.DEBUG) elif args.verbose: logger.setLevel(logging.INFO) # load dicom slices [series] = pydicom_series.read_files(args.input, False, True) # second to not show progress bar, third to retrieve data #print series.sampling # Note: The first value is the mean of all differences between ImagePositionPatient-values of the DICOM slices - of course total bullshit data_3d = series.get_pixel_array() # check parameters if args.dimension >= data_3d.ndim or args.dimension < 0: raise ArgumentError('The image has only {} dimensions. The supplied target dimension {} exceeds this number.'.format( data_3d.ndim, args.dimension)) if not 0 == data_3d.shape[args.dimension] % args.offset: raise ArgumentError('The number of slices {} in the target dimension {} of the image shape {} is not dividable by the supplied number of consecutive slices {}.'.format( data_3d.shape[args.dimension], args.dimension, data_3d.shape, args.offset)) # prepare empty target volume volumes_3d = data_3d.shape[args.dimension] / args.offset shape_4d = list(data_3d.shape) shape_4d[args.dimension] = volumes_3d data_4d = scipy.zeros([args.offset] + shape_4d, dtype=data_3d.dtype) logger.debug('Separating {} slices into {} 3D volumes of thickness {}.'.format(data_3d.shape[args.dimension], volumes_3d, args.offset)) # iterate over 3D image and create sub volumes which are then added to the 4d volume for idx in range(args.offset): # collect the slices for sl in range(volumes_3d): idx_from = [slice(None), slice(None), slice(None)] idx_from[args.dimension] = slice(idx + sl * args.offset, idx + sl * args.offset + 1) idx_to = [slice(None), slice(None), slice(None)] idx_to[args.dimension] = slice(sl, sl+1) #print 'Slice {} to {}.'.format(idx_from, idx_to) data_4d[idx][idx_to] = data_3d[idx_from] # flip dimensions such that the newly created is the last data_4d = scipy.swapaxes(data_4d, 0, 3) # save resulting 4D volume save(data_4d, args.output, False, args.force) logger.info("Successfully terminated.")
def main(): args = getArguments(getParser()) # prepare logger logger = Logger.getInstance() if args.debug: logger.setLevel(logging.DEBUG) elif args.verbose: logger.setLevel(logging.INFO) # load input slices [series] = pydicom_series.read_files(args.input, False, True) # second to not show progress bar, third to retrieve data data_input = series.get_pixel_array() if args.spacing: print '{} {}'.format(*series.info.PixelSpacing) return 0 logger.debug('Resulting shape is {}.'.format(data_input.shape)) # save resulting volume save(data_input, args.output, False, args.force) logger.info("Successfully terminated.")