% Main program for finding positions of trees from ku94D-148.tiff
% and to produce the upper part of Figure 13 and Figure 14.

% Read the image 'ku94D-148.tiff' here supposed to be located in 
% the current directory
I = imread('ku94D-148.tiff');
figure(1)
imshow(I)

% Now smooth by a 2D circular Gaussian filter 
% with \sigma=4.5 pixel-widths
s=4.5;
A = smoothG(double(I)./256,s);
figure(2)
imshow(A)
imwrite(A,'smoothD-148.tif','tif')
% This is the image used in the upper part of Figure 13.

% Now find maxima with a distance at least 3*s from borders.
lim=ceil(s*3);
B=ismax(A,lim);
% Now we have found estimates of maxima corresponding "ones" in B.

% To get a good picture we broaden the maxima somewhat by 2D 
% circular Gaussian smoothing.  In addition we invert the image 
% so that maxima become black spots with a white bacckground.
s1=1;
B1 = smoothG(B,s1);
maxB=max(max(B1));
C = -B1./maxB +1;
figure(3)
imshow(C)
imwrite(C,'ismax.tif','tif')
% This is the image used in Figure 14.

