-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Description
The centroid of the PSF generated by AnalyticalScaoPsf is off by about one pixel in x and y direction from the image center for an odd number of pixels and about 0.5 for an even number. There's also a fractional part that seems to vary with the size of the PSF. I'm not sure if one can expect the PSF to be perfectly centered given it's a non-trivial shape, but it seems more likely that it's either slightly off in the x-y direction or along one of the spikes. Along the diagonals as is happening here, especially as this effect is size-dependent looks like an artifact to me.
The PSF with an even number of pixels should have it's centroid between the central pixels. In terms of convolving with it this may not be a very good idea, so maybe an even number of pixels should be disallowed or emit a warning.
reproduction:
import matplotlib.pyplot as plt
import numpy as np
from anisocado import AnalyticalScaoPsf
def image_moment(image, x_order, y_order):
y, x = np.indices(image.shape)
return np.sum(x**x_order * y**y_order * image)
def centroid(image):
m00 = image_moment(image, 0, 0)
m10 = image_moment(image, 1, 0)
m01 = image_moment(image, 0, 1)
return m10/m00, m01/m00
# change numbers here to see the fractional part of the deviation shift
even = AnalyticalScaoPsf(pixelSize=0.004, N=50, seed=0).shift_off_axis(0,0)
odd = AnalyticalScaoPsf(pixelSize=0.004, N=51, seed=0).shift_off_axis(0,0)
# central pixel(s); subtract one -> highest valid index
# swap entries because first/outer index is y
even_expected = ((np.array(even.shape)-1)/2)[::-1]
odd_expected = ((np.array(odd.shape)-1)/2)[::-1]
fig, axs = plt.subplots(1, 2)
axs[0].imshow(even)
axs[0].axhline(even_expected[0])
axs[0].axvline(even_expected[1])
axs[0].set_title('even')
axs[1].imshow(odd)
axs[1].axhline(odd_expected[0])
axs[1].axvline(odd_expected[1])
axs[1].set_title('odd')
print(f'even centroid coordinates; expected: {even_expected} actual: {centroid(even)}')
print(f'odd centroid coordinates; expected: {odd_expected} actual:{centroid(odd)}')
plt.show()output:
odd centroid coordinates; expected: [25. 25.] actual:(25.755302032887823, 25.737949326316873)
even centroid coordinates; expected: [24.5 24.5] actual: (24.954821392835964, 24.95490068404942)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status