Cell Phone Spectroscope: Straightening The Image

Sidetrack:

You will recall that I promised you an interesting sidetrack. When you're done, click here to get back to the spectroscope page.

You may wonder: if this is a sidetrack, why I would show it to you at all? Well, this is actually my favorite part of the project. Most of steps were actually not very difficult once I figured out what to do. Cropping a picture? Let's google "pillow python crop image". Don't get me wrong, each step took legit time to get it working, but conceptually it wasn't very challenging.

But figuring out how to analyze the data usefully to determine the parabola-of-best-fit, and then how to alter my data to remove the distortion, that required some fun mental gymnastics. I'm disappointed it didn't work out, and fixing this is on my summer to-do list.

Step 3: Straighten the Data

You probably noticed that the lines in the the original picture are curved, and wondered what I'm going to do about that. After some experimentation, which I outline below, the answer turns out to be "not a darn thing".

I did manage to straighten out the picture, and I had a good time doing it. First I had to convert the picture to an array (technically a list of lists, I think). Then I found the maximum value for each row of data and fit a parabola to the data (assuming that the data is quadratic).

Using the line of best fit, I created a scale factor for each row to shorten each row down to the same length as the middle row.

The end result looked like this:

So straight!

Alas, the actual data from the straightened picture was worse than just taking data from the middle of the unstraightened pic. So it goes.