Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: smescarzaga on July 02, 2019, 01:19:30 AM

Title: Gradual Selection: How to select certain percentage of points
Post by: smescarzaga on July 02, 2019, 01:19:30 AM
I'm trying to automate a workflow that calls for the selection of a percentage of the sparse cloud at each iteration, rather than at some threshold of reconstruction uncertainty, projection error, etc. I've seen below where a threshold variable is passed into a gradual selection

Code: [Select]
fltr = ps.PointCloud.Filter()
    fltr.init(chunk, ps.PointCloud.Filter.ReconstructionUncertainty)
    fltr.selectPoints(2 * thresh)


How I can I specify in the script to select a percentage of the initial points?

EDIT: As a clarification, I'd like the filter to select a percentage of the points in my cloud based on reconstruction uncertainty.
Title: Re: Gradual Selection: How to select certain percentage of points
Post by: Alexey Pasumansky on July 02, 2019, 06:55:39 PM
Hello smescarzaga,

I can suggest to use the following approach:

Code: [Select]
import Metashape as ps
chunk = ps.app.document.chunk
THRESHOLD = 10 #percentage values for selection


fltr = ps.PointCloud.Filter()
fltr.init(chunk, ps.PointCloud.Filter.ReconstructionUncertainty)
values = fltr.values.copy()
values.sort()
thresh = values[int(len(values)* (1-THRESHOLD/100))]
fltr.selectPoints(thresh)

It will set selected the given percentage of the points (THRESHOLD).
Title: Re: Gradual Selection: How to select certain percentage of points
Post by: smescarzaga on July 02, 2019, 10:25:44 PM
This works great! Thank you Alexey!
Title: Re: Gradual Selection: How to select certain percentage of points
Post by: xyz on February 08, 2021, 11:16:59 AM
I would like to apply this script to the total number of points as well.
Anybody knows how to do this? I was thinking about implementing len(chunk.point_cloud.points) in some way