- What are you actually fitting and how big are your images?
- Also, have you tried LSQCURVEFIT in the Optimization Toolbox? I think you might see a speedup with it.
- Another thing to consider is how much variation do you expect in the coefficients of adjacent or near adjacent pixels? If the variation is not expected to be much, use the results from the previous iteration as your initial guess in the next iteration. This will hopefully give the optimizer a good starting point so that it can converge with fewer iterations.
- Do you really need to do this at each pixel? Downsampling by a factor of two in each dimension will get you a 4x speedup pretty effortlessly.
Optimization of FIT function in a FOR loop
7 views (last 30 days)
Show older comments
My current project work is based on processing tiff images. I have x images each of size m x n pixels.
I am using Matlab FIT function to fit a customised equation using data from all x images at each pixel (mxn). From the fit, three parameters need to be calculated.
I am using 2 for loop to calculate the fit for each pixel. The program is extremely slow (> 6 hours) during execution of the 2 for loops even with parallel processing. Preallocation is already included in the code.
Is there a way to call the FIT function just once and it executes the fitting for all pixels?
The relevant code is attached here, fitt() defines all the options for fit V1 & S1 are input parameters, X1 Y1 is dimensions of the images.
parfor i = 1:X1
[ft1, opts1] = fitt();
for j = 1:Y1
[result1, gof1] = fit(V1(:,i,j),S1(:,i,j),ft1,opts1);
A1(i,j)=result1.C3;
A2(i,j)=result1.C1;
A3(i,j)=result1.C2;
end
end
I am using Matlab version R2012a on Windows Vista OS.
Thanks
0 Comments
Answers (1)
Sean de Wolski
on 16 Aug 2013
A few questions and thoughts:
8 Comments
Matt J
on 27 Aug 2013
Edited: Matt J
on 27 Aug 2013
Hi Matt J, The Jacobian showed little improvement in time reduction.
It's more than just turning Jacobian on. There is code optimization to be done. You have to recycle the exponential expressions used in the objective function calculation when computing the Jacobian.
See Also
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!