ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
597 stars 160 forks source link

Problem with using ants.image_similarity #497

Open Mo-Junyang opened 11 months ago

Mo-Junyang commented 11 months ago

Hi there, it's me again, I am using ants.image_similarity to evaluate the 'mi' and 'cc' between two image And I want to know what's the value range of these two metric: ANTSNeighborhoodCorrelation JointHistogramMutualInformation

import ants
import numpy as np
img = ants.from_numpy(np.random.randn(20, 20, 20))
ants.image_similarity(img,img,metric_type="ANTSNeighborhoodCorrelation")
# return: -1.0
ants.image_similarity(img,img,metric_type="JointHistogramMutualInformation")
# return: -0.24074076116085052
img = ants.from_numpy(np.random.randn(20,20,20))
ants.image_similarity(img,img,metric_type="JointHistogramMutualInformation")
# return: -0.19555595517158508

I've read the document and found out that the function returns the distance, so it makes sense that same pictures' CC return -1. But how about the mi metric? Same images return a value in [-1,0]. And the value changes with the image value changing. What is the best value of these metrics? If I want to print the similarity, what should I do? Do print(-ants.image_similarity(...))?

ntustison commented 11 months ago

But how about the mi metric?

There's no absolute scale as with CC.

Mo-Junyang commented 11 months ago

But how about the mi metric?

There's no absolute scale as with CC.

What does it mean? I thought the closer CC is to -1, the higher the similarity. (AM I RIGHT? ). So I want to know the rule of MI, and why two groups of same images will have different MI metrics? Thank you very much!

ntustison commented 11 months ago

What does it mean?

If you're looking for a standard scaling as in CC, it doesn't exists for MI. I would encourage you to read more about the MI measure itself (not necessarily in the context of image registration) to get answers to your question.

I thought the closer CC is to -1, the higher the similarity. (AM I RIGHT? )

For the ITK image similarity measure, yes, CC = -1 is the maximal similarity.

So I want to know the rule of MI

Again, see above. There is no simple rule like CC. Please read more on the MI metric.

Mo-Junyang commented 11 months ago

Again, see above. There is no simple rule like CC. Please read more on the MI metric.

I've read some doc about MI, And I've been told that MI yields value from 0 to +∞, where 0 means A and B are independent. The higher the MI, the more information is shared between 2 images, the higher the similarity. But why ants.image_similariity usually returns a negative value? I just wanna know how can I evaluate the similarity of images by MI using ants.image_similariity. And is there any method like sklearn.metric.normalized_mutual_info_score that can scale the value into [0,1]?

stnava commented 11 months ago

in ANTs (and possibly ITK) - similarity increases with lower values of the metric - for all metrics. You can multiply by negative one if you want the opposite standard.

normalized mutual information is a different metric than (standard) mutual information.