How do I fit an arbitrary function to data using LSQNONLIN ?

조회 수: 6 (최근 30일)
hamidreza hamidi
hamidreza hamidi 2017년 4월 15일
댓글: hamidreza hamidi 2017년 4월 22일
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?

답변 (1개)

Alan Weiss
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
  댓글 수: 1
hamidreza hamidi
hamidreza hamidi 2017년 4월 22일
tx for your answer. I want to do automatic image registration and want to find rotation translation and scale this is why I'm using this function.how can I fix this issue? tanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by