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

Gaussian smooth fails with float32 #145

Open
blazzter opened this issue Jul 27, 2017 · 2 comments
Open

Gaussian smooth fails with float32 #145

blazzter opened this issue Jul 27, 2017 · 2 comments
Labels

Comments

@blazzter
Copy link

blazzter commented Jul 27, 2017

if I have object:

data = np.random.rand(200,200)
data = data.astype('float32')
hs_data = hs.signals.Signal2D(data)
hs_data.plot()

and apply Gaussian filter, it fails with:

Traceback (most recent call last):
File "/home/mkrajnak/.local/lib/python3.5/site-packages/hyperspyui/plugins/gaussianfilter.py", line 198, in set_preview
self.update()
File "/home/mkrajnak/.local/lib/python3.5/site-packages/hyperspyui/plugins/gaussianfilter.py", line 216, in update
record=False, out=out)
File "/home/mkrajnak/.local/lib/python3.5/site-packages/hyperspyui/plugins/gaussianfilter.py", line 112, in gaussian
im_o[:] = gaussian(im_i, sigma, *args, **kwargs)
File "/home/mkrajnak/.local/lib/python3.5/site-packages/skimage/filters/_gaussian.py", line 118, in gaussian
image = convert_to_float(image, preserve_range)
File "/home/mkrajnak/.local/lib/python3.5/site-packages/skimage/_shared/utils.py", line 243, in convert_to_float
image = img_as_float(image)
File "/home/mkrajnak/.local/lib/python3.5/site-packages/skimage/util/dtype.py", line 336, in img_as_float
return convert(image, np.float64, force_copy)
File "/home/mkrajnak/.local/lib/python3.5/site-packages/skimage/util/dtype.py", line 236, in convert
raise ValueError("Images of type float must be between -1 and 1.")
ValueError: Images of type float must be between -1 and 1.

Any clue?

@blazzter blazzter changed the title Gaussian smooth fails with float32 in specific case Gaussian smooth fails with float32 Jul 27, 2017
@francisco-dlp
Copy link
Member

I think that you've found a bug: in order to make the data palatable for skimage's gaussian filter, the plugin normalises the data making the (wrong) assumption that vmax - vmin > 1.

This can be easily fixed but, @vidartf. why not using ndimage's gaussian filter instead which doesn't require renormalising the images?

@vidartf
Copy link
Member

vidartf commented Jul 28, 2017

why not using ndimage's gaussian filter instead which doesn't require renormalising the images?

If I remember correctly, this might have been a performance issue. The blur should be fast in order to be responsive when interactively changing the sigma.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants