You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
metrics.structural_similarity: win_size is not ignored if gaussian_weights is set to True #7231
Based on the documentation of structural_similarity parameter win_size should be ignored if parameter gaussian_weights is set to True. The reasoning is that if gaussian_weights is True, then win_size is calculated from sigma.
However, if win_size set to any valid integer, the important value setting if branch is skipped at line 169. (Still the code is working properly if win_size is None)
Later win_size is used unconditionally for calculating pad (line 254) and could be used if use_sample_covariance is set to True (line 222-226.).
Using the following images the results are changing depending on whether win_size is set to None or set to a valid integer. (While based on the documentation I expected no change in the results.)
Way to reproduce:
importskimageim1=skimage.io.imread("~/img/camera.png")
im2=skimage.io.imread("~/img/camera_noisy.png")
ssim_without_win_size=skimage.metrics.structural_similarity(im1, im2, gaussian_weights=True, win_size=None)
#By documentation win_size should be ignored is gaussian_weights is set to True...ssim_with_win_size=skimage.metrics.structural_similarity(im1, im2, gaussian_weights=True, win_size=101)
print(ssim_without_win_size) #0.3654599419036462print(ssim_with_win_size) #0.3890367780407127#...but it did change the value.
Version information:
3.12.0 | packaged by conda-forge | (main, Oct 3 2023, 08:43:22) [GCC 12.3.0]
Linux-5.4.0-165-generic-x86_64-with-glibc2.31
scikit-image version: 0.23.0rc0.dev0+git20231030.c2725eaba
numpy version: 1.26.0
Thanks for reporting, @anwolosz! I would be tempted to fix the docstring, replacing "If gaussian_weights is True, this is ignored and the window size will depend on sigma." with "If gaussian_weights is True and win_size is None, the window size will depend on sigma."
Otherwise, changing the code will introduce a breaking change, but maybe this would be the healthier way to go? I haven't written the function and I'm not sure how to interpret setting gaussian_weights to True:
is it meant to 'overwrite' anything else (here, the win_size value)?
is it meant as a 'fallback' (here, for the case when win_size isn't specified)?
I'd like to ask my fellow @scikit-image/core members for their opinion.
cov_norm=1.0# population covariance to match Wang et. al. 2004
seem relevant. Regardless of gaussian_weights, win_size might affect the result via cov_norm if use_sample_covariance=True. I have no idea about the implications of a mismatching win_size and sigma, so not sure what to do with this information either.
Unless someone more knowledgeable chimes in I'd go with your suggestion @mkcor. And maybe add a warning, in case a weird win_size is given with gaussian_weights=True...
@grlee77, pinging you as the author of #1511 in case you have time and context. 🤞
Hello scikit-image core devs! There hasn't been any activity on this issue for more than 180 days. I have marked it as "dormant" to make it easy to find.
To our contributors, thank you for your contribution and apologies if this issue fell through the cracks! Hopefully this ping will help bring some fresh attention to the issue. If you need help, you can always reach out on our forum
If you think that this issue is no longer relevant, you may close it, or we may do it at some point (either way, it will be done manually).
Activity
mkcor commentedon Nov 7, 2023
Thanks for reporting, @anwolosz! I would be tempted to fix the docstring, replacing "If
gaussian_weightsis True, this is ignored and the window size will depend onsigma." with "Ifgaussian_weightsis True andwin_sizeis None, the window size will depend onsigma."Otherwise, changing the code will introduce a breaking change, but maybe this would be the healthier way to go? I haven't written the function and I'm not sure how to interpret setting
gaussian_weightsto True:win_sizevalue)?win_sizeisn't specified)?I'd like to ask my fellow @scikit-image/core members for their opinion.
Also, noticing:
scikit-image/skimage/metrics/_structural_similarity.py
Line 175 in 441fe68
lagru commentedon Nov 11, 2023
I am not familiar at all with algorithm and implementation but this lines
scikit-image/skimage/metrics/_structural_similarity.py
Lines 169 to 175 in 441fe68
scikit-image/skimage/metrics/_structural_similarity.py
Lines 222 to 228 in 441fe68
seem relevant. Regardless of
gaussian_weights,win_sizemight affect the result viacov_normifuse_sample_covariance=True. I have no idea about the implications of a mismatchingwin_sizeandsigma, so not sure what to do with this information either.Unless someone more knowledgeable chimes in I'd go with your suggestion @mkcor. And maybe add a warning, in case a weird
win_sizeis given withgaussian_weights=True...@grlee77, pinging you as the author of #1511 in case you have time and context. 🤞
github-actions commentedon May 10, 2024
Hello scikit-image core devs! There hasn't been any activity on this issue for more than 180 days. I have marked it as "dormant" to make it easy to find.
To our contributors, thank you for your contribution and apologies if this issue fell through the cracks! Hopefully this ping will help bring some fresh attention to the issue. If you need help, you can always reach out on our forum
If you think that this issue is no longer relevant, you may close it, or we may do it at some point (either way, it will be done manually).
Fix structural_similarity win_size / gaussian_weights conflict (#8162)