function latva=find_trees2(name)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function find_trees etsii annetusta tiedosta puiden keskipisteet
% käyttäen 5x5 maksimin etsintää.
% 
% Copyright Juha Hyyppä 5.3.2006
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      

eval(['load ',name])

[x,y]=size(chm);
latva=zeros(x,y);
chm2=chm;

puut=[];

for i=3:x-2
    for j=3:y-2
        piste=chm(i,j);
        A=max(max(chm(i-2:i+2,j-2:j+2)));
        if abs(piste-A)<0.00001
            %oletettu latvapiste
            latva(i,j)=1;
            chm2(i,j)=100;
            puut=[puut
                 i j chm(i,j)];
        end
    end
end    

figure(1)
imagesc(chm)
colorbar
figure(2)
imagesc(chm2)
figure(3)
hist(puut(:,3))

  
pause



