mehta-lab / waveorder

Wave optical models and inverse algorithms for label-agnostic imaging of density & orientation.
BSD 3-Clause "New" or "Revised" License
12 stars 3 forks source link

Make "Stokes transform" consistent between full (used by QLIPP) and linear (used by PTI) Stokes polarimeters #103

Closed talonchandler closed 1 year ago

talonchandler commented 1 year ago

During development of the background corrections I've repeatedly run into the following questions:

  1. why does the Stokes transform normalize S1 & S2 by S3 for QLIPP and S0 for PTI?
  2. why are the retardance calculations for QLIPP (arctan2(sqrt(s1**2 + s2**2)*s3, s3)) and PTI (arcsin(sqrt(s1**2 + s2**2))) different?

The first question is particularly important if we're hoping to background correct and use S1, S2, and S3 downstream. For example, if we put in a unit-intensity, purely polarized Stokes vector [1, 1/sqrt(2), 1/2, 1/2] (note that S1**2 + S2**2 + S3**2 = 1) into the QLIPP path of Stokes_transform, we receive [S0, S1/S3, S2/S3, S3] = [1, sqrt(2), 1, 1/2] which yields a different retardance than the raw (already normalized) initial Stokes vector would. It seems that the QLIPP "Stokes transform" does more than just normalize...

I've realized that the two questions above are coupled, and this PR makes the "Stokes transform" and retardance calculation consistent between QLIPP and PTI.

On closer inspection, I found that the s3 normalization together with the arctan calculation gives the same retardance as an s0 normalization together with the arcsin calculation. Mathematically, $$\tan^{-1}\left(\sqrt{(s_1^2 + s_2^2)/s_3^2}\right) = \sin^{-1}(\sqrt{s_1^2 + s_2^2})$$ when $s_1^2 + s_2^2 + s_3^2 = 1$.

This equivalence allows us to always normalize by s0 and always use $\sin^{-1}(\sqrt{s_1^2 + s_2^2})$ to calculate retardance.


My first commit adds a simple test for a large range of retardances and orientations. I confirmed that these tests passed before and after the main changes in this PR: always normalize by S0, and always use the $\sin^{-1}(\sqrt{s_1^2 + s_2^2})$ to calculate retardance.

I will test this change experimentally with recOrder before merging, and I invite discussion before then.

mattersoflight commented 1 year ago

On closer inspection, I found that the s3 normalization together with the arctan calculation gives the same retardance as an s0 normalization together with the arcsin calculation. Mathematically, $$\tan^{-1}\left(\sqrt{(s_1^2 + s_2^2)/s_3^2}\right) = \sin^{-1}(\sqrt{s_1^2 + s_2^2})$$ when $s_1^2 + s_2^2 + s_3^2 = 1$.

The above assumption is the rephrasing of the assumption that the linear Stokes polarimeter assumes fully polarized light. When the light is partially polarized, $s_1^2 + s_2^2 + s_3^2 = p^2,$ when we assume that $s_1, s_2, s_3$ have been normalized by $s_0.$ Here, $p$ is the degree of polarization.

We can scale the $s_1, s_2, s_3$ by the degree of polarization per pixel before we compute the retardance to unify both code paths.

talonchandler commented 1 year ago

Closing this in favor of #110.

As @mattersoflight pointed out, the work in this branch assumed that the sample introduced no depolarization. The improved version in #110 relaxes this assumption and handles samples that are attenuating depolarizing retarders (ADRs).