Answers.Body: <p>From the original paper, you can see that the authors uses the dynamic range of the image in the computation of C.</p>
  <p><a href="https://i.sstatic.net/iVnKF5Bj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iVnKF5Bj.png" alt="enter image description here" /></a></p>
  <p>Link: <a href="https://ieeexplore.ieee.org/document/1284395" rel="nofollow noreferrer">https://ieeexplore.ieee.org/document/1284395</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-17T11:48:34.763Z
Answers.Text: So those values (min and max) come into play when C is calculated?
Answers.UserDisplayName: FluidMechanics Potential Flows
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-21T22:35:13.710Z
Answers.Text: Exactly. L is there to put C in a valid range for the pixel values of the image.
Answers.UserDisplayName: Fab G
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-15T22:14:39.547Z
Answers.LastActivityDate: 2024-07-15T22:14:39.547Z
Answers.UserDisplayName: Fab G
Body: <p>The SSIM metric (<a href="https://en.wikipedia.org/wiki/Structural_similarity_index_measure" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Structural_similarity_index_measure</a>) formulas do not seem to depend on the range of the values the pixel have (from 0 to 1, from 0 to 255, or any other normalization).</p>
  <p>I want to use the SSIM metric for my pytorch model as a loss (by doing <code>len(batch)*(1-SSIM(X,Y,size_average=True))</code>), therefore I'm using the <code>pytorch-mssim</code> library (<a href="https://github.com/VainF/pytorch-msssim" rel="nofollow noreferrer">https://github.com/VainF/pytorch-msssim</a>). The formulas are consistent with what I can see on Wikipedia however, the class <code>SSIM</code> has an argument <code>data_range</code> which I do not understand since it should not affect the result of the SSIM metric. Especially since in my case I use percentile normalization and hence do not know my <code>data_range</code> in advance.</p>
  
Tags: <deep-learning><pytorch><ssim>
Title: Why does SSIM in pytorch-mssim need the data range to be specified?
UserDisplayName: FluidMechanics Potential Flows
ThreadText: # Why does SSIM in pytorch-mssim need the data range to be specified?
  
  (Asked by: username_0 on 2024-04-06)
  
  The SSIM metric (<https://en.wikipedia.org/wiki/Structural_similarity_index_measure>) formulas do not seem to depend on the range of the values the pixel have (from 0 to 1, from 0 to 255, or any other normalization).
  
  I want to use the SSIM metric for my pytorch model as a loss (by doing `len(batch)*(1-SSIM(X,Y,size_average=True))`), therefore I'm using the `pytorch-mssim` library (<https://github.com/VainF/pytorch-msssim>). The formulas are consistent with what I can see on Wikipedia however, the class `SSIM` has an argument `data_range` which I do not understand since it should not affect the result of the SSIM metric. Especially since in my case I use percentile normalization and hence do not know my `data_range` in advance.
  
  **Tags:** deep-learning, pytorch, ssim
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-07-15. Score: 0 | Accepted answer
  
  From the original paper, you can see that the authors uses the dynamic range of the image in the computation of C.
  
  [![enter image description here](https://i.sstatic.net/iVnKF5Bj.png)](https://i.sstatic.net/iVnKF5Bj.png)
  
  Link: <https://ieeexplore.ieee.org/document/1284395>
  
  > **Comments:**
  > **username_0**: So those values (min and max) come into play when C is calculated?  
  > **username_1**: Exactly. L is there to put C in a valid range for the pixel values of the image.  
  
  ---
  
  