i = double( imread('fruits2.tif') ); t = i(386:404, 623:673); subplot(2,2,1); imshow(i,[]) subplot(2,2,2); imshow(t,[]) [xs, ys] = size(i); tic fun = @(x,n) 1/(1+sum(sum((x-n).^2))); c = nlfilter(i,[size(t,1) size(t,2)],fun, t); subplot(2,2,3); imshow(c, []) subplot(2,2,4); mesh(c) m = max(c(:)); ind = find( floor(c/m)>0 ); x = mod(ind,xs) - round(size(t,1)/2)+1 y = ceil(ind/xs) - round(size(t,2)/2)+1 subplot(2,2,1); hold on plot(y,x, 'r*') hold off toc