Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

Add feature to choose voxel color mode when creating VoxelGrid from PointCloud

Open rxba opened this issue 1 year ago • 1 comments

Type

  • [ ] Bug fix (non-breaking change which fixes an issue): Fixes #
  • [X] New feature (non-breaking change which adds functionality). Resolves #6934
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) Resolves #

Motivation and Context

Creating a VoxelGrid with VoxelGrid.create_from_point_cloud or VoxelGrid.create_from_point_cloud_within_bounds currently always averages the colors of each point per voxel. This is a sane default, yet might not always be desired, for example for MRI reconstruction as described in the linked issue. This PR adds the feature of choosing a mode of determining the color per voxel when creating a VoxelGrid:

  • avg - average color value (default)
  • min - minimum color value for each color channel
  • max - maximum color value for each color channel
  • sum - accumulated color value

Checklist:

  • [X] I have run python util/check_style.py --apply to apply Open3D code style to my code.
  • [X] This PR changes Open3D behavior or adds new functionality.
    • [X] Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is updated accordingly.
    • [X] I have added or updated C++ and / or Python unit tests OR included test results (e.g. screenshots or numbers) here.
  • [X] I will follow up and update the code if CI fails.
  • [X] For fork PRs, I have selected Allow edits from maintainers.

Description

I've made the following changes:

  • VoxelGrid.create_from_point_cloud and VoxelGrid.create_from_point_cloud_within_bounds take an additional optional parameter color_mode, defined by the enum VoxelGrid::VoxelColorMode, which determines the way colors are assigned to voxels (default behaviour is unchanged)
  • for this, I created the color aggregation helper class AggColorVoxel. This is basically AvgColorVoxel, but with the additional functionality of also being able to return the min, max and sum color value of the voxel (I did not remove AvgColorVoxel to not break existing code. However, it seemed unfitting to add min, max and sum functionality to this class considering its name and description. It's my first feature contribution, so I'm unsure of what to do with AvgColorVoxel, since technically this class could now be deprecated and replaced by AggColorVoxel.)
  • updated C++ and Python documentation
  • added a short sentence to the voxelization tutorial to describe this optional feature

Here are some examples (top left: AVG, top right: MIN, bottom left: MAX, bottom right: SUM):

Screenshot 2024-08-28 at 20 20 39 Screenshot 2024-08-28 at 20 34 06 Screenshot 2024-08-28 at 20 37 05

rxba avatar Aug 28 '24 19:08 rxba

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB