0
votes

I have a 3D image V. For each pixel v in this 3D image, I need to minimize a function

(Y1 - F1(x1, x2))^2 + (Y2 - F2(x1, x2))^2

Y1 and Y2 are two observations. F1 and F2 are non-linear functions, derivable, but in a complicated form. x1 and x2 are two unknowns.

I know how to solve this problem pixel by pixel using lsqnonlin or lsqcurvefit in matlab. But it was so slow. Anyone can tell me how to solve this problem in the whole image? Thank you in advance.

2
What are Y1 and Y2 in terms of the pixel data? RGB values?Buck Thorn
It seems you know how F1 and F2 behave. Why not calculate them for a lot of points, look at the results and check whether you can find the optimum? If you are sure they are in a certain area you can repeat the process with a lot of points in that area.Dennis Jaheruddin
Not RGB. Signal intensities.f. c.
Yes, I know F1 and F2. The forms are fixed for all pixels. But what do you mean "calculate them for a lot of points"? how?f. c.
Following up on what @DennisJaheruddin commented, perhaps you can discretize the problem and set up a look up table in advance.Buck Thorn

2 Answers

2
votes

First of all, I think you should try fminsearch. It is designed for this kind problem.

If fminsearch cannot help you, but you know something about how they behave, you can try using a manual quantitative approach (just calculating it at a lot of points and see if it behaves well).

If your functions can handle vectorized inputs, it can be done like this:

vec1 = 0:0.1:10; %Assume you expect it somewhere between 0 and 10
vec2 = 0:0.1:10;
[x1, x2] = ndgrid(vec1, vec2); 
result = (Y1 - F1(x1, x2))^2 + (Y2 - F2(x1, x2))^2

If this does not work, you can do this:

horzcount = 0;
for x1 = vec1
   horzcount = horzcount +1;
   vertcount = 0;
   for x2 = vec2
      vertcount = vertcount + 1;
      result(horzcount, vertcount) = (Y1 - F1(x1, x2))^2 + (Y2 - F2(x1, x2))^2;
   end
end

Afterwards look at the result (use surf on an area or plot on a row or column) and determine whet you are satisfied to have found the region that contains the optimum. Then zoom in on that region by adjusting vec1 and vec2 accordingly untill you have achieved sufficient precision.

1
votes

Following up on @DennisJaheruddin's answer, there is some point at which a grid search is less computationally expensive than minimization of an objective function using simplex, and occurs even for small images if evaluating functions F1,F2 is much more costly than performing the arithmetic to compute the objective function (for F1, F2 precalculated)

I would first get an idea of the solution range and required precision of the solution values, then compute vec1 and vec2 as proposed by @DennisJaheruddin, as vectors spanning the range, and precompute F1(x1, x2) and F2(x1, x2)

Then for each point find

Imin = min((Y1 - F1).^2 + (Y2 - F2).^2)

Looks like this can be vectorized. The solutions Imin index into the original grid so you can figure out X1min and X2min at each pixel.