[x y]=ndgrid(-128:127,-128:127);
r=x+i*y;
r0=-12+10*i;
r1=12-10*i;
a0=1;
a1=exp(-i*pi/10);
b0=exp(-i*pi/4);
b1=exp(-i*(pi/4+pi/10));

Xs=[real(r0) imag(r0) real(r1) imag(r1) real(a0) imag(a0) real(b0) imag(b0) real(a1) imag(a1) real(b1) imag(b1)];

[chi img]=e2fit(Xs,r,1,Xs,[]);
[chi img]=e2fit(Xs,r,img,Xs,[]);

N=[1000 500 200 100 50 20 10 5 2 1];

Xc=zeros(10*length(N),length(Xs));

for n=1:length(N)
  for m=1:10
    imgN=img+max(img(:))*randn(256,256)/N(n);
    Xc((n-1)*10+m,:)=fminsearch(@(x) e2fit(x,r,imgN,Xs,[]),Xs);
    mean(abs((Xc((n-1)*10+m,1:4)-Xs(1:4))./Xs(1:4))*100)
  end
end

