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
608 stars 161 forks source link

Got the same results when using ants.image_similarity with different types #479

Closed Mo-Junyang closed 1 year ago

Mo-Junyang commented 1 year ago

I am using ants.image_similarity to calculate the histogram mutual information and the Neighborhood cross correlation

import ants

x = ants.image_read(ants.get_ants_data('r16'))
y = ants.image_read(ants.get_ants_data('r30'))

mi_metric = ants.image_similarity(fixed_image=x,
                                  moving_image=y,
                                  metric_type="JointHistogramMutualInformation",)

cc_metric = ants.image_similarity(fixed_image=x,
                                  moving_image=y,
                                  metric_type="ANTsNeighborhoodCorrelation",)

but got two same results, cc_metric = mi_metric. Should they be the same? Is there anything wrong between these two metric_type?

BTW, is this function corresponding to MeasureImageSimilarity in ANTs?

cookpa commented 1 year ago

I think you might be seeing 'JointHistogramMutualInformation' for both cases.

The underlying library function compares the metric_type to the different options by the "==" operator. This might be getting confused by different encoding of Python and C++ strings.

https://github.com/ANTsX/ANTsPy/blob/c5c6b6e526a5389b35acac79b21e46d123f0fa25/ants/lib/LOCAL_antsImageToImageMetric.h#L306

I'm not sure of the best solution but will look into it.

The function appears to not call the ANTs MeasureImageSimilarity program directly, but it might produce the same results nonetheless because it evaluates the same metrics.

Mo-Junyang commented 1 year ago

I think you might be seeing 'JointHistogramMutualInformation' for both cases.

The underlying library function compares the metric_type to the different options by the "==" operator. This might be getting confused by different encoding of Python and C++ strings.

https://github.com/ANTsX/ANTsPy/blob/c5c6b6e526a5389b35acac79b21e46d123f0fa25/ants/lib/LOCAL_antsImageToImageMetric.h#L306

I'm not sure of the best solution but will look into it.

The function appears to not call the ANTs MeasureImageSimilarity program directly, but it might produce the same results nonetheless because it evaluates the same metrics.

If you figure out how to get the 'ANTsNeighborhoodCorrelation' metric, please let me know, thank you so much!

cookpa commented 1 year ago

Looks like it's not string encoding because pybind11 takes care of that

https://pybind11.readthedocs.io/en/stable/advanced/cast/strings.html

The weird thing is other metric return different values, MeanSquares, Correlation, MattesMutualInformation are all unique. But ANTsNeighborhoodCorrelation is wrong somehow

cookpa commented 1 year ago

It's a typo!

Try "ANTSNeighborhoodCorrelation" not "ANTsNeighborhoodCorrelation". I'll work on making this not silently fail

cookpa commented 1 year ago

Actually ANTSNeighborhoodCorrelation won't work, but I'll fix that

Mo-Junyang commented 1 year ago

@cookpa I am looking forward to it. Thanks again for your help!