Sorting point cloud by its RGB colour range in grasshopper

Hi all,

I am trying to create a script (having very little knowledge of grasshopper) with a photogrammetry scan. Based off of the RGB values of each point I want to 1. group them and 2. modify and change their colours.

If someone could help with the script or point me in the direction of where to look that would be amazing!

Thanks in advance

I wrote this little ditty five years ago, don’t know if it’s relevant?

If you have data, you’ll get better results by posting it.

One more:

Whoa! 18.2 MB!! I can open the file in Rhino and see that the tree (sideways) is 1 point cloud with one million points when exploded!!! But don’t know how to access those colors in Grasshopper? Looking…

Maybe, but standby… Someone might come along and tell us how to read the colors from the points.

https://mcneel.myjetbrains.com/youtrack/issue/RH-42861

1 Like

I spent way too much time struggling with Rhino APIs and Python and not enough time on Google.

So I have code now that outputs all points and their colors. Trying to do something useful with it but a million points is a HUGE data set. Have you got something smaller we can play with until this works?

I didn’t know a text panel could hold a million colors.

P.S. Can you please elaborate on how to group the colors? Do you want to “round off” colors to ranges of 25 red, 25 green and 25 blue values?

I’m still refining what I have and would like clarification from you before I post the code.

For each point, I’m splitting the colors into RGB values and sorting them, using the highest R, G or B value to categorize them. By this method I count 544618 blue points, 406564 green points and 48974 red points. (see third image below)

Then I have a slider (5 to 30) that divides 255 (the max value of RGB) into ranges (domains) for rounding off color values, effectively reducing the number of colors.

It’s slow for a million points; Sort and Find Domain take 1.7 minutes each for 3 million values (one million points times three color values each).

I’m using Custom Preview to re-color the points instead of modifying the point cloud in Python, which is also somewhat slow and perhaps alters the results?

Here is the original tree:

Here is the tree using 25 values each for RGB:

And here is tree using only red, green and blue: (harsh!)

1 Like

Well, there are all kinds of games that can be played with colors, but as I like to say, this is your art project. I’ll post the code I have, knowing there are more ideas to explore. You need to right-click the Cloud_ID component (cyan group) and then click the point cloud in Rhino.

The purple group at the top limits the points used unless you choose ‘All’ in the blue group FILTER. WARNING!! ‘All’ is slow!


point_cloud_2022Oct22a.gh (24.9 KB)

Here is the Python:

import Rhino
import rhinoscriptsyntax as rs
mport scriptcontext as sc

sc.doc = Rhino.RhinoDoc.ActiveDoc
cloud = sc.doc.Objects.Find(PtCloud)
rs.EnableRedraw(False)

cloud_points = rs.PointCloudPoints(cloud)
cloud_colors = rs.PointCloudPointColors(cloud)
print len(cloud_points)
pts = cloud_points
colors = cloud_colors

That table doesn’t have many colors and will fall over with only two legs?

I forgot to mention that the disabled Preview component on the right, connected to the three color swatch components… well, it’s difficult to explain and I wanted to fix that before posting but… The sequence of colors depends on the point cloud, as indicated in the text panel above it showing the count for each color. The table shows this:

Color: R = 324888
Color: B = 1125
Color: G = 631

So the colors need to be connected to Entwine in that same sequence: RBG (God bless her soul), not BGR. Crude, I know, but it’s bed time for me.

Wrong:

Correct:

This code is a first draft, many things could be changed.

P.S. The points displayed by Custom Preview are definitely and obviously larger than the points in the point cloud, so any color games should modify the point cloud via Python. Which might get weird, modifying the source data unless a copy is made? I know nothing about point clouds.

