Guest User

Untitled

a guest
Oct 1st, 2023
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | Source Code | 0 0
  1. import numpy as np
  2.  
  3.  
  4. def jitter_landmark(landmark, distance_distribution, bias):
  5.     """
  6.    Jitters a 3D landmark such that the distances to the original landmark
  7.    follow the specified distribution.
  8.  
  9.    Args:
  10.    - landmark (tuple): A tuple containing the x, y, and z coordinates of the landmark.
  11.    - distance_distribution (list): A list of Euclidean distances.
  12.  
  13.    Returns:
  14.    - jittered_landmark (tuple): A tuple containing the jittered x, y, and z coordinates.
  15.    """
  16.     # Sample a random direction in 3D space
  17.     direction = np.random.randn(3)
  18.  
  19.     # Normalize the direction vector to have unit length
  20.     direction /= np.linalg.norm(direction)
  21.  
  22.     # Sample a distance from the specified distribution
  23.     sampled_distance = np.random.choice(distance_distribution)
  24.  
  25.     # Calculate the jittered coordinates
  26.     x, y, z = landmark
  27.     jittered_x = x + sampled_distance * direction[0] * bias
  28.     jittered_y = y + sampled_distance * direction[1] * bias
  29.     jittered_z = z + sampled_distance * direction[2] * bias
  30.  
  31.     # Return the jittered landmark coordinates
  32.     jittered_landmark = (jittered_x, jittered_y, jittered_z)
  33.  
  34.     # Calculate Euclidean distance between original and jittered landmarks
  35.     euclidean_distance = np.linalg.norm(
  36.         np.array(landmark) - np.array(jittered_landmark)
  37.     )
  38.  
  39.     # Print the Euclidean distance
  40.     print("Euclidean Distance to Original Landmark:", euclidean_distance)
  41.     return jittered_landmark
  42.  
Advertisement
Add Comment
Please, Sign In to add comment