How to use "fmincon"

1 view (last 30 days)
Tomer
Tomer on 21 Oct 2015
Commented: Tomer on 21 Oct 2015
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

Walter Roberson
Walter Roberson on 21 Oct 2015
x = fmincon(@(x) opt(x(1),x(2),x(3),x(4)), [0.5, 0.5, 1.1, 150], [], [], [], [], lb, ub);
  1 Comment
Tomer
Tomer on 21 Oct 2015
Great! thank you very much!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!