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

Fix the reading error when PLY files use non-RGB color orders. #7167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pengpeng-yu
Copy link

Type

Motivation and Context

It seems that open3d.io.read_point_cloud assumes that the color properties end with the blue channel:

if (index == 2) { // reading 'blue'
state_ptr->color_index++;
}

If a PLY file defines colors in other orders, e.g., GBR, the color_index is incorrectly incremented after reading the blue channel, causing all red values to be placed at the wrong positions.

However, open3d.t.io.read_point_cloud correctly handles this case:

const int64_t index = attr_state->stride_ * attr_state->current_size_ +
attr_state->offset_;
data_ptr[index] = static_cast<T>(ply_get_argument_value(argument));
++attr_state->current_size_;

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 changed the meaning of color_index to track the number of processed channels (instead of the number of points), which allows for correct point indexing regardless of the channel order.

Here is an example using this file :

import open3d as o3d
import numpy as np

pc = o3d.io.read_point_cloud("aaa.ply")   # Current version will produce  RPly: Aborted by user  [Open3D WARNING] Read PLY failed: unable to read file: aaa.ply
pc2 = o3d.t.io.read_point_cloud("aaa.ply")

print( ((pc2.point.colors).numpy() == np.asarray(pc.colors) * 255).all() )

Copy link

update-docs bot commented Feb 11, 2025

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

@ssheorey ssheorey self-requested a review February 11, 2025 14:18
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.

[Open3D WARNING] Read PLY failed: unable to read file:
1 participant