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
Computing structural similarity between images #3502
I am trying to compare 3D images using SSIM, and finding expected results (nearly identical images are more similar than those with greater differences).
What I was unable to glean from the SSIM documentation, however, (as the documentation is in 2d) is how is the 3rd dimension handled? Additionally how would this scale to a 4th dimension, such as time? Thanks so much for your time and help!
@gkiar if multichannel=True, the third dimension is treated as "colours", and the structural similarity is the mean of the single-channel structural similarity computed over each channel separately. This happens here.
If multichannel=False (the default), then the structural similarity is computed over all dimensions identically. The structural similarity works by comparing images pixel-by-pixel and computing their variances and covariances, so it really doesn't make any difference whether the image is 2D, 3D, 4D, or 15D. What matters is the pixel-pixel correspondence between the test image and the reference image. See the Wikipedia page for more info. Note that in the wikipedia page, x and y are two different images, rather than two coordinate axes.
When in doubt, check the source code! If you think the documentation could be clearer about all this, please feel free to contribute a pull request!
Additionally, I think that adding non-square windows would be a very useful contribution for 3D images where the resolution is different between different axes.
I'd add to the above that, generally, we don't have a support for time dimension.
If such dimension in your problem can be treated as a spatial one, and a function of interest works with nD input, then you are all set. If not, you should build a custom solution on top of the provided API.
Hi @jni@soupault, thank you both for your quick and helpful responses! That clarifies a lot for me. In fact, this helped me realize that SSIM may actually not be what I want to use for two reasons:
it is not rotation invariant, and
it requires images to be of equal sizes.
Though you've certainly already clarified my original question enough, I was wondering if you had recommendations for comparing images that are structurally similar, though they may be rotated (in 3D) and have slightly differing dimensions.
And to clarify my last question a bit further - I would rather not do anything as dramatic as image registration, as that can be quite computationally expensive and is in fact an example of a processing step I'd like to evaluate using <insert image metric here>. Mutual information came to mind, but I'm unaware of an implementation in scikit-image. Thanks!
@stefanv mutual information is also computed pixel-wise and not rotationally invariant though?
But @gkiar, on the other hand, clearly you don't want to evaluate registration using a scale and rotation invariant metric, because then the registration step can't affect the metric, so your requirements appear to be in conflict?
@stefanv yes, lots of metrics need to make it into skimage. See #3354 for example. =) It's high on my to do list. We need to settle on a consistent API though (e.g. does the "true" image come first or second, what do we name the "true"/"reference" image vs the "test"/"target" image, etc.).
@jni thanks for your comment - I didn't want to dive too deep into the specific use case, but I'm not trying to evaluate the quality of the registration in terms of fit, we have other metrics for that, but various processing steps in terms of the distortion they introduce due to things like interpolation (in the case of registration), or other things (in the case of other processing steps).
Is mutual information pixelwise and non rotationally invariant? I understood it as an evaluation of the shared entropy of pixel intensities over entire images, which I understood to then be independent from the locations of those pixels.
@jni The reference image comes first, of course ;)
W.r.t. mutual information: it is approximately invariant to mutual rotations in both images. Importantly for this use case, it does not match on a pixel-by-pixel basis. True, when the two images align, the mutual information will drop, but even two images that have slight relative rotations should have lower mutual information than if compared with entirely different content.
Activity
jni commentedon Oct 23, 2018
@gkiar if
multichannel=True, the third dimension is treated as "colours", and the structural similarity is the mean of the single-channel structural similarity computed over each channel separately. This happens here.If
multichannel=False(the default), then the structural similarity is computed over all dimensions identically. The structural similarity works by comparing images pixel-by-pixel and computing their variances and covariances, so it really doesn't make any difference whether the image is 2D, 3D, 4D, or 15D. What matters is the pixel-pixel correspondence between the test image and the reference image. See the Wikipedia page for more info. Note that in the wikipedia page,xandyare two different images, rather than two coordinate axes.When in doubt, check the source code! If you think the documentation could be clearer about all this, please feel free to contribute a pull request!
Additionally, I think that adding non-square windows would be a very useful contribution for 3D images where the resolution is different between different axes.
soupault commentedon Oct 23, 2018
I'd add to the above that, generally, we don't have a support for time dimension.
If such dimension in your problem can be treated as a spatial one, and a function of interest works with nD input, then you are all set. If not, you should build a custom solution on top of the provided API.
gkiar commentedon Oct 23, 2018
Hi @jni @soupault, thank you both for your quick and helpful responses! That clarifies a lot for me. In fact, this helped me realize that SSIM may actually not be what I want to use for two reasons:
Though you've certainly already clarified my original question enough, I was wondering if you had recommendations for comparing images that are structurally similar, though they may be rotated (in 3D) and have slightly differing dimensions.
Thanks again!
gkiar commentedon Oct 23, 2018
And to clarify my last question a bit further - I would rather not do anything as dramatic as image registration, as that can be quite computationally expensive and is in fact an example of a processing step I'd like to evaluate using <insert image metric here>. Mutual information came to mind, but I'm unaware of an implementation in scikit-image. Thanks!
stefanv commentedon Oct 23, 2018
Mutual information sounds like what you need. You can see an implementation here: https://github.com/elegant-scipy/elegant-scipy/blob/master/markdown/ch7.markdown (may need to be tweaked for N-D).
@jni: Time to add this to skimage?
jni commentedon Oct 24, 2018
@stefanv mutual information is also computed pixel-wise and not rotationally invariant though?
But @gkiar, on the other hand, clearly you don't want to evaluate registration using a scale and rotation invariant metric, because then the registration step can't affect the metric, so your requirements appear to be in conflict?
@stefanv yes, lots of metrics need to make it into skimage. See #3354 for example. =) It's high on my to do list. We need to settle on a consistent API though (e.g. does the "true" image come first or second, what do we name the "true"/"reference" image vs the "test"/"target" image, etc.).
gkiar commentedon Oct 24, 2018
@jni thanks for your comment - I didn't want to dive too deep into the specific use case, but I'm not trying to evaluate the quality of the registration in terms of fit, we have other metrics for that, but various processing steps in terms of the distortion they introduce due to things like interpolation (in the case of registration), or other things (in the case of other processing steps).
Is mutual information pixelwise and non rotationally invariant? I understood it as an evaluation of the shared entropy of pixel intensities over entire images, which I understood to then be independent from the locations of those pixels.
Thank you very much for your continued help!
stefanv commentedon Oct 24, 2018
@jni The reference image comes first, of course ;)
W.r.t. mutual information: it is approximately invariant to mutual rotations in both images. Importantly for this use case, it does not match on a pixel-by-pixel basis. True, when the two images align, the mutual information will drop, but even two images that have slight relative rotations should have lower mutual information than if compared with entirely different content.