There is an image of apple on white canvas. I want to crop it in a way so that my new image will contain only required part(apple only). To explain it clearly I have drawn a black rectangle around apple and grapes. I want only what is inside rectangle. I cant give height and width to cut because I want to run that script on many images that have different different shapes (for example apple and grapes here). Should I check every pixel for color change (from white to colored) so that I can get height and width of actual part of every image or there is a better way.