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
Make unwrap_phase
fail for 2D input containing NaNs
#7176
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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
pivot
being NaN. Current solution is to checkpivot
before passing it to that function and return error codes up the call stack until we can raise a proper Python exception.Checklist
./doc/examples
for 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: