I have decided to mark this project as finished, and start a new project for version 2: a stereo polarimetric camera, with the shutters synchronized to the rotating polarization filter. I am planning to use it as a 3d scanner that combines a stereo disparity algorithm with a method that can resolve surface normals from stereo polarimetric images. By making sure that the normals from the stereo disparity match the ones from the polarimetric images, we can make a very detailed mesh, well beyond what is possible with either one of these algorithms on their own.
The prototype
The idea is simple: rotate a linear polarization filter in front of the lens and capture an image at 0, 45, 90 and 135 degrees. Then use Stokes to calculate the angle of polarization based on the difference in luminance between the 4 pictures.
Lego + Raspberry PI
I wanted to keep the build simple, but the standard way of calculating the angle and degree of polarization requires you to sync the angle of the filter with the exposure of a frame. I really wanted to use a raspberry with a HQ camera out of the box without doing any modification to the hardware in order to use an external trigger. I decided to try and generalize the math behind stokes and make it work for measurements that aren't spaced 45 degrees apart.
The math
First we state that the polarization parameters we are after (angle of polarization and degree of polarization) make up a complex number in the polar form. We multiply the real values of the 4 frames at A=0, B=45, C=90 and D=135 degrees with complex numbers at these angles with absolute value of 1. Because stokes squares the numbers, this is the same as multiplying with 1, i, -1, -i respectively, after the square of the real numbers has been taken. Taking the sum per pixel over all frames becomes A-C + i(B-D). Note how this reflects the calculation Q and U. We still have to divide by the sum of the absolute values of A,B,C and D, but that is pretty much it.
Moving the calculation to the complex domain reduces stokes to a simple sum of the frames multiplied with their filter angle, defined as a complex number. We can now generalize and take other roots of unity in the complex domain to calculate the polarization parameters for frames spaced at other intervals.
Finally, it now seems possible to have a polarization filter rotating at a certain speed, and a camera capturing at a certain framerate, and calculate the angle and degree of polarization without explicit hardware synchronization, to some extent, let's see how far we get (I'm writing this before actually fully testing the theory, there might be issues)
This is really cool :)