Skip to content

Commit

Permalink
Feature/optional pose norm info (#141)
Browse files Browse the repository at this point in the history
* CDL: minor doc typo fix

* Undoing some changes that got mixed in

* automatically set pose normalization info if not provided, add some readme notes. Fixes #140
  • Loading branch information
cleong110 authored Jan 10, 2025
1 parent 87c3691 commit 3e4e5e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Maintaining data consistency is very important and data normalization is one met

For instance, you can set the shoulder width to a consistent measurement across all data points. This is useful for comparing poses across different individuals.

* See this example for using a standard body feature, such as the shoulder width, for normalization:
* See this example for manually specifying a standard body feature, such as the shoulder width, for normalization:

```python
pose.normalize(p.header.normalization_info(
Expand All @@ -106,6 +106,12 @@ pose.normalize(p.header.normalization_info(
))
```

* If normalization info is not specified, normalize() will automatically base normalization on shoulder joints.

```python
pose.normalize() # same result as above, but attempts to automatically select shoulder points based on format
```

* Keypoint values can be standardized to have a mean of zero and unit variance:

```python
Expand All @@ -116,7 +122,6 @@ pose.normalize_distribution()

The usual way to do this is to compute a separate mean and standard deviation for each keypoint and each dimension (usually x and y). This can be achieved with the `axis` argument of `normalize_distribution`.


```python

# Normalize each keypoint separately:
Expand Down
6 changes: 5 additions & 1 deletion src/python/pose_format/pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
PoseNormalizationInfo)
from pose_format.utils.fast_math import distance_batch
from pose_format.utils.reader import BufferReader
from pose_format.utils.generic import pose_normalization_info


class Pose:
Expand Down Expand Up @@ -87,7 +88,7 @@ def focus(self):
dimensions = (maxs - mins).tolist()
self.header.dimensions = PoseHeaderDimensions(*dimensions)

def normalize(self, info: PoseNormalizationInfo, scale_factor: float = 1) -> "Pose":
def normalize(self, info: PoseNormalizationInfo|None=None, scale_factor: float = 1) -> "Pose":
"""
Normalize the points to a fixed distance between two particular points.
Expand All @@ -103,6 +104,9 @@ def normalize(self, info: PoseNormalizationInfo, scale_factor: float = 1) -> "Po
Pose
The normalized Pose object.
"""
if info is None:
info = pose_normalization_info(self)

transposed = self.body.points_perspective()

p1s = transposed[info.p1]
Expand Down

0 comments on commit 3e4e5e3

Please sign in to comment.