How do I fit an arbitrary function to data using LSQNONLIN ?
5 次查看(过去 30 天)
显示 更早的评论
hi I'm trying to find image's rotation and translation and scale compare to a reference image.so first I rotate one picture to examine my code. so we have to image first a reference image that we name it ydata and a rotated image that we name it xdata. so our work is to find the amount of rotation. we are using Llevenberg-Mqrquardt optimization scheme so first, I wrote rotation, translation,and scale function:
function [raw_matrix] = RST_n_n( dis_R,tx,ty,r,s )
%dis_R=distorted image
%tx,ty=translation x va y
%r = rotation
% S=scale
[dis_R_x,dis_R_y]=size(dis_R);
raw_matrix=zeros(dis_R_x,dis_R_y);
RTS_M=[s*cos(r),s*sin(r),tx;-s*sin(r),s*cos(r),ty;0,0,1];
for i=1:dis_R_x
for j=1:dis_R_y
RTS_MM=RTS_M*[i;j;1];
xx=round(RTS_MM(1));
yy=round(RTS_MM(2));
if xx>dis_R_x |xx<=0| yy>dis_R_y | yy<=0
xx=400;
raw_matrix(i,j)=0;
else
raw_matrix(i,j)=dis_R(xx,yy);
% raw_matrix=raw_matrix(:)
end
end
end
end
my function is completely work.i test it son i used lsqcurvefit function like this:
clc
clear all
close all
xdata=double(imread('FechnerGoldenrectangles.jpeg'));
ydata=double(imread('test.jpg'));
fun = @(r,xdata)RST_n_n(xdata,0,0,r,1 );
a=1;%intial guess
final=lsqcurvefit(fun,a,xdata,ydata)
but it doesn't give me coefficient I dont know where is my problem ! can u help me?
0 个评论
回答(1 个)
Alan Weiss
2017-4-19
Your objective is piecewise constant (you have round calls). Like all nonlinear Optimization Toolbox solvers, lsqnonlin is based on gradients, and if your function is locally constant, then the solver sees that every point is a local optimum because the gradient is zero, and immediately stops.
To use an Optimization Toolbox solver, you might want to smooth your objective function, interpolate it, or something so that it is not locally constant, but instead has values that smoothly change.
Alan Weiss
MATLAB mathematical toolbox documentation
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!