# Understanding flow code

Hi!

I have actually bought a PX4FLOW. It is the first time I work with image processing and I am really interested of knowing about how it works. I have been trying to understand the code but I have some questions.
My problem is not the sintaxis of the code (I can find it on the internet), what I don’t understand is the use/ utility of some functions. I think that with a short definition of some functions should be enough to start understanding everything.

I know that it is based on SAD algorithm which takes the sum of the absolute diferences on each pixel. I have seen that the lower is the sum, the more similar are the 2 images. The functions I don’t understand are the next ones:

1.-

I think it is doing the SAD algorithm taking the difference on the images?

2.-

Why it is a 4x4 pattern taken?
I have been reading about why is interesting to take the average pixel gradient but I continue without understanding why is so interesting and why it is used for knowing if the pixel is suitable for flow tracking:

I think I understand this function : It does the SAD algorithm for a 8x8 pattern taken from the two photos of (188*120). It only takes a 8x8 pattern to make the process quicklier and computable, isn’t it?. For analyzing the pixels, it analyze each bit of each pixel and takes de diference with the other image, so the ABSDIFF of EACH BIT of EACH PIXEL should be 1 or 0? It takes a lot of different 8x8 patterns of each photo?

I can see the difference from the above function. Isn’t the SAD computation done in the previous step function? Why it is doing again the SAD compute?

That’s all, I think if I understand what this functions are used for (Not how are done, why are used) I will be able to understand everything. I have surfing on the internet and I think I understand SAD algorithm, but I don know how it is implemented.