RX Algorithm in C

Earlier this year I was trying to learn more C by working on a project formerly left over from drone club. After a couple weeks of toiling with memory leaks (Valgrind is an awesome tool), I finally came up with an implementation of the RX algorithm that's almost fast enough to be useful on a drone for basic anomaly detection.

The code is hosted on GitHub, and I welcome suggestions for improvements as C is definitely not my first language. I suspect there are many memory improvements that could be made; nevertheless, it can compute the Mahalanobis metric on one million RGB vectors in about 1/5 of a second.

As a test, I created the following video from data collected by Terry Sims. Even 4K frames only take about 2s to compute on my modest laptop.
The hardest part was probably figuring out how to read images from disk with libpng. I mostly read through the example.c file to understand how this library works.

I understand now that file specifications/formats are extremely intricate and specific, i.e. every single byte has a meaning, and it's easy to misinterpret that meaning if the functions aren't configured correctly.