Attached is .m file of the custom function that I wrote and used to automatically detect peaks in a Hartmann image,
and calculate the centroid corrdinates of each of those peaks.
A simple example of its usage, provided that myimage is a two-dimensional image array obtained from the camera, is
radius = 10;
peak_positions = detect_peaks_uml(myimage,radius);
no_of_peaks = length(peak_positions);
centroids_array = zeros(no_of_peaks);
for k = 1:no_of_peaks
centroids_array(k,1) = peak_positions(k).WeightedCentroid(1);
centroids_array(k,2) = peak_positions(k).WeightedCentroid(2);
end
I chose my value of radius by looking at spots in a sample image and counting the number of pixels across a peak. It may be
more useful to automatically obtain a value for the radius. I may run some tests to see how different choices of radius
affect the centroid calculations.
I may also need to add some error checking and/or image validating codes, but so far I have not encountered any problems.
Please let me know if anyone needs more explanation!
Won |