Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace skimage affine ellipse with numpy ops #1922

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion albumentations/augmentations/geometric/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,23 @@ def bboxes_affine_ellipse(bboxes: np.ndarray, matrix: skimage.transform.Projecti
points = np.stack([x, y], axis=-1).reshape(-1, 2)

# Transform all points at once
transformed_points = skimage.transform.matrix_transform(points, matrix.params)
# Replacing skimage.transform.matrix_transform with numpy ops:
# points reshape from N, 2 to N, 3 with extra dim filled with 1
points = np.concatenate([points, np.ones((points.shape[0], 1))], axis=1)

# change matrix.params.T to matrix.T if matrix is np.ndarray and no longer skimage.transform.ProjectiveTransform
momincks marked this conversation as resolved.
Show resolved Hide resolved
transformed_points = points @ matrix.params.T
momincks marked this conversation as resolved.
Show resolved Hide resolved

# set zero to very small number before homogeneous divide
transformed_points[:, -1:] = np.where(
transformed_points[:, -1:] == 0,
np.finfo(float).eps,
transformed_points[:, -1:],
)

# homogeneous divide and then get x, y
transformed_points = (transformed_points / transformed_points[:, -1:])[:, :2]

transformed_points = transformed_points.reshape(len(bboxes), -1, 2)

# Compute new bounding boxes
Expand Down
Loading