Minimizing the FWHM of a Gaussian using fmincon

4 views (last 30 days)
Hi there,
I am trying to write some code which alters the proportions in which several line profiles are combined as to minimize the FWHM of a Gaussian fit to the resultant profile. I managed to get it working but it was slightly messy and unconvincing, so I've been retrying.
From my code below, I use values of v (a vector containing four numbers) as coefficients for combining five images. I then take a linear profile across the image from a pre-defined region and perform a Gaussian fit to this profile (the fit function 'f' is the gauss1 fit modified to have a y-offset). I then calculate the FWHM of the fitted Gaussian.
What I want to do is vary the values of v to minimise the FWHM. I also want to make sure that the value of the minimized FWHM is not smaller than the value 'PixResol', so I used fmincon with what I thought to be appropriate constraints.
However, this is completely incorrect as I get the error message that the third argument in fmincon requires a four-element vector. As I understand it, this implies that fmincon is applying the constraints to the four different values of v. However, I don't care what values v takes, I am only concerned with the final value of the FWHM.
It is probably quite obvious that I am not at all experienced in minimization in Matlab, and I have been looking through the documentation for fmincon (and other minimizers) for help but have found none!
If anyone could at least point me in the right direction I would be incredibly grateful.
Many thanks,
Siân
[v,fval] = fmincon(@imfun, v0, -1, -PixResol);
function b = imfun(v)
c2 = v(1);
c3 = v(2);
c4 = v(3);
c5 = v(4);
im = im1 + c2*im2 + c3*im3 + c4*im4 + c5*im5;
for i = 1:length(im1Prof)
Y = im(yRange(i),xRange(i));
end
[fitobject gof] = fit(X, Y, f, ...
'Start', [max(Y) cent FWHMguess mean(Y(1:base))]);
coeffs = coeffvalues(fitobject);
FWHM = coeffs(3)*sqrt(2*log(2));
b = FWHM;
end
  1 Comment
Matt J
Matt J on 28 Nov 2012
Edited: Matt J on 28 Nov 2012
The idea of deliberately bounding the FWHM from below is pretty bizarre to me. Normally, you want to minimize blur as much as possible, not keep it above your pixel resolution just so that you can see it.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 28 Nov 2012
Edited: Matt J on 28 Nov 2012
Well, if you really want to do this, you need a nonlinear constraint, implemented as follows, but see also my comments above.
[v,fval] = fmincon(@imfun, v0, [],[],[],[],@(v)nonlcon(v,PixResol));
function [c,ceq]=nonlcon(v,PixResol)
c=PixResol - imfun(v);
ceq=[];
end
  1 Comment
Sian Culley
Sian Culley on 29 Nov 2012
Thank you very much for your help! I am aware that from an image processing point of view this seems rather strange, but I promise that I have some valid physics-based reasons for wanting to do this :-)
Siân

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!