Example #1
0
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
Example #2
0
 def test_get_region_bounds(self):
     test_img = np.zeros((1000,1000), dtype=np.uint8)
     rr, cc = circle(100,100,50)
     test_img[rr,cc] = 1
     bx, by = gzapi.get_region_bounds(test_img)
     bx, by = bx[0], by[0]
     minc, maxc = bx
     minr, maxr = by
     self.assertEqual(maxc - minc + 1, 100)
     self.assertEqual(maxr - minr + 1, 100)
     center = gzapi.get_bbox_center((minr, minc, maxr, maxc))
     self.assertTupleEqual(center, (100,100))
Example #3
0
 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)
Example #4
0
 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