up42 / image-similarity-measures

:chart_with_upwards_trend: Implementation of eight evaluation metrics to access the similarity between two images. The eight metrics are as follows: RMSE, PSNR, SSIM, ISSM, FSIM, SRE, SAM, and UIQ.
MIT License
550 stars 68 forks source link

ISSM metric does not work #34

Closed mamunTomal closed 2 years ago

mamunTomal commented 2 years ago

The following error shows up and returns ISSM=0

site-packages/image_similarity_measures/quality_metrics.py:146: RuntimeWarning: divide by zero encountered in log2 return -np.sum(np.nan_to_num(H * np.log2(H)))

chrieke commented 2 years ago

Hi @mamunTomal, thanks for reporting. I can reproduce the RuntimeWarning, however the evaluation metric is still correctly reported. Could you give more detail on how you are using the package?

Safiullahmarwat commented 2 years ago

Hi @chrieke the same error I am receiving.

D:\quality_metrics.py:160: RuntimeWarning: divide by zero encountered in log2
  return -np.sum(np.nan_to_num(H * np.log2(H)))
D:\quality_metrics.py:160: RuntimeWarning: invalid value encountered in multiply
  return -np.sum(np.nan_to_num(H * np.log2(H)))
D:\quality_metrics.py:177: RuntimeWarning: invalid value encountered in double_scalars
  return numerator / denominator
Out[9]: 0.0 

I printed H matrix, and it is a 10x10 matrix with some zero elements. My python version is 3.7, using via import, and the error occurs for every test images.

mamunTomal commented 2 years ago

Hi @chrieke I received the same error as shown by @Safiullahmarwat. I used python 3.6 and 3.7 in different environments. The CLI was used in Pycharm. I later resorted to write my own code in Matlab and got the results from there. I plan to share the matlab implementation of ISSM once I am sure it is bug free.

Safiullahmarwat commented 2 years ago

Hi @mamunTomal can you please share the values you used for thresholds? as in this code

g = cv2.Canny((x* 0.0625).astype(np.uint8), 100, 200)
h = cv2.Canny((y* 0.0625).astype(np.uint8), 100, 200)

here g and h, both are zero valued matrices. I think this is the issue. It seems like other quality functions, the author have imagined the image to be 12bit imagery. for other functions, i replaced the value of 4095 with 255, as I am using 8 bit images. dont know how to replace the value 0.0625. [Update] I just removed 0.0625 and kept the original type (as the original type is also uint8) and it worked for me. Thank you the author such a great work.

g = cv2.Canny(x, 100, 200)
h = cv2.Canny(y, 100, 200)
nikooc2s commented 2 years ago

I am happy that it is resolved. We need to be more clear that we first implemented this library considering satellite images with physical values (e.g. surface or top-of-the-atmosphere products with some sort of corrections) for each pixel which can be captured with 12bits numbers. (Note that the end product is in 16bit because computers are optimized to deal with 8, 16, or 32 bit numbers).

nikooc2s commented 2 years ago

@chrieke Also this one, can you close it. Thanks!