Integrating over an image?
You can try to improve one both sides. One issue is that smooth separable kernels $w$ or integration scheme like trapz tend to reduce rank, and pose conditioning problems. Did you use pinv or X = (A)\(b) already?


You can invest on non-separable or higher order integration rules, see for instance n-dimensional simplex quadrature;
You can invest in regularization, for instance with the simple diagonal update: $B_c = B + c*\operatorname{eye}(\operatorname{size}(B))$. If this is not sufficient, there are quantities of constrained or penalized methods (LASSO for instance), implemented for instance in the CVX toolbox (e.g. Premade solvers for specific problems (vector variables)).