Here is my problem:
I have an image divided into segments. Each segment consists of pixels with coordinates (x,y) called vector $v$, each pixel has a length 3 vector RGB called $I(v)$. I want to find an affine matrix (3x3) $A$ which minimises $I(v) - A[v^T 1]^T$, however not just for the pixel, but for the whole segment. This means that the minimisation equation becomes $\sum\limits_{v \in segment}||I(v) - A[v^T 1]^T ||^2$.
How would I go about minimising this? Preferably with functions in numpy/scipy or similar (e.g. MATLAB/Octave).