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 fixed percentage of the points defined as TARGET_PERCENT variable.


Script for Metashape 1.x:

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 list_values_valid = list() for i in range(len(list_values)):     if points[i].valid:         list_values_valid.append(list_values[i]) list_values_valid.sort() target = int(len(list_values_valid) * TARGET_PERCENT / 100) threshold = list_values_valid[target] f.selectPoints(threshold)  f.removePoints(threshold)



Script for Metashape 2.x:

import Metashape
TARGET_PERCENT = 90 #percentage of left points

doc = Metashape.app.document #active project in GUI
chunk = doc.chunk
points = chunk.tie_points.points

f = Metashape.TiePoints.Filter()
f.init(chunk, criterion = Metashape.TiePoints.Filter.ReprojectionError) #Reprojection Error
list_values = f.values
list_values_valid = list()
for i in range(len(list_values)):
    if points[i].valid:
        list_values_valid.append(list_values[i])
list_values_valid.sort()
target = int(len(list_values_valid) * TARGET_PERCENT / 100)
threshold = list_values_valid[target]
f.selectPoints(threshold) 
f.removePoints(threshold)