The following example shows how to use Python API for selection of the sparse cloud points similar to Gradual Selection option in GUI. 


The example shows how to get the reprojection value that would allow to leave the fixe percentage of the points defined as TARGET_PERCENT variable.


import Metashape

TARGET_PERCENT = 90 #percentage of left points


doc = Metashape.app.document #active project in GUI.

chunk = doc.chunk

points = chunk.point_cloud.points


f = Metashape.PointCloud.Filter()

f.init(chunk, criterion = Metashape.PointCloud.Filter.ReprojectionError) #Reprojection Error

list_values = f.values

for i in range(list_values):

    if points[i].valid:

        list_values.append(list_values[i])

list_values.sort()

target = int(len(list_values) * TARGET_PERCENT / 100)

threshold = list_values[target]

f.selectPoints(threshold) 

f.removePoints(threshold)