dmantione told you all you need to know, for a more code like explanation:
Dir:= normalize(LookAt ?˘_" IsAt);
imageNr:= Round(ImageCount / 2 / pi * Arccos(Dir.y));
if (Dir.x > 0) then imageNr:= ImageCount ?˘_" imageNr;