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

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

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

Conversation

rxba
Copy link
Contributor

@rxba rxba commented Aug 28, 2024

Type

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:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • 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

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

/// \enum VoxelColorMode
///
/// \brief Possible ways of determining voxel color from PointCloud.
enum class VoxelColorMode { AVG, MIN, MAX, SUM };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible nitpick: can we call this "VoxelPoolingMode" or "VoxelPoolingMethod" instead of "VoxelColorMode"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I'd tend to agree that "VoxelPoolingMode" is probably the better name, but I'll wait until a maintainer has had the chance to review the PR to get their feedback.

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.

VoxelGrid.create_from_point_cloud should allow for choosing color reduction method other than avg
2 participants