Hi @TTS
When using Volvox, you can import a smaller subset of the point cloud to make working with the cloud faster until you need all the points. Volvox also lets you extract the colors by deconstructing the cloud with DeCloud component. Once you have the colors, you can tint them all at once (C# component uses GH_GraphicsUtil.BlendColour).

20221022_PointCloudColorGrouping.gh (21.7 KB)

Or you can tint only specified ranges of colors.

I hacked a Python PtCloud component that accepts a list of points and a list of colors:

I moved the points an arbitrary 5 units in both X and Y so the new point cloud doesn’t overlap the original.

I can’t replicate that observation this morning. :thinking:

I replaced the Cloud_ID component (cyan group) with a command line prompt:
point_cloud_2022Oct23a

The only clue that you have selected a point cloud is the prompt disappears. Terrible UI because there is a long wait before anything else happens. Be patient. I added an ‘OnOff’ switch to the getPtCloud component (the original Python) so toggling that switch (off then on again) will re-display the prompt to “Select a point cloud:”

I disabled most of the white group because it was slow and not required for the yellow group.
point_cloud_2022Oct23a.gh (27.3 KB)

I don’t know if this is off topic but …
Have you tried using “Cloudcompare” , it is free software that is very good at classifying pointclouds.
It should be able to do a colour separation.
I use it for processing LIDAR landscape data.
I have worked with point clouds up to 30Gig, it is very powerful.
Mike.

This version has cosmetic changes that don’t address your primary goals (above) but might be general purpose enough to be useful for other GH projects.

  1. The pink group at the top-right uses Galapogos to find a minimum bounding box for the point cloud. When the solver is done, click the Data Dam to pass the results downstream. As always, Data Dam leaks on startup, meaning it passes data without being clicked. :frowning:

  2. The teal-colored group below it uses the minimal bounding box to orient the point cloud vertically at the origin.

  3. Fixed the color issue in the disabled white group. No need to manually reconnect color swatches.

INSTRUCTIONS

  1. Select Point Cloud (then wait patiently)
  2. Start Galapogas Solver (wait patiently)
  3. When Galapogos is done, click Data Dam
    (again, wait patiently)

getPtCloud takes ~18 seconds for both the table and the tree, according to the profiler.
FDom (Find Domain) in the yellow group takes 1.9 minutes for the tree, 32 secs. for the table.
Sort in the white group takes 1.8 minutes for the tree. It is disabled by default.


point_cloud_2022Oct24b.gh (39.0 KB)

P.S. Got a substantial improvement in Galapogos by using a mesh instead the point cloud (‘Union Box’) to test Bounding Box plane rotations!


point_cloud_2022Oct24c.gh (29.3 KB)

Orientation might be flaky since I don’t really know which end of the point cloud is up…

I see nothing proprietary in anything posted on this thread. You haven’t posted any code at all and are free to remove the two E57 pointcloud files from your posts. There are plenty of other examples that anyone is free to use instead:

http://www.libe57.org/data.html

This is obviously a public forum, my answers are intended for anyone working with pointclouds, not just you.

100% agree

1 Like

Hey Joseph!

Incredible answers honestly have seen few people go to such an extent! I am trying to solve a similar issue but maybe I don’t need to. Here’s my problem:

I have site scans that come in as both meshes with textures and coloured point clouds, these site scans I want to be able to designate materials for acoustic analysis using Pachyderm which requires material qualities for analysis ( Pachyderm Acoustical Simulation | Food4Rhino ). I want to break these meshes up into components based off of the colours provided by the point cloud as an approximation of the materials present in the scene and then assign those components to materials in Pachyderm.

I figured as the only data beyond positional present is colour data, and finding a way to analyze the colors present in mesh textures I assume is more complicated, that this would be the best workflow. Is there a way to select mesh faces based off of corresponding pointcloud points? If not would it be better to reform the mesh from the pointcloud and assign values that way? Let me know what you think! I’ve been looking at volvox and cockroach as possible aids in this solution for point cloud analysis and editing.

I know very little about meshes so am not the best person to ask. I believe mesh colors are defined at vertices rather than faces, eh?