Is the line on the left supposed to be in the cropped output? Assuming not, just crop that off.
grayImage = grayImage(:, 50:end);
Then threshold, take convex hull, label, call regionprops, and call imcrop. Here is some untested code.
binaryImage = grayImage < 128;
binaryImage = bwareaopen(binaryImage, 400);
binaryImage = bwconvhull(binaryImage, 'union');
measurements = regionprops(logical(binaryImage), 'BoundingBox');
boundingBox = measurements(1).BoundingBox;
croppedImage = imcrop(grayImage, boundingBox);
If that doesn't work and you can't figure out how to fix it, then post your code and screenshots, otherwise please mark the Answer as "Accepted".