How to use "fmincon"
Show older comments
Hi,
I'm trying to optimize the parameters of an image registration procedure between two 3D images using the "fmincon" function. The code is the following:
-------------------------------------
function optimize_parameters1
lb = [eps, eps, 1+eps, 10];
ub = [10, 1, 10, 255];
x = fmincon(@opt, [0.5, 0.5, 1.1, 150], [], [], [], [], lb, ub);
keyboard;
function val = opt(InitialRadius, Epsilon, GrowthFactor, NumberOfHistogramBins)
load('images.mat');
optimizer = registration.optimizer.OnePlusOneEvolutionary;
optimizer.InitialRadius = InitialRadius;
optimizer.Epsilon = Epsilon;
optimizer.GrowthFactor = GrowthFactor;
optimizer.MaximumIterations = 50;
metric = registration.metric.MattesMutualInformation();
metric.NumberOfHistogramBins = round(NumberOfHistogramBins);
metric.UseAllPixels = 1;
aligned = imregister( ...
T.img, imref3d(size(T.img)), ...
S.img, imref3d(size(S.img)), ...
'rigid', optimizer, metric, ...
'DisplayOptimization', 0, ...
'InitialTransformation', affine3d(eye(4)), ...
'PyramidLevels', 3);
val = sum((double(aligned(:))-double(S.img(:))).^2) * prod(S.header.spacing);
---------------------------
However, I keep getting this error:
---------------------------
Error using registration.optimizer.OnePlusOneEvolutionary/set.InitialRadius (line 152)
Expected input to be a scalar.
Error in optimize_parameters1>opt (line 16)
optimizer.InitialRadius = InitialRadius;
Error in fmincon (line 534)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in optimize_parameters1 (line 6)
x = fmincon(@opt, [0.5, 0.5, 1.1, 150], [], [], [], [], lb, ub);
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
-------------------------------
What am I doing wrong?
Thanks in advance!
Tomer
Accepted Answer
More Answers (0)
Categories
Find more on Nonlinear Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!