Hi,
I see that you use non-integer pixel positions to get the pixel values:
xp =i+x0+0.5;
yp =j+y0+0.5;
When you use getPixel() on non-integer values, it will use interpolation. When you have a perfect edge [..., 0, 0, 255, 255, ...], the edge will be smoother because of this interpolation (see image, the real edge is just [..., 0, 0, 255, 255, ...], yet the ESF is [..., 0, 0, 127.5, 255, 255, ...]), resulting in worse MTF at the end.

Hi,
I see that you use non-integer pixel positions to get the pixel values:
xp =i+x0+0.5;
yp =j+y0+0.5;
When you use getPixel() on non-integer values, it will use interpolation. When you have a perfect edge [..., 0, 0, 255, 255, ...], the edge will be smoother because of this interpolation (see image, the real edge is just [..., 0, 0, 255, 255, ...], yet the ESF is [..., 0, 0, 127.5, 255, 255, ...]), resulting in worse MTF at the end.