Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def jitter_landmark(landmark, distance_distribution, bias):
- """
- Jitters a 3D landmark such that the distances to the original landmark
- follow the specified distribution.
- Args:
- - landmark (tuple): A tuple containing the x, y, and z coordinates of the landmark.
- - distance_distribution (list): A list of Euclidean distances.
- Returns:
- - jittered_landmark (tuple): A tuple containing the jittered x, y, and z coordinates.
- """
- # Sample a random direction in 3D space
- direction = np.random.randn(3)
- # Normalize the direction vector to have unit length
- direction /= np.linalg.norm(direction)
- # Sample a distance from the specified distribution
- sampled_distance = np.random.choice(distance_distribution)
- # Calculate the jittered coordinates
- x, y, z = landmark
- jittered_x = x + sampled_distance * direction[0] * bias
- jittered_y = y + sampled_distance * direction[1] * bias
- jittered_z = z + sampled_distance * direction[2] * bias
- # Return the jittered landmark coordinates
- jittered_landmark = (jittered_x, jittered_y, jittered_z)
- # Calculate Euclidean distance between original and jittered landmarks
- euclidean_distance = np.linalg.norm(
- np.array(landmark) - np.array(jittered_landmark)
- )
- # Print the Euclidean distance
- print("Euclidean Distance to Original Landmark:", euclidean_distance)
- return jittered_landmark
Advertisement
Add Comment
Please, Sign In to add comment