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
def test_point_rotate(self): x, y = 1.0, 1.0 theta = np.pi/2 x_rot, y_rot = gzapi.point_rotate(x, y, theta) self.assertAlmostEqual(x_rot, -1) self.assertAlmostEqual(y_rot, 1)