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's features are in the scale of square L2 norm.
Gaussian kernel should be using the square L2 norm, but I see significant differences between Gaussian functions in Matlab and Octave, see the answer here.
The code is about Estimating resolution from a PSF slide image and about the function EstimateResolutionFromPsfImage with default values of tolarance [0.7 1.3]
in Matlab 2016a
resolutionEstimate = EstimateResolutionFromPsfImage(im2bw(imgRGB), [0.7 1.3]);
where imgRGB
is
Output results in complications coming from the fact that the command returns 0x1 struct in objectProperties
from the line 29 of EstimateResolutionFromPsfImage
objectProperties = regionprops( dilatedImage, ImageData, ...
'Area', 'Centroid', 'PixelList', 'PixelValues', 'MaxIntensity' );
where I do not understand how it can be zero in the case.
My workspace is ok at start but after passing the objecProperties
statement, there is a 0x1 struct which should not be there as almost empty
and eventually leads to errors
Index exceeds matrix dimensions.
Error in EstimateResolutionFromPsfImage (line 108)
Resolution = mean( allPeakData(:,4) ) ./ 0.336;
Error in masi (line 272)
resolutionEstimate = EstimateResolutionFromPsfImage(im2bw(imgRGB), [0.7 1.3]);
Possible reasons
- Input.
ImageData
possible wrong. - Changes is
regionprops
. I think there are something that I have not understood enough well inregionprops
. The commandimagesc(dilatedImage)
shows that the matrixdilatedImage
is null i.e. every cell is null in the matrix, like Shai comments. This confirms that the problem is withobjectProperties
becausedilatedImage
is dependent on theobjectProperties
which is 0x1 struct i.e. causing the complication. - Conversion from Matlab 7.3 to 2016a. I did not find anything that is only unique for Matlab 7.3 in the code. It should work for Matlab 2016a like for Matlab 7.3.
Psf image generation based on dhanushka's hint
MIT's code SimulatePsfSlide
seems to work somehow in generating psfImg
.
I am reviewing the effect of different parameters on the result and confirming the result but have some difficulties with overexposed images and and eventually having warnings like
Warning: Rank deficient, rank = 4, tol = 1.979466e-12.
> In nlinfit>LMfit (line 579)
In nlinfit (line 276)
...
Warning: Rank deficient, rank = 1, tol = 1.979466e-12.
Warning: Some columns of the Jacobian are effectively zero at the solution,
indicating that the model is insensitive to some of its parameters. That may be
because those parameters are not present in the model, or otherwise do not
affect the predicted values. It may also be due to numerical underflow in the
model function, which can sometimes be avoided by choosing better initial
parameter values, or by rescaling or recentering. Parameter estimates may be
unreliable.
Here some line which causes complications where I do not understand why 16 and why conversion with im2double
simulatedPsfImage = im2double( simulatedPsfImage * 16 );
dhanushka's code in Matlab 2016a
Matlab does not work with inputs of homogenous changes when the image is not PSF, like the first image.
Dhanushka's filter is not recommended here because of many reasons. I get a much better model with significantly greater tolerance (even 1.00) with the code. Replace dhanushka's not recommended filter by a better one and use this
im = im2double( imgGray ); % zeros( ImageSize ) );
sigma = 5;
simulatedPsfImage = imgaussfilt(im, sigma);
simulatedPsfImage = im2double( simulatedPsfImage );
[ measuredResolution, standardError, bestFitData ] = ...
EstimateResolutionFromPsfImage( simulatedPsfImage, [1.00 1.00] );
Output is much better
where BestFitData = 249.999999999989 249.999999999989 0.00713504020178639 5.31607106546232 -0.000392450463696062
; so estimatedSigma = 5.316, which is worser than dhanushka's second example.
You will have significant problems with tolerance levels with the fspecial gaussian
in Matlab, but not in Octave like dhanushka's second example shows.
Extension to Mars
Mars case with dhanushka's code when input
Output with imgaussfilt
Final conclusion
L2 norm is not sufficient here.
Why is the output of regionprops here 0x1 struct?