function [i,j,val] = find_sparse_maxima(im, threshold)
	% [i,j] = find_sparse_maxima(im, threshold)
	%
	% find indices i,j of entries in im which are local maxima
	% and above a given threshold in a sparse image
	%
	% maxima are not detected near edges of sparse pixels
	
	% 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  ));
	L				= im(sub2ind(im_size, i  ,j-1));
	R				= im(sub2ind(im_size, i  ,j+1));
	U				= im(sub2ind(im_size, i-1,j  ));
	D				= im(sub2ind(im_size, i+1,j  ));
	is_max			= L < val & R < val & U < val & D < val ...
					& L ~= 0  & R  ~= 0 & U ~= 0  & D ~= 0;
	val				= val(is_max)';
	i				= i(is_max);
	j				= j(is_max);
end