Try this:
grayImage = imread('11.bmp');
subplot(2, 2, 1);
imshow(grayImage)
title('Original Image', 'FontSize', 15);
grayImage = imrotate(grayImage, -45);
subplot(2, 2, 2);
imshow(grayImage)
title('Rotated Image', 'FontSize', 15);
mask = bwconvhull(grayImage ~= 255 & grayImage ~= 0);
subplot(2, 2, 3);
imshow(mask)
title('mask', 'FontSize', 15);
[rows, columns] = find(mask)
croppedImage = grayImage(min(rows):max(rows), min(columns):max(columns));
subplot(2, 2, 4);
imshow(croppedImage)
title('Cropped Image', 'FontSize', 15);
Best Answer