
camerano = 1;
nameMTV='CTS.MTV0550';

nshots = 30;

currentdir = pwd;
cd('..');
[ctfmodroot, dataout, madxp] = ctfsettings();
addpath([ctfmodroot '/MatLab/JavaCoInterface']);
cd(currentdir);

CameraON(nameMTV);

animage =  GetImage(nameMTV);

sumimages = animage;

fprintf(1,'Camera %s: Got 1st Image\n',nameMTV);

%contourf(animage);
%surface(animage);
%fprintf(1,'Camera %s: Plotted 1st Image\n',nameMTV);

rebin = 4;



for i=1:10

  [animage, xs, ys ] =  GetImage(nameMTV);
  sumimages = sumimages + animage;
  avgimage = sumimages/(1.+ i);

  tic;
  if (rebin < 2)
    figure(2);  
    surface(xs, ys, avgimage ,'linestyle','none');
  else
    figure(1);  
    rebinnedi = RebinImage(avgimage,rebin);
    xs2 = RebinVector(xs,rebin);
    ys2 = RebinVector(ys,rebin);
    surface(xs2, ys2, rebinnedi ,'linestyle','none');
  end

  t1 = toc;

%  figure(2);
%  surface(xs, ys, avgimage ,'linestyle','none');

%  figure(3);
%  projx = GetProjection(avgimage,1);
%  plot(projx);
  
 %  surface(avgimage);
  %mesh(avgimage);
  %pause(0.5);
  
  
  fprintf(1,'Camera %s: Plotted %d Image in %f \n',nameMTV, i+1, t1);
  
    
end

return;

bkg = avgimage;

avgimage = 0;
sumimages = 0;

for i=1:nshots

  [animage, xs, ys ] =  GetImage(nameMTV);
  sumimages = sumimages + animage - bkg;
  avgimage = sumimages/i;
  
  
  figure(1);  
  surface(xs, ys, avgimage ,'linestyle','none');
  
%  projx = GetProjection(avgimage,1);
%  plot(projx);

  %figure(2);
  %contour(avgimage);
  %mesh(avgimage);
  %pause(0.5);
  
  fprintf(1,'%f %f %f %f\n',avgimage(10,10),avgimage(20,20),avgimage(30,30),avgimage(40,40));
  fprintf(1,'Camera %s: Plotted %d Image\n',nameMTV, i+1);
  
    
end
