Skip to content

Instantly share code, notes, and snippets.

@ferryzhou
Created December 18, 2012 21:21
Show Gist options
  • Save ferryzhou/4332122 to your computer and use it in GitHub Desktop.
Save ferryzhou/4332122 to your computer and use it in GitHub Desktop.
get maxima of a gray scale image
function [I, J, xvals] = get_local_maxima(imcor, radius)
% a = rand(10);
% [I, J, xvals] = get_local_maxima(a, 3);
% figure, imagesc(a); hold on; scatter(J, I);
[m, n] = size(imcor);
nim = ones(m + radius * 2, n + radius * 2) * 1e-10;
nim(radius + (1:m), radius + (1:n)) = imcor;
cols = im2col(nim, [2*radius + 1, 2 * radius + 1], 'sliding');
mcols = max(cols);
o = imcor == reshape(mcols, m, n);
[I, J] = find(o);
xvals = imcor(sub2ind([m, n], I, J));
end
a = rand(10);
[I, J, xvals] = get_local_maxima(a, 3);
figure, imagesc(a); hold on; scatter(J, I);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment