Repository navigation
Conversation
It seems that the infinite loop happens inside the function `partition` which never exits due to `pivot` being NaN. So check `pivot` before passing it to that function and return error codes up the call stack until we can raise a proper Python exception. Not sure if that is the best way to address the problem. I understand little of what's going on, but it's better than hanging with one core stuck at 100%. Performance wise I didn't see any significant impact for the following snippet taken from plot_phase_unwrap.py: ```python import numpy as np from skimage import data, img_as_float, color, exposure from skimage.restoration import unwrap_phase image = color.rgb2gray(img_as_float(data.chelsea())) image = exposure.rescale_intensity(image, out_range=(0, 4 * np.pi)) image_wrapped = np.angle(np.exp(1j * image)) %timeit unwrap_phase(image_wrapped) ```
| if (isnan(pivot)) { | ||
| return NAN_ERROR; | ||
| } |
There was a problem hiding this comment.
Not sure if that is the best way to address the problem. I understand little of what's going on, but it's better than hanging with one core stuck at 100%. Performance wise I didn't see any significant impact for the following snippet taken from plot_phase_unwrap.py:
import numpy as np
from skimage import data, img_as_float, color, exposure
from skimage.restoration import unwrap_phase
image = color.rgb2gray(img_as_float(data.chelsea()))
image = exposure.rescale_intensity(image, out_range=(0, 4 * np.pi))
image_wrapped = np.angle(np.exp(1j * image))
%timeit unwrap_phase(image_wrapped)Though I am a bit dubious because the paper makes it seem like there should be a huge amount of edges and I am not sure how often quicker_sort is called in the total scheme of things.
|
Ugh, this snippet (from #3831 (comment)) still fails import numpy as np
from skimage.restoration import unwrap_phase
wrapped = np.empty((100, 100), dtype=np.float64)
wrapped[:] = np.linspace(0, 4*np.pi, 100) % (2*np.pi)
wrapped[10, 10] = np.nan # <-- comment out to get working code
masked = np.ma.masked_array(wrapped, mask=np.isnan(wrapped))
print(np.isnan(masked).any())
unwrapped = unwrap_phase(masked) |
|
Hello scikit-image core devs! There hasn't been any activity on this PR for more than 180 days. I have marked it as "dormant" to make it easy to find. |
|
I wonder whether we should generalize this, to allow NaN to be identical to a mask, and do something like: before passing into the C routines? @lagru - what do you think? |
|
Superseded by #8193. |
Fixes #3831. Mask any NaNs in the image. This is a more general fix than in #7176. ```release-note `unwrap_phase` now handles input images with NaN values, by taking the NaN values to be an implicit mask. Previously, the NaN values could cause the code to hang. Closes #3831. ``` --------- Co-authored-by: Lars Grüter <[email protected]>
Fixes #3831. Mask any NaNs in the image. This is a more general fix than in #7176. Co-authored-by: Lars Grüter <[email protected]> -- Ported from #8193 on pre-megamove-integration (af098de) Assisted-by: claude-code:claude-opus-5 Co-authored-by: Matthew Brett <[email protected]>
Fixes scikit-image#3831. Mask any NaNs in the image. This is a more general fix than in scikit-image#7176. ```release-note `unwrap_phase` now handles input images with NaN values, by taking the NaN values to be an implicit mask. Previously, the NaN values could cause the code to hang. Closes scikit-image#3831. ``` --------- Co-authored-by: Lars Grüter <[email protected]>
Description
Closes #3831.
After some stone-age debugging with print statements, it seems to me that the infinite loop happens inside
scikit-image/skimage/restoration/unwrap_2d_ljmu.c
Lines 128 to 139 in 97b3ecb
which never exits due to
pivotbeing NaN. Current solution is to checkpivotbefore passing it to that function and return error codes up the call stack until we can raise a proper Python exception.Checklist
./doc/examplesfor new featuresRelease note
Summarize the introduced changes in the code block below in one or a few sentences. The
summary will be included in the next release notes automatically: