function maxval = findmax(im1) 

% Use a gaussian blur to smooth out spikes


im2 = gaussfilt( rgb2gray(im1) , 5, 2);

max1 = max( im2(:) );
[row,col] = find( im2 == max1 );


winsize = 50;
row1 = median(row );
col1 = median(col );
[row1, col1];
samplewin = im1( (row1-winsize):(row1+winsize), (col1-winsize):(col1+winsize), : );
maxval = mean( mean(samplewin ));

return;



function imout = gaussfilt(im, nsize, stdev);
	gw = gausswin(nsize, 1/stdev);
	gw = gw ./ sum(gw);
	
	
	imout = filter2( gw' , filter2(gw, im) );
return
