function a= identify_field(uid,fieldid)

format long g;
format compact;
pkg load image
fontSize = 20;

filename = strcat(uid,"_TCI.png");

rgbImage = imread(filename);
% Get the dimensions of the image.  numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);


% Let's get our template by extracting a small portion of the original image.
templateWidth = 71
templateHeight = 49
fieldstatic = strcat(uid,fieldid);
fieldstatic = strcat(fieldstatic,"_static_map.png");

smallSubImage = imread(fieldstatic);
f_size = size(smallSubImage)
% Get the dimensions of the image.  numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(smallSubImage);

channelToCorrelate = 1;  % Use the red channel.
tic
correlationOutput = normxcorr2(smallSubImage(:,:,1), rgbImage(:,:, channelToCorrelate));
toc

% Get the dimensions of the image.  numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(correlationOutput);

% Find out where the normalized cross correlation image is brightest.
[maxCorrValue, maxIndex] = max(abs(correlationOutput(:)));
[yPeak, xPeak] = ind2sub(size(correlationOutput),maxIndex(1))
% Because cross correlation increases the size of the image, 
% we need to shift back to find out where it would be in the original image.
corr_offset = [(xPeak-size(smallSubImage,2)) (yPeak-size(smallSubImage,1))]

% Calculate the rectangle for the template box.  Rect = [xLeft, yTop, widthInColumns, heightInRows]
%boxRect = [corr_offset(1) corr_offset(2) templateWidth, templateHeight]
sizeRGB = size(rgbImage);
a = zeros(1,4);
xstart = corr_offset(2)-10;
xend = yPeak+10+f_size(1);
ystart = corr_offset(1)-10;
yend = xPeak+10+f_size(2)
if xstart<10 | ystart<10
	a(1,1) = 1;
	a(1,2) = sizeRGB(1);
	a(1,3) = 1;
	a(1,4) = sizeRGB(2);
	break;
end
if xstart<1
	xstart=1;
end
if xend>sizeRGB(1)
	xend = sizeRGB(1);
end
if ystart <1
	ystart=1
end
if yend>sizeRGB(2)
	yend = sizeRGB(2)
end


a(1,1) = xstart;
a(1,2) = xend;
a(1,3) = ystart;
a(1,4) = yend;
a
end
