function ctr = detect_peaks_uml(image,radius) % Usage example: % positions = detect_peaks_uml(myimage,10); % % total number of peaks detected: length(positions.WeightedCentroid) % access the coordinates of the nth peak: % positions(n).Weightedcentroid(1), positions(n).WeightedCentroid(2) weighted_image = image .^ 2; background = imopen(weighted_image,strel('disk',radius)); modimage = weighted_image - background; % Peak detection does not appear to work unless the array is scaled. modimage = modimage./max(max(modimage)); % The following line does not seem to be necessary, so commented out. % modimage = imadjust(modimage); level = graythresh(modimage); bwimage = im2bw(modimage,level); ctr = regionprops(bwimage, modimage, {'centroid','weightedcentroid'});