How do I fit an arbitrary function to data using LSQNONLIN ?
조회 수: 6 (최근 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!