Skip to content

Commit 49a1ae5

Browse files
authored
Fix docs code for ScaleIntensityRangePercentiles (#6829)
When running the docs code for `ScaleIntensityRangePercentiles`, it failed with the error (MONAI 1.2.dev2316): ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/mhadlich/anaconda3/envs/monai/lib/python3.8/site-packages/monai/transforms/intensity/array.py", line 998, in __call__ img_t = self._normalize(img=img_t) File "/home/mhadlich/anaconda3/envs/monai/lib/python3.8/site-packages/monai/transforms/intensity/array.py", line 971, in _normalize a_min: float = percentile(img, self.lower) # type: ignore File "/home/mhadlich/anaconda3/envs/monai/lib/python3.8/site-packages/monai/transforms/utils_pytorch_numpy_unification.py", line 121, in percentile result = torch.quantile(x, q, dim=dim, keepdim=keepdim) RuntimeError: quantile() input tensor must be either float or double dtype ``` This commit updates the docs for the function to use `torch.Tensor` instead. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
1 parent 5e6ce7c commit 49a1ae5

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

monai/transforms/intensity/array.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ class ScaleIntensityRangePercentiles(Transform):
11321132
.. code-block:: python
11331133
:emphasize-lines: 11, 22
11341134
1135-
image = np.array(
1135+
image = torch.Tensor(
11361136
[[[1, 2, 3, 4, 5],
11371137
[1, 2, 3, 4, 5],
11381138
[1, 2, 3, 4, 5],
@@ -1144,23 +1144,24 @@ class ScaleIntensityRangePercentiles(Transform):
11441144
# to output range [b_min, b_max]
11451145
scaler = ScaleIntensityRangePercentiles(10, 90, 0, 200, False, False)
11461146
print(scaler(image))
1147-
[[[0., 50., 100., 150., 200.],
1148-
[0., 50., 100., 150., 200.],
1149-
[0., 50., 100., 150., 200.],
1150-
[0., 50., 100., 150., 200.],
1151-
[0., 50., 100., 150., 200.],
1152-
[0., 50., 100., 150., 200.]]]
1147+
metatensor([[[ 0., 50., 100., 150., 200.],
1148+
[ 0., 50., 100., 150., 200.],
1149+
[ 0., 50., 100., 150., 200.],
1150+
[ 0., 50., 100., 150., 200.],
1151+
[ 0., 50., 100., 150., 200.],
1152+
[ 0., 50., 100., 150., 200.]]])
1153+
11531154
11541155
# Scale from lower and upper image intensity percentiles
11551156
# to lower and upper percentiles of the output range [b_min, b_max]
11561157
rel_scaler = ScaleIntensityRangePercentiles(10, 90, 0, 200, False, True)
11571158
print(rel_scaler(image))
1158-
[[[20., 60., 100., 140., 180.],
1159-
[20., 60., 100., 140., 180.],
1160-
[20., 60., 100., 140., 180.],
1161-
[20., 60., 100., 140., 180.],
1162-
[20., 60., 100., 140., 180.],
1163-
[20., 60., 100., 140., 180.]]]
1159+
metatensor([[[ 20., 60., 100., 140., 180.],
1160+
[ 20., 60., 100., 140., 180.],
1161+
[ 20., 60., 100., 140., 180.],
1162+
[ 20., 60., 100., 140., 180.],
1163+
[ 20., 60., 100., 140., 180.],
1164+
[ 20., 60., 100., 140., 180.]]])
11641165
11651166
See Also:
11661167

0 commit comments

Comments
 (0)