Forum

Author Topic: Select Faces by Color  (Read 4877 times)

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Select Faces by Color
« on: September 17, 2019, 07:03:32 PM »
Much like the option already available for Dense Clouds.

it would be very useful to be able to select faces based on vertex color so that we can smooth certain parts of the model for example.

Alexey, is this possible via python currently?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15163
    • View Profile
Re: Select Faces by Color
« Reply #1 on: September 17, 2019, 10:24:11 PM »
Hello wojtek,

Via Python you can access the color information for the vertices as (R,G,B) tuple in general case.

I'll see if it would be possible to create a script that could work relatively fast.
Best regards,
Alexey Pasumansky,
Agisoft LLC

matttob

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Select Faces by Color
« Reply #2 on: October 16, 2024, 06:05:29 PM »
Hi Alexey,

 I am recently trying to do the exact same thing and wondering if you had made any progreee on this? I'm really happy to write the code (I think!) but struggling to find out exactly how to access the color information for the vertices as (R,G,B)

Many thanks

Matthew

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15163
    • View Profile
Re: Select Faces by Color
« Reply #3 on: October 17, 2024, 02:02:03 PM »
Hello Matthew,

Please see simple example of model face selection by color:

Code: [Select]

import Metashape

doc = Metashape.app.document
chunk = doc.chunk
model = chunk.model
vertices = model.vertices

red = 100
green = 239
blue = 99
color = 3 * Metashape.Vector([red, green, blue])
tolerance = 20
n_selected = 0

for face in model.faces:
face_color = Metashape.Vector([0, 0, 0])
for i in range(0, 3):
face_color += Metashape.Vector([vertices[face.vertices[i]].color[0], vertices[face.vertices[i]].color[1], vertices[face.vertices[i]].color[2]])
if (color - face_color).norm() < tolerance*3:
face.selected = True
n_selected +=1

Metashape.app.update()
Metashape.app.messageBox("Selected {:d} faces. Press OK.\n".format(n_selected))

Red, green, blue values should be defined in script body.
Best regards,
Alexey Pasumansky,
Agisoft LLC

matttob

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Select Faces by Color
« Reply #4 on: October 18, 2024, 12:28:43 AM »
Amazing thankyou so much, I was really struggling with the syntax/naming of just accessing the vertices but now it seems very simple :)

matttob

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Select Faces by Color
« Reply #5 on: October 25, 2024, 11:29:37 AM »
Hi Alexey,

The code you provided worked perfectly. However, we would like to perform the same operation after we have applied a Raster Transformation to the Point Cloud and when we do this the selection still seems to be performed on the pre-transformed vertices even after we apply the color to the point cloud and the images appear to have the rater transformation applied. I was wondering if there is something we can do here in the API to make sure that the raster transform is applied to the Vertices?

Many thanks

Matthew

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15163
    • View Profile
Re: Select Faces by Color
« Reply #6 on: October 25, 2024, 06:29:03 PM »
Hello Matthew,

As a workaround you can try to recalculate vertices[face.vertices].color values according to chunk.raster_transform.formula.

Alternatively, run colorize mesh vertices operation based on the point cloud color, providing that raster transformation is applied. But in such approach you will loose the original colors.
Best regards,
Alexey Pasumansky,
Agisoft LLC

matttob

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Select Faces by Color
« Reply #7 on: October 30, 2024, 07:18:47 PM »
Hi Alexey,

Thanks for your continued help on this and apologies for my late response, but I was trying my best to get it working before bothering you again, but I haven't succeeded.

Is it possible for you to explain a bit more or provide a little more code for what you mean when you say:

" can try to recalculate vertices[face.vertices].color values according to chunk.raster_transform.formula."

many thanks

Matthew