Commit ebbfd3c08535a7ba221663d42665f3d144663d18
Committed by
GitHub
1 parent
09ea10ae
Exists in
master
MOD: Take median over multiple samples when setting tracker fiducials (#336)
Showing
2 changed files
with
23 additions
and
8 deletions
Show diff stats
invesalius/constants.py
invesalius/gui/task_navigator.py
... | ... | @@ -566,16 +566,29 @@ class Tracker(): |
566 | 566 | def AreTrackerFiducialsSet(self): |
567 | 567 | return not np.isnan(self.tracker_fiducials).any() |
568 | 568 | |
569 | - def SetTrackerFiducial(self, fiducial_index): | |
570 | - coord = None | |
569 | + def GetTrackerCoordinates(self, n_samples=1): | |
570 | + coord_raw_samples = {} | |
571 | + coord_samples = {} | |
571 | 572 | |
572 | - coord_raw = dco.GetCoordinates(self.trk_init, self.tracker_id, self.ref_mode_id) | |
573 | + for i in range(n_samples): | |
574 | + coord_raw = dco.GetCoordinates(self.trk_init, self.tracker_id, self.ref_mode_id) | |
573 | 575 | |
574 | - if self.ref_mode_id: | |
575 | - coord = dco.dynamic_reference_m(coord_raw[0, :], coord_raw[1, :]) | |
576 | - else: | |
577 | - coord = coord_raw[0, :] | |
578 | - coord[2] = -coord[2] | |
576 | + if self.ref_mode_id: | |
577 | + coord = dco.dynamic_reference_m(coord_raw[0, :], coord_raw[1, :]) | |
578 | + else: | |
579 | + coord = coord_raw[0, :] | |
580 | + coord[2] = -coord[2] | |
581 | + | |
582 | + coord_raw_samples[i] = coord_raw | |
583 | + coord_samples[i] = coord | |
584 | + | |
585 | + coord_raw_avg = np.median(list(coord_raw_samples.values()), axis=0) | |
586 | + coord_avg = np.median(list(coord_samples.values()), axis=0) | |
587 | + | |
588 | + return coord_avg, coord_raw_avg | |
589 | + | |
590 | + def SetTrackerFiducial(self, fiducial_index): | |
591 | + coord, coord_raw = self.GetTrackerCoordinates(n_samples=const.FIDUCIAL_REGISTRATION_TRACKER_SAMPLES) | |
579 | 592 | |
580 | 593 | # Update tracker fiducial with tracker coordinates |
581 | 594 | self.tracker_fiducials[fiducial_index, :] = coord[0:3] | ... | ... |