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

The function skimage.util.compare_images fails silently if called with integers matrices #7331

Open
Hish15 opened this issue Feb 29, 2024 · 1 comment
Labels

Comments

@Hish15
Copy link

Hish15 commented Feb 29, 2024

Description:

I was trying to call the skimage.util.compare_images with integers matrices (the documentation does not prevent this).
The function does return a value, but not the expected one.
I found out that the function skimage.util.img_as_float32 called in skimage.util.compare_images does not convert the int matrix to a float matrix as expected, resulting into a wrong return value for compare_images.

Way to reproduce:

import skimage.util as skiu

mat_a = skiu.img_as_float32([[1.0, 1.0], [1.0, 1.0]])
mat_b = skiu.img_as_float32([[1, 1], [1, 1]])
mat_c = skiu.compare_images(mat_a, mat_b, method='diff')

assert mat_a[0][0] == 1.0 # OK
assert mat_b[0][0] == 1.0 # Will fail
assert mat_c[0][0] == 0 #Will fail too

Version information:

3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
Linux-4.4.0-22621-Microsoft-x86_64-with-glibc2.36
scikit-image version: 0.22
@mkcor
Copy link
Member

mkcor commented Mar 11, 2024

Right, it looks like the issue stems from skimage.util.img_as_float (or, likewise, skimage.util.img_as_float32), since:

import numpy as np
import skimage as ski

arr = np.array([[1, 1], [1, 1]])
ski.util.img_as_float(arr)
# array([[1.08420217e-19, 1.08420217e-19],
#        [1.08420217e-19, 1.08420217e-19]])
ski.util.img_as_float32(arr)
# array([[1.0842022e-19, 1.0842022e-19],
#        [1.0842022e-19, 1.0842022e-19]], dtype=float32)

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

2 participants