Reducing rotations based on bounding box constraint #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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](https://private-user-images.githubusercontent.com/7001376/261629941-12a690cd-fc6a-4111-9c37-592cd577fee9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg4MTcxOTksIm5iZiI6MTcxODgxNjg5OSwicGF0aCI6Ii83MDAxMzc2LzI2MTYyOTk0MS0xMmE2OTBjZC1mYzZhLTQxMTEtOWMzNy01OTJjZDU3N2ZlZTkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MTlUMTcwODE5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTAyYzIyYTg3YjhhNDI5ZDEyNDQzMmZmYTkxOGJmYzhlZDIzNDdlODlkMjNkYjMzYzVmMmI3MDdlYTM3ODRiMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.Tt_RIqVlNN4YPaFHBGTn2WNEub2fluikx8s7dBlhfY4)
With improvement
![image](https://private-user-images.githubusercontent.com/7001376/261629802-214384b0-2d7f-4f7f-853a-5bfbf671d581.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg4MTcxOTksIm5iZiI6MTcxODgxNjg5OSwicGF0aCI6Ii83MDAxMzc2LzI2MTYyOTgwMi0yMTQzODRiMC0yZDdmLTRmN2YtODUzYS01YmZiZjY3MWQ1ODEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MTlUMTcwODE5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzQwOGJjOTEwODNhMWY4Y2U4ZWFhZGUyMTA2MzhlZTdmNzFiZDM0YTZlMTlhZmE1MjcwY2E4ZDFlYjhiMTkxNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.8ABa3KqDsaFipfriWVnsMouEoYaIDbKzlhZFJIAje0U)
New steps
Ex:
if input cube.shape is (4, 1, 2) it will be rotated into (1, 2, 4)
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
All axes size is equal
No constraints are possible. Should be validated for 24 rotations.
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)`
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))