
Some methods, like Li, have some special handling for nan values, but that is not uniform across all our methods, as you have seen. 😂 I would suggest: ```python t = threshold_otsu(image[np.isfinite(image)]) ``` That will only pass the non-nan, non-inf pixels to Otsu to do the calculation. Hope this helps! Juan.
On 18 Dec 2020, at 7:19 am, Laurynas Gedminas <laurynasgedminas@gmail.com> wrote:
Hello, I have NDVI image, its not a square, and has some None values, I am trying to create otsu threshold, but getting error: autodetected range of [nan, nan] is not finite
how to go around that?
<image.png>
Thank you,

Hey, the suggested code reshapes the original array from (171, 169) to (11746,) and does not work in otsu threshold Thank you, Laurynas On Thu, Dec 17, 2020 at 9:56 PM Juan Nunez-Iglesias <jni@fastmail.com> wrote:
Some methods, like Li, have some special handling for nan values, but that is not uniform across all our methods, as you have seen. 😂 I would suggest:
```python t = threshold_otsu(image[np.isfinite(image)]) ```
That will only pass the non-nan, non-inf pixels to Otsu to do the calculation.
Hope this helps!
Juan.
On 18 Dec 2020, at 7:19 am, Laurynas Gedminas <laurynasgedminas@gmail.com> wrote:
Hello, I have NDVI image, its not a square, and has some None values, I am trying to create otsu threshold, but getting error:
autodetected range of [nan, nan] is not finite
how to go around that?
<image.png>
Thank you,

You can use numpy's reshape function to reshape the array back to the correct shape. https://numpy.org/doc/stable/reference/generated/numpy.reshape.html On Fri, Dec 18, 2020, 12:03 PM Laurynas Gedminas <laurynasgedminas@gmail.com> wrote:
Hey, the suggested code reshapes the original array from (171, 169) to (11746,) and does not work in otsu threshold
Thank you, Laurynas
On Thu, Dec 17, 2020 at 9:56 PM Juan Nunez-Iglesias <jni@fastmail.com> wrote:
Some methods, like Li, have some special handling for nan values, but that is not uniform across all our methods, as you have seen. 😂 I would suggest:
```python t = threshold_otsu(image[np.isfinite(image)]) ```
That will only pass the non-nan, non-inf pixels to Otsu to do the calculation.
Hope this helps!
Juan.
On 18 Dec 2020, at 7:19 am, Laurynas Gedminas <laurynasgedminas@gmail.com> wrote:
Hello, I have NDVI image, its not a square, and has some None values, I am trying to create otsu threshold, but getting error:
autodetected range of [nan, nan] is not finite
how to go around that?
<image.png>
Thank you,
_______________________________________________ scikit-image mailing list -- scikit-image@python.org To unsubscribe send an email to scikit-image-leave@python.org https://mail.python.org/mailman3/lists/scikit-image.python.org/ Member address: ravery@ucsb.edu

Hi Laurynas, What version of scikit-image are you using? threshold_otsu should work with arrays of any dimensionality, including 1D arrays: In [2]: filters.threshold_otsu(np.random.random((11746,))) Out[2]: 0.4980217396247033 Juan.
On 19 Dec 2020, at 1:37 am, Laurynas Gedminas <laurynasgedminas@gmail.com> wrote:
Hey, the suggested code reshapes the original array from (171, 169) to (11746,) and does not work in otsu threshold
Thank you, Laurynas
On Thu, Dec 17, 2020 at 9:56 PM Juan Nunez-Iglesias <jni@fastmail.com <mailto:jni@fastmail.com>> wrote: Some methods, like Li, have some special handling for nan values, but that is not uniform across all our methods, as you have seen. 😂 I would suggest:
```python t = threshold_otsu(image[np.isfinite(image)]) ```
That will only pass the non-nan, non-inf pixels to Otsu to do the calculation.
Hope this helps!
Juan.
On 18 Dec 2020, at 7:19 am, Laurynas Gedminas <laurynasgedminas@gmail.com <mailto:laurynasgedminas@gmail.com>> wrote:
Hello, I have NDVI image, its not a square, and has some None values, I am trying to create otsu threshold, but getting error: autodetected range of [nan, nan] is not finite
how to go around that?
<image.png>
Thank you, <image.png>

Hello Juan, the scikit-image is 0.18 version. I think the problem is the nan values in the array? ndvi.shape (171, 169) ndvi array([[nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], ..., [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan]]) it also does not work with masked arrays: t3 = np.ma.masked_invalid(ndvi): [image: image.png] Thank you On Fri, Dec 18, 2020 at 7:33 PM Juan Nunez-Iglesias <jni@fastmail.com> wrote:
Hi Laurynas,
What version of scikit-image are you using? threshold_otsu should work with arrays of any dimensionality, including 1D arrays:
In [2]: filters.threshold_otsu(np.random.random((11746,))) Out[2]: 0.4980217396247033
Juan.
On 19 Dec 2020, at 1:37 am, Laurynas Gedminas <laurynasgedminas@gmail.com> wrote:
Hey, the suggested code reshapes the original array from (171, 169) to (11746,) and does not work in otsu threshold
Thank you, Laurynas
On Thu, Dec 17, 2020 at 9:56 PM Juan Nunez-Iglesias <jni@fastmail.com> wrote:
Some methods, like Li, have some special handling for nan values, but that is not uniform across all our methods, as you have seen. 😂 I would suggest:
```python t = threshold_otsu(image[np.isfinite(image)]) ```
That will only pass the non-nan, non-inf pixels to Otsu to do the calculation.
Hope this helps!
Juan.
On 18 Dec 2020, at 7:19 am, Laurynas Gedminas <laurynasgedminas@gmail.com> wrote:
Hello, I have NDVI image, its not a square, and has some None values, I am trying to create otsu threshold, but getting error:
autodetected range of [nan, nan] is not finite
how to go around that?
<image.png>
Thank you,
<image.png>

Yes, you need to use `t = threshold_otsu(image[np.isfinite(image)])` in order to get rid of the nan values. Then it should work: In [1]: image = np.random.random((100, 100)) In [2]: image_nan = np.pad(image, 20, mode='constant', constant_values=np.nan) In [3]: filters.threshold_otsu(image_nan[np.isfinite(image_nan)]) Out[3]: 0.501983630941274
On 22 Dec 2020, at 12:56 am, Laurynas Gedminas <laurynasgedminas@gmail.com> wrote:
Hello Juan,
the scikit-image is 0.18 version. I think the problem is the nan values in the array? ndvi.shape (171, 169) ndvi array([[nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], ..., [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan], [nan, nan, nan, ..., nan, nan, nan]])
it also does not work with masked arrays: t3 = np.ma.masked_invalid(ndvi): <image.png> Thank you
On Fri, Dec 18, 2020 at 7:33 PM Juan Nunez-Iglesias <jni@fastmail.com <mailto:jni@fastmail.com>> wrote: Hi Laurynas,
What version of scikit-image are you using? threshold_otsu should work with arrays of any dimensionality, including 1D arrays:
In [2]: filters.threshold_otsu(np.random.random((11746,))) Out[2]: 0.4980217396247033
Juan.
On 19 Dec 2020, at 1:37 am, Laurynas Gedminas <laurynasgedminas@gmail.com <mailto:laurynasgedminas@gmail.com>> wrote:
Hey, the suggested code reshapes the original array from (171, 169) to (11746,) and does not work in otsu threshold
Thank you, Laurynas
On Thu, Dec 17, 2020 at 9:56 PM Juan Nunez-Iglesias <jni@fastmail.com <mailto:jni@fastmail.com>> wrote: Some methods, like Li, have some special handling for nan values, but that is not uniform across all our methods, as you have seen. 😂 I would suggest:
```python t = threshold_otsu(image[np.isfinite(image)]) ```
That will only pass the non-nan, non-inf pixels to Otsu to do the calculation.
Hope this helps!
Juan.
On 18 Dec 2020, at 7:19 am, Laurynas Gedminas <laurynasgedminas@gmail.com <mailto:laurynasgedminas@gmail.com>> wrote:
Hello, I have NDVI image, its not a square, and has some None values, I am trying to create otsu threshold, but getting error: autodetected range of [nan, nan] is not finite
how to go around that?
<image.png>
Thank you, <image.png>
participants (3)
-
Juan Nunez-Iglesias
-
Laurynas Gedminas
-
Ryan Avery