I think the whole function could be speeded up by using more type definitions, see px, py, max_radius, normalize.