Forum

Author Topic: ability to filter tie points by variance  (Read 3217 times)

bisenberger

  • Sr. Member
  • ****
  • Posts: 329
    • View Profile
    • Digital Mapping & Graphics
ability to filter tie points by variance
« on: February 19, 2023, 07:11:05 PM »
It would be handy to be able to filter tie points by variance to easily select and delete the tie points with the largest errors.
Digital Mapping & Graphics LLC
https://digital-mapping.net/

fran.garcia

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: ability to filter tie points by variance
« Reply #1 on: March 18, 2023, 12:48:50 AM »
Hi if there´s any way to do it please help

Etienne_U

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: ability to filter tie points by variance
« Reply #2 on: May 17, 2023, 04:58:08 PM »
Hi bisenberger,

I made a script which makes it possible, by selecting the percent of tie points you'd like to keep.
If it is not exactly what you need, you can try to adjust my script, it is not a hard one.

Best,

Etienne

Code: [Select]
# Permet de filtrer les tie points en gardant un certain pourcentage de points

import Metashape
import glob
import os
import time
import math



def Tie_Points_Filtering():

    doc = Metashape.app.document
   
    # Demande à l'utilisateur du nom du chunk
    chunk_name = Metashape.app.getString("What is the chunk's name ?")

    # Itération au sein des chunks pour travailler dans celui sélectionner par l'utilisateur
    for chunk_it in doc.chunks:
        if chunk_name == chunk_it.label:
            chunk = chunk_it


    # Demande de combien de pourcent de tie points à garder
    TARGET_PERCENT = Metashape.app.getFloat("What percent of tie points would you like to keep after the alignement ?")


##########################          Filtre des tie points         #######################


   
    # Fonction pour supprimer les mauvais tie points
    def remove_tie_points(critere,TARGET_PERCENT):

        points = chunk.tie_points
        num_points = len([i for i in chunk.tie_points.points if i.valid])
        target = num_points * TARGET_PERCENT / 100

        # Trie des Tiepoints selon leur erreur
        list_values = []
        f = Metashape.TiePoints.Filter()
        f.init(points, criterion = critere)
        list_values = [val for i,val in enumerate(f.values) if chunk.tie_points.points[i].valid]
        list_values.sort()

        # Threshold à appliquer
        threshold = list_values[int(target)]
        f.selectPoints(threshold)
        f.removePoints(threshold)

   

    # Suppresion des tie points pour selon les 3 différentes manières
    critere = Metashape.TiePoints.Filter.ReprojectionError
    remove_tie_points(critere,int(TARGET_PERCENT))
   
    critere = Metashape.TiePoints.Filter.ReconstructionUncertainty
    remove_tie_points(critere,int(TARGET_PERCENT))
   
    critere = Metashape.TiePoints.Filter.ProjectionAccuracy
    remove_tie_points(critere,int(TARGET_PERCENT))
   
    chunk.optimizeCameras(fit_f=True, fit_cx=True, fit_cy=True, fit_b1=False, fit_b2=False, fit_k1=True,
    fit_k2=True, fit_k3=True, fit_k4=True, fit_p1=True, fit_p2=True, fit_corrections=True,
    adaptive_fitting=True, tiepoint_covariance=True)


label = "Scripts/[02] Tie Points Filtering"
Metashape.app.addMenuItem(label, Tie_Points_Filtering)