function imgNum = countImages(Trials);
% imgNum = countImages(Trials);
% assigns an image number to each distinct image (repeated images numbered the same)
% imgNum is an array of the same length as Trials.image. If trials.image is 'blank', imgNum is -1,
% if Trials.image is 'end of run', imgNum is -2, otherwise imgNum assigns a positive number to each image.
% 
% 1/03 by ras
imgcnt = 1;
imgNum = zeros(1,length(Trials.image));
% first assigned reserved names, specifying null trials etc., to negative imgNums
for i = 1:length(Trials.image)
	if strncmp('blank',Trials.image{i},5)
		imgNum(i) = -1;
	elseif strncmp('end',Trials.image{i},3)
		imgNum(i) = -2;
	end
end
% assign remaining names, specifying image files, to positive imgNums
while ~all(imgNum)
	nextimg = find(imgNum==0);
	nextimg = nextimg(1);
	imgname = Trials.image{nextimg};
	for i = 1:length(Trials.image)
		if isequal(Trials.image{i}, imgname)
			imgNum(i) = imgcnt;
		end
	end
	imgcnt = imgcnt + 1;	
end
return
