Automatic cropping based on edge detection