function [i,j,val] = find_maxima(im, threshold)
	% [i,j] = find_maxima(im, threshold)
	%
	% find indices i,j of entries in im which are local maxima
	% and above a given threshold
	
	% find indices above threshold, sufficiently far from edges
	im_size			= size(im);
	[i,j]				= find(im >= threshold);
	ok					= i > 1 & i < im_size(1) ...
						& j > 1 & j < im_size(2);
	i					= i(ok);
	j					= j(ok);
	% of these, find indices that are local maxima
	val				= im(sub2ind(im_size, i  ,j  ));
	is_max			= im(sub2ind(im_size, i  ,j-1)) < val ...
						& im(sub2ind(im_size, i  ,j+1)) < val ...
						& im(sub2ind(im_size, i-1,j  )) < val ...
						& im(sub2ind(im_size, i+1,j  )) < val;
	val				= val(is_max)';
	i					= i(is_max);
	j					= j(is_max);
end