Skip to content

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

Merged
ssheorey merged 1 commit intoisl-org:mainfrom
pengpeng-yu:main
Mar 18, 2025
Merged

Fix the reading error when PLY files use non-RGB color orders.#7167
ssheorey merged 1 commit intoisl-org:mainfrom
pengpeng-yu:main

Conversation

@pengpeng-yu
Copy link
Contributor

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() )

@update-docs
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
Copy link
Member

@ssheorey ssheorey left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks @pengpeng-yu !

@ssheorey ssheorey merged commit 8d06977 into isl-org:main Mar 18, 2025
36 of 39 checks passed
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:

2 participants