Try and use apply to fix edge-detection