I am looking for a way to make median radial profiles for a 2D array image in Python. The median radial profile has almost the same logic as the mean radial profile (Most efficient way to calculate radial profile), but instead of calculating the mean of each ring, I need to find the median. Any ideas on how to do this?
Right now I have this code, but I don't know how to test it if it works or not:
def radial_profile(data, center):
y, x = np.indices((data.shape))
r = np.sqrt((x - center[0])**2 + (y - center[1])**2)
r = r.astype(np.int).ravel()
data = data.ravel()
RadialProfile = []
# find the median in each of the group of data with the same radius
for el in np.arange(1,np.amax(r)):
median = np.median(data[np.where(r == el)[0]])
RadialProfile.append(median)
return RadialProfile
Aucun commentaire:
Enregistrer un commentaire