def _load_single_file(self, file_path, loader, dtype=np.float32): image_data = SpatialImage2D._load_single_file( file_path, loader, dtype) if self.spatial_rank < 3: return image_data if self.original_axcodes[0] and self.output_axcodes[0]: image_data = misc.do_reorientation( image_data, self.original_axcodes[0], self.output_axcodes[0]) if self.original_pixdim[0] and self.output_pixdim[0]: # verbose: warning when interpolate_order>1 for integers image_data = misc.do_resampling(image_data, self.original_pixdim[0], self.output_pixdim[0], self.interp_order[0]) return image_data
def _load_single_5d(self, idx=0): if len(self._file_path) > 1: # 3D image from multiple 2d files raise NotImplementedError # assuming len(self._file_path) == 1 image_obj = misc.load_image(self.file_path[idx]) image_data = image_obj.get_data() image_data = misc.expand_to_5d(image_data) assert image_data.shape[3] == 1, "time sequences not supported" if self.original_axcodes[idx] and self.output_axcodes[idx]: output_image = [] for t_pt in range(image_data.shape[3]): mod_list = [] for mod in range(image_data.shape[4]): spatial_slice = image_data[..., t_pt:t_pt + 1, mod:mod + 1] spatial_slice = misc.do_reorientation( spatial_slice, self.original_axcodes[idx], self.output_axcodes[idx]) mod_list.append(spatial_slice) output_image.append(np.concatenate(mod_list, axis=4)) image_data = np.concatenate(output_image, axis=3) if self.original_pixdim[idx] and self.output_pixdim[idx]: assert len(self._original_pixdim[idx]) == \ len(self.output_pixdim[idx]), \ "wrong pixdim format original {} output {}".format( self._original_pixdim[idx], self.output_pixdim[idx]) # verbose: warning when interpolate_order>1 for integers output_image = [] for t_pt in range(image_data.shape[3]): mod_list = [] for mod in range(image_data.shape[4]): spatial_slice = image_data[..., t_pt:t_pt + 1, mod:mod + 1] spatial_slice = misc.do_resampling( spatial_slice, self.original_pixdim[idx], self.output_pixdim[idx], self.interp_order[idx]) mod_list.append(spatial_slice) output_image.append(np.concatenate(mod_list, axis=4)) image_data = np.concatenate(output_image, axis=3) return image_data
def get_data(self): if len(self._file_path) > 1: # 3D image from multiple 2d files raise NotImplementedError # assuming len(self._file_path) == 1 image_obj = misc.load_image(self.file_path[0]) image_data = image_obj.get_data() image_data = misc.expand_to_5d(image_data) if self.original_axcodes[0] and self.output_axcodes[0]: image_data = misc.do_reorientation( image_data, self.original_axcodes[0], self.output_axcodes[0]) if self.original_pixdim[0] and self.output_pixdim[0]: # verbose: warning when interpolate_order>1 for integers image_data = misc.do_resampling(image_data, self.original_pixdim[0], self.output_pixdim[0], self.interp_order[0]) return image_data
def _load_single_file(self, file_path, loader, dtype=np.float32): image_data = SpatialImage2D._load_single_file(file_path, loader, dtype) if self.spatial_rank < 3: return image_data pixdim = self.original_pixdim[0] if self.original_axcodes[0] and self.output_axcodes[0]: image_data = misc.do_reorientation(image_data, self.original_axcodes[0], self.output_axcodes[0]) transf, _, _ = misc.compute_orientation(self.output_axcodes[0], self.original_axcodes[0]) if pixdim: pixdim = tuple(pixdim[k] for k in transf[:, 0].astype(np.int)) if pixdim and self.output_pixdim[0]: # verbose: warning when interpolate_order>1 for integers image_data = misc.do_resampling(image_data, pixdim, self.output_pixdim[0], self.interp_order[0]) return image_data
def get_data(self): if len(self._file_path) > 1: # 3D image from multiple 2d files mod_list = [] for mod in range(len(self.file_path)): mod_2d = SpatialImage2D( file_path=(self.file_path[mod], ), name=(self.name[mod], ), interp_order=(self.interp_order[mod], ), output_pixdim=(self.output_pixdim[mod], ), output_axcodes=(self.output_axcodes[mod], ), loader=(self.loader[mod], )) mod_data_5d = mod_2d.get_data() mod_list.append(mod_data_5d) try: image_data = np.concatenate(mod_list, axis=4) except ValueError: tf.logging.fatal( "multi-modal data shapes not consistent -- trying to " "concat {}.".format([mod.shape for mod in mod_list])) raise return image_data # assuming len(self._file_path) == 1 image_obj = load_image_from_file(self.file_path[0], self.loader[0]) image_data = image_obj.get_data() image_data = misc.expand_to_5d(image_data) if self.original_axcodes[0] and self.output_axcodes[0]: image_data = misc.do_reorientation(image_data, self.original_axcodes[0], self.output_axcodes[0]) if self.original_pixdim[0] and self.output_pixdim[0]: # verbose: warning when interpolate_order>1 for integers image_data = misc.do_resampling(image_data, self.original_pixdim[0], self.output_pixdim[0], self.interp_order[0]) return image_data