Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs code for ScaleIntensityRangePercentiles #6829

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions monai/transforms/intensity/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ class ScaleIntensityRangePercentiles(Transform):
.. code-block:: python
:emphasize-lines: 11, 22

image = np.array(
image = torch.Tensor(
matt3o marked this conversation as resolved.
Show resolved Hide resolved
[[[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
Expand All @@ -1144,23 +1144,24 @@ class ScaleIntensityRangePercentiles(Transform):
# to output range [b_min, b_max]
scaler = ScaleIntensityRangePercentiles(10, 90, 0, 200, False, False)
print(scaler(image))
[[[0., 50., 100., 150., 200.],
[0., 50., 100., 150., 200.],
[0., 50., 100., 150., 200.],
[0., 50., 100., 150., 200.],
[0., 50., 100., 150., 200.],
[0., 50., 100., 150., 200.]]]
metatensor([[[ 0., 50., 100., 150., 200.],
[ 0., 50., 100., 150., 200.],
[ 0., 50., 100., 150., 200.],
[ 0., 50., 100., 150., 200.],
[ 0., 50., 100., 150., 200.],
[ 0., 50., 100., 150., 200.]]])


# Scale from lower and upper image intensity percentiles
# to lower and upper percentiles of the output range [b_min, b_max]
rel_scaler = ScaleIntensityRangePercentiles(10, 90, 0, 200, False, True)
print(rel_scaler(image))
[[[20., 60., 100., 140., 180.],
[20., 60., 100., 140., 180.],
[20., 60., 100., 140., 180.],
[20., 60., 100., 140., 180.],
[20., 60., 100., 140., 180.],
[20., 60., 100., 140., 180.]]]
metatensor([[[ 20., 60., 100., 140., 180.],
[ 20., 60., 100., 140., 180.],
[ 20., 60., 100., 140., 180.],
[ 20., 60., 100., 140., 180.],
[ 20., 60., 100., 140., 180.],
[ 20., 60., 100., 140., 180.]]])

See Also:

Expand Down