def test_get_methods(self): tmp_arr = np.ones((5, 5), dtype=np.uint8) vox = [1.0, 1.0] orig = [0, 0] img = SpatialImage(tmp_arr) metadata = { 'dim': 2, 'extent': [5.0, 5.0], 'shape': (5, 5), 'type': 'uint8', 'voxelsize': [1.0, 1.0], 'origin': [0, 0], 'max': 1, 'mean': 1.0, 'min': 1 } self.assertEqual(img.get_type(), tmp_arr.dtype) self.assertEqual(img.get_voxelsize(), vox) self.assertEqual(img.get_shape(), tmp_arr.shape) self.assertEqual(img.get_origin(), orig) self.assertEqual(img.get_extent(), [tmp_arr.shape[0], tmp_arr.shape[1]]) self.assertEqual(img.get_dim(), 2) self.assertDictEqual(img.get_metadata(), metadata)
def test_set_methods(self): tmp_arr = np.ones((5, 5), dtype=np.uint8) img = SpatialImage(tmp_arr) new_vox = [0.5, 0.5] new_orig = [1, 1] new_ext = [ tmp_arr.shape[0] * new_vox[0], tmp_arr.shape[1] * new_vox[1] ] new_type = np.uint16 new_met = img.get_metadata() new_met['name'] = 'img_test' img.set_voxelsize(new_vox) self.assertEqual(img.get_voxelsize(), new_vox) self.assertEqual(img.get_metadata()['voxelsize'], new_vox) self.assertEqual(img.get_extent(), new_ext) self.assertEqual(img.get_metadata()['extent'], new_ext) img = img.set_type(new_type) self.assertEqual(img.get_type(), 'uint16') self.assertEqual(img.get_metadata()['type'], 'uint16') img.set_origin(new_orig) self.assertEqual(img.get_origin(), new_orig) self.assertEqual(img.get_metadata()['origin'], new_orig) img.set_extent([10.0, 5.0]) self.assertEqual(img.get_voxelsize(), [2.0, 1.0]) self.assertEqual(img.get_metadata()['extent'], [10.0, 5.0]) self.assertEqual(img.get_metadata()['voxelsize'], [2.0, 1.0]) img.set_metadata(new_met) self.assertDictEqual(img.get_metadata(), new_met) img.set_pixel([2, 2], 10) self.assertEqual(img.get_pixel([2, 2]), 10) #--- numpy compatibility (for example transposition) new_arr = np.ones((10, 5), dtype=np.uint8) img = SpatialImage(new_arr, voxelsize=[0.5, 1]) img = img.transpose() self.assertEqual(img.get_metadata()['shape'], (5, 10)) self.assertEqual(img.get_metadata()['voxelsize'], [1.0, 0.5]) self.assertEqual(img.get_metadata()['voxelsize'], img.get_voxelsize()) self.assertEqual(img.get_metadata()['extent'], [5.0, 5.0]) self.assertEqual(img.get_metadata()['extent'], img.get_extent())
def test_set_methods(self): tmp_arr = np.ones((5,5),dtype=np.uint8) img = SpatialImage(tmp_arr) new_vox = [0.5, 0.5] new_orig = [1, 1] new_ext = [tmp_arr.shape[0]*new_vox[0], tmp_arr.shape[1]*new_vox[1]] new_type = np.uint16 new_met = img.get_metadata() new_met['name'] = 'img_test' img.set_voxelsize(new_vox) self.assertEqual(img.get_voxelsize(), new_vox) self.assertEqual(img.get_metadata()['voxelsize'], new_vox) self.assertEqual(img.get_extent(), new_ext) self.assertEqual(img.get_metadata()['extent'], new_ext) img = img.set_type(new_type) self.assertEqual(img.get_type(), 'uint16') self.assertEqual(img.get_metadata()['type'], 'uint16') img.set_origin(new_orig) self.assertEqual(img.get_origin(), new_orig) self.assertEqual(img.get_metadata()['origin'], new_orig) img.set_extent([10.0, 5.0]) self.assertEqual(img.get_voxelsize(), [2.0,1.0]) self.assertEqual(img.get_metadata()['extent'], [10.0, 5.0]) self.assertEqual(img.get_metadata()['voxelsize'], [2.0,1.0]) img.set_metadata(new_met) self.assertDictEqual(img.get_metadata(), new_met) img.set_pixel([2,2], 10) self.assertEqual(img.get_pixel([2,2]), 10) #--- numpy compatibility (for example transposition) new_arr = np.ones((10,5), dtype=np.uint8) img = SpatialImage(new_arr, voxelsize=[0.5,1]) img = img.transpose() self.assertEqual(img.get_metadata()['shape'], (5,10)) self.assertEqual(img.get_metadata()['voxelsize'], [1.0,0.5]) self.assertEqual(img.get_metadata()['voxelsize'], img.get_voxelsize()) self.assertEqual(img.get_metadata()['extent'], [5.0,5.0]) self.assertEqual(img.get_metadata()['extent'], img.get_extent())
def test_get_methods(self): tmp_arr = np.ones((5,5),dtype=np.uint8) vox = [1.0, 1.0] orig = [0, 0] img = SpatialImage(tmp_arr) metadata = {'dim': 2, 'extent': [5.0, 5.0], 'shape': (5, 5), 'type': 'uint8', 'voxelsize': [1.0, 1.0], 'origin': [0, 0], 'max': 1, 'mean': 1.0, 'min': 1} self.assertEqual(img.get_type(), tmp_arr.dtype) self.assertEqual(img.get_voxelsize(), vox) self.assertEqual(img.get_shape(), tmp_arr.shape) self.assertEqual(img.get_origin(), orig) self.assertEqual(img.get_extent(), [tmp_arr.shape[0], tmp_arr.shape[1]]) self.assertEqual(img.get_dim(), 2) self.assertDictEqual(img.get_metadata(), metadata)
times = [3,4] segmentation_list, feature_space_list, back_id_list = [], [], [] for ind, val in enumerate(times): 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)