- 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 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Sean de Wolski
2013년 8월 16일
A few questions and thoughts:
댓글 수: 8
Matt J
2013년 8월 27일
편집: Matt J
2013년 8월 27일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!