def test_transform(self): roi = ROI.ROI(polygons=[[0, 0], [0, 2], [2, 2], [2, 0]], im_shape=(3, 3)) transforms = [np.array([[1, 0, 0], [0, 1, 0]])] # one per plane roi_list = ROI.ROIList([roi]) assert_equal(roi_list.transform(transforms)[0].coords, roi.coords)
def test_postprocess(self): centers = [(10, 10), (40, 40), (70, 70), (100, 100)] roi_xy = [ np.arange(self.tiff_ds.sequences[0].shape[2]), np.arange(self.tiff_ds.sequences[0].shape[3]) ] rois = ROI.ROIList([ ROI.ROI(_gaussian_2d(roi_xy, center, (10, 10))) for center in centers ]) tobool = segment.SparseROIsFromMasks(n_processes=2) smooth = segment.SmoothROIBoundaries(n_processes=2) rois = smooth.apply(tobool.apply(rois)) assert_(len(rois) == len(centers)) for roi in rois: polygon = mplPath.Path(roi.coords[0][:, :2]) for nc, center in enumerate(centers): if polygon.contains_point(center): centers.pop(nc) break assert_(len(centers) == 0)
def test_poly2mask(): poly1 = [[0, 0], [0, 1], [1, 1], [1, 0]] poly2 = [[0, 1], [0, 2], [2, 2], [2, 1]] masks = ROI.poly2mask([poly1, poly2], (3, 3)) assert_equal( masks[0].todense(), np.matrix([[True, False, False], [True, True, False], [False, False, False]], dtype=bool))
def test_mask2poly(): mask = np.zeros((10, 10), dtype=bool) mask[2:4, 3:7] = True multi_poly = ROI.mask2poly(mask) assert_equal( np.array(multi_poly[0].exterior.coords), np.array([[7., 3.5, 0.], [7., 2.5, 0.], [6.5, 2., 0.], [3.5, 2., 0.], [3., 2.5, 0.], [3., 3.5, 0.], [3.5, 4., 0.], [6.5, 4., 0.], [7., 3.5, 0.]]))
def test_poly2mask(): poly1 = [[0, 0], [0, 1], [1, 1], [1, 0]] poly2 = [[0, 1], [0, 2], [2, 2], [2, 1]] masks = ROI.poly2mask([poly1, poly2], (3, 3)) assert_equal( masks[0].todense(), np.matrix( [[True, False, False], [True, True, False], [False, False, False]], dtype=bool))
def test_ROI(self): roi = ROI.ROI(polygons=[[0, 0], [0, 1], [1, 1], [1, 0]], im_shape=(2, 2)) assert_equal(roi.coords, [ np.array([[0., 0., 0.], [0., 1., 0.], [1., 1., 0.], [1., 0., 0.], [0., 0., 0.]]) ]) assert_equal(roi.mask[0].todense(), np.matrix([[True, False], [False, False]], dtype=bool))