def test_read_3D(self): sp_img_inr = imread(data_path('time_0_cut.inr')) img_path_tiff = data_path('time_0_cut.tiff') imsave(img_path_tiff, sp_img_inr) sp_img_tiff = imread(img_path_tiff) self.assertDictEqual(sp_img_inr.get_metadata(), sp_img_tiff.get_metadata()) np.testing.assert_array_equal(sp_img_inr, sp_img_tiff)
# print the SpatialImage metadata print('Metadata :'), metadata # metadata modification metadata['filename'] = img_path # set the SpatialImage metadata, mutator sp_img.set_metadata(metadata) # print the SpatialImage metadata print('New metadata :'), sp_img.get_metadata() # get the SpatialImage voxelsize (list of floating numbers) vox = sp_img.get_voxelsize() # print the SpatialImage voxelsize print('Voxelsize :'), vox # voxelsize modification new_vox = [] # empty list for ind, val in enumerate(vox): new_vox.append(2.0*val) # set the SpatialImage voxelsize, mutator sp_img.set_voxelsize(new_vox) print('New voxelsize :'), sp_img.get_voxelsize() # output # filename res_name = 'example_input_output.tif' # SpatialImage to .tif format imsave(out_path+res_name, sp_img) # filename res_name = 'example_input_output.inr' # SpatialImage to .inr format imsave(out_path+res_name, sp_img)
# print the SpatialImage metadata print('Metadata :'), metadata # metadata modification metadata['filename'] = img_path # set the SpatialImage metadata, mutator sp_img.set_metadata(metadata) # print the SpatialImage metadata print('New metadata :'), sp_img.get_metadata() # get the SpatialImage voxelsize (list of floating numbers) vox = sp_img.get_voxelsize() # print the SpatialImage voxelsize print('Voxelsize :'), vox # voxelsize modification new_vox = [] # empty list for ind, val in enumerate(vox): new_vox.append(2.0 * val) # set the SpatialImage voxelsize, mutator sp_img.set_voxelsize(new_vox) print('New voxelsize :'), sp_img.get_voxelsize() # output # filename res_name = 'example_input_output.tif' # SpatialImage to .tif format imsave(out_path + res_name, sp_img) # filename res_name = 'example_input_output.inr' # SpatialImage to .inr format imsave(out_path + res_name, sp_img)
# time_1 is first the local reference image, # and becames the floating image # time_2 is the global reference image times = [0, 1, 2] # list of SpatialImage instances list_images = [imread(data_path('time_' + str(time) + '.inr')) for time in times] # Rigid registration along the whole sequence: # list_compo_trsf : list of transformations # list_res_img : list of resulting images # the primitive embeds an iterative registration list_compo_trsf, list_res_img = sequence_registration(list_images, method='sequence_rigid_registration') for ind, img in enumerate(list_res_img): # filenames res_name = ''.join(['example_seq_reg_rigid_', str(ind), '_', str(times[-1]), '.inr']) # SpatialImage to .inr format imsave(out_path+res_name, img) # Affine registration alog the whole sequence: list_compo_trsf, list_res_img = sequence_registration(list_images, method='sequence_affine_registration') for ind, img in enumerate(list_res_img): # filenames res_name = ''.join(['example_seq_reg_affine_', str(ind), '_', str(times[-1]), '.inr']) # SpatialImage to .inr format imsave(out_path+res_name, img)
] floating_img, reference_img = list_images[0], list_images[1] # Rigid registration: trsf_rig, res_rig = registration(floating_img, reference_img, method='rigid_registration') # display the spatial transformation (4x4 matrix): trsf_rig.c_display() # save the spatial transformation: res_name = 'example_trsf_rigid.trsf' # filename trsf_rig.write(out_path + res_name) # save the result image: res_name = 'example_reg_rigid_1_2.tif' # filename # SpatialImage to .tif format imsave(out_path + res_name, res_rig) # Affine registration: trsf_aff, res_aff = registration(floating_img, reference_img, method='affine_registration') res_name = 'example_reg_affine_1_2.tif' # filename # SpatialImage to .tif format imsave(out_path + res_name, res_aff) # Deformable registration: trsf_def, res_def = registration(floating_img, reference_img, method='deformable_registration') res_name = 'example_reg_deformable_1_2.tif' # filename # SpatialImage to .tif format
img = imread(data_path('time_' + str(val) + '_seg.inr')) # subimage extraction shape = img.get_shape() indices = [0,shape[0]-1,0,shape[1]-1,0,5] img = img.get_region(indices=indices) # remove small cells labels = np.unique(img).tolist() img = labels_post_processing(img, method='labels_erosion', radius=2) img[img==0] = np.min(labels) img = SpatialImage(img, voxelsize=img.get_voxelsize()) # save input labeled images res_name = 'example_track_time_' + str(val) + '_seg.inr' imsave(out_path+res_name, img) labels = np.unique(img).tolist() # list of labels back_id = np.min(labels) # background identifier back_id_list.append(back_id) labels.remove(back_id) # feature space computation obj_gf = GeometricalFeatures(img, label=labels) feature_space = obj_gf.compute_feature_space() segmentation_list.append(img), feature_space_list.append(feature_space) # temporal matching obj_tm = TemporalMatching(segmentation_list=segmentation_list, feature_space_list=feature_space_list, background_id_list=back_id_list)
for time in times] floating_img, reference_img = list_images[0], list_images[1] # Rigid registration: trsf_rig, res_rig = registration(floating_img, reference_img, method='rigid_registration') # display the spatial transformation (4x4 matrix): trsf_rig.c_display() # save the spatial transformation: res_name = 'example_trsf_rigid.trsf' # filename trsf_rig.write(out_path+res_name) # save the result image: res_name = 'example_reg_rigid_1_2.tif' # filename # SpatialImage to .tif format imsave(out_path+res_name, res_rig) # Affine registration: trsf_aff, res_aff = registration(floating_img, reference_img, method='affine_registration') res_name = 'example_reg_affine_1_2.tif' # filename # SpatialImage to .tif format imsave(out_path+res_name, res_aff) # Deformable registration: trsf_def, res_def = registration(floating_img, reference_img, method= 'deformable_registration') res_name = 'example_reg_deformable_1_2.tif' # filename
opening2 = grey_erosion(input_img>30, 10) """ threshold = int(sys.argv[3]) ext_img = h_transform(asf_img, h=threshold, method='h_transform_min') print 'done transform' con_img = region_labeling(ext_img, low_threshold=1, high_threshold=threshold, method='connected_components') print 'done labelling' seg_img = segmentation(smooth_img, con_img, control='first', method='seeded_watershed') print 'done seg' # optional post processig block #pp_img = labels_post_processing(seg_img, radius=1, # iterations=1, # method='labels_erosion') res_name = 'example_segmentation.tif' imsave(sys.argv[2], seg_img)