I am trying to convert the code of MIT\'s course Biological Instrumentation and Measurement in the wiki page here from Matlab 7.3 to Matlab R2016a. My input data\'
To my understanding your input image isn't a PSF image. Quoting from the link you provided, a PSF image is an image of approximate point sources on a dark background, such as a star field or sub resolution fluorescent microspheres. You can generate such image for testing using the SimulatePsfSlide
function in the given code.
EDIT
I don't have Matlab. I ran the code in Octave with a simple PSF image having a single point source in the middle of the image generated from the code below. You can first try with a simple known image and check the result.
In the code below, you can vary the Gaussian PSF size and sigma and see how nlinfit estimates the sigma.
Over-exposure shouldn't be a problem, those values are clipped according to the test code in the link.
clear all
close all
psfSize = 9;
psfSigma = 5;
% single point source in the middle: this is the object
ImageSize = [500 500];
im = im2double( zeros( ImageSize ) );
im( int32(ImageSize(1)/2), int32(ImageSize(2)/2) ) = 1;
% gaussian psf: this is the psf of our imaging system
h = fspecial('gaussian', [psfSize psfSize], psfSigma);
% convolve the object with psf: the image, this is what we see
simulatedPsfImage = imfilter(im, h, 'same');
simulatedPsfImage = im2double( simulatedPsfImage );
% estimating resolution
[ measuredResolution, standardError, bestFitData ] = ...
EstimateResolutionFromPsfImage( simulatedPsfImage );
Input data and nlinfit output (beta and MSE only): Note that in the second case, the MSE is smaller, indicating that the input data closely matches the model. Also we get the correct sigma.
psfSize = 9, sigma = 5, estimated sigma = 3.0730
beta =
2.5000e+002
2.5000e+002
2.0275e-002
3.0730e+000
-4.4688e-004
mse = 1.6114e-006
psfSize = 25, sigma = 5, estimated sigma = 5.0000
beta =
2.5000e+002
2.5000e+002
6.5254e-003
5.0000e+000
7.3796e-010
mse = 2.2996e-020
Output in Matlab 2016a with psfSize=9
and psfSigma=5
, which shows a significant difference between fspecial
in Matlab and Octave
where bestFitData = 250.000000000593 250.000000000593 0.0202577533025840 3.07726724108174 -0.000451857701021258
; here estimatedSigma = 3.077.