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

Reducing rotations based on bounding box constraint #45

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rubaiate
Copy link

This change enhance run time performance of python implementation by reducing number of rotations necessary.

The logic is based on bounding box of the new cube shape. Since cube is already cropped we can safely use np.shape as bounding box.

Performance improvement tested for n = 8

Without improvement
image

With improvement
image

New steps

  1. After creating expanded cube it is rotated such that np.shape values are sorted order. This will help analyzing cube in later stages.
    Ex:
    if input cube.shape is (4, 1, 2) it will be rotated into (1, 2, 4)
  2. Based on the bounding box possible rotations can be constrained.
    As an example lets assume object bounding box size is (1, 2, 4). Any cube has same shape should have same bounding box. So search space should only have objects which contained in (1, 2, 4) bounding box. To keep bounding box constraint cube can be rotated in only 4 ways.

Following is the list of all possibilities

  1. All axes size is equal
    No constraints are possible. Should be validated for 24 rotations.

  2. Two axes sizes are equal other axis size is different
    Only 8 rotations are possible without breaking bounding box
    `for _ in range(0, 4):
    yield cube
    cube = np.rot90(cube, 1, equal_axes)

    cube = np.rot90(cube, 2, (diff_axis, equal_axes[0]))

    for _ in range(0, 4):
    yield cube
    cube = np.rot90(cube, 1, equal_axes)`

  3. All axes sizes are different.
    Only 4 rotations are possible without breaking bounding box.
    yield cube
    yield np.rot90(cube, 2, (0, 1))
    yield np.rot90(cube, 2, (0, 2))
    yield np.rot90(cube, 2, (1, 2))

@bertie2
Copy link
Collaborator

bertie2 commented Aug 22, 2023

looks good and is well commented, however your choice of ordering of the axis (first <= second <= third) is the opposite to the previous ordering method, if possible could that be reversed to (first >= second >= third) , otherwise I'm happy to merge this asap!

@rubaiate rubaiate force-pushed the bounding-box-rotation-constraint branch 2 times, most recently from aaf49b5 to 8e5785b Compare August 23, 2023 14:40
@rubaiate
Copy link
Author

Logic is updated to provide (first >= second >= third) axis size ordering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants