def test_get_largest_region(self): test_img = np.zeros((1000,1000), dtype=np.uint8) rr, cc = circle(100,100,50) test_img[rr,cc] = 1 rr, cc = circle(500,500,100) test_img[rr, cc] = 1 largest_region = gzapi.get_largest_region(test_img) self.assertTupleEqual(largest_region.centroid, (500,500))
def test_processed_image(self): largest = None while largest is None: self.di.data_id = self.di.get_random_image() top = self.di.image.plot_components[2] im = top.data.arrays.get('im') # Assert that the orientation is indeed zero largest = get_largest_region(im) self.assertLessEqual(round(largest.orientation), 1)
def test_rotate_largest_region(self): test_img = np.zeros((1000,1000), dtype=np.uint8) rr, cc = circle(100,100,50) test_img[rr,cc] = 1 rr, cc = ellipse(500,500,300,100) test_img[rr, cc] = 1 rotated = gzapi.rotate_largest_region(test_img) largest_region = gzapi.get_largest_region(rotated) self.assertAlmostEqual(largest_region.orientation, 0) self.assertIsNone(gzapi.rotate_largest_region(None))
def process_image(x): org_region = di.get_largest_region(x) rr1, cc1 = di.get_bbox_center(org_region.bbox) rotated_x = di.rotate_largest_region(x) _x = cc1 - x.shape[1]/2 _y = rr1 - x.shape[0]/2 cc2, rr2 = di.point_rotate(_x, _y, -org_region.orientation) rr2 += rotated_x.shape[0]/2 cc2 += rotated_x.shape[1]/2 cropped = di.crop_around_centroid(rotated_x, rr2, cc2) return cropped
def update_cropped_image_data(self): x = self.image_data.arrays.get('im')[:, :, 0] org_region = get_largest_region(x) rr1, cc1 = get_bbox_center(org_region.bbox) rotated_x = rotate_largest_region(x) _x = cc1 - x.shape[1] / 2 _y = rr1 - x.shape[0] / 2 cc2, rr2 = point_rotate(_x, _y, -org_region.orientation) rr2 += rotated_x.shape[0] / 2 cc2 += rotated_x.shape[1] / 2 cropped = crop_around_centroid(rotated_x, rr2, cc2) self.cropped_image_data.set_data('im', cropped)
def _cropped_image_data_default(self): x = self.image_data.arrays.get('im')[:, :, 0] org_region = get_largest_region(x) rr1, cc1 = get_bbox_center(org_region.bbox) rotated_x = rotate_largest_region(x) _x = cc1 - x.shape[1] / 2 _y = rr1 - x.shape[0] / 2 cc2, rr2 = point_rotate(_x, _y, -org_region.orientation) rr2 += rotated_x.shape[0] / 2 cc2 += rotated_x.shape[1] / 2 cropped = crop_around_centroid(rotated_x, rr2, cc2) apd = ArrayPlotData(im=cropped) return apd