Skip to content

Computing structural similarity between images #3502

Closed

Description

@gkiar

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!

Activity

  1. jni commented on Oct 23, 2018

    @jni
    Member

    @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.

  2. soupault commented on Oct 23, 2018

    @soupault
    Member

    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.

  3. gkiar commented on Oct 23, 2018

    @gkiar
    Author

    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:

    1. it is not rotation invariant, and
    2. 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.

    Thanks again!

  4. gkiar commented on Oct 23, 2018

    @gkiar
    Author

    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!

  5. stefanv commented on Oct 23, 2018

    @stefanv
    Member

    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?

  6. jni commented on Oct 24, 2018

    @jni
    Member

    @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.).

  7. gkiar commented on Oct 24, 2018

    @gkiar
    Author

    @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!

  8. stefanv commented on Oct 24, 2018

    @stefanv
    Member

    @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.

  9. added
    🫂 Support
    on Oct 27, 2018
  10. locked and limited conversation to collaborators on Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions