Remove the unwanted region from an image and rotate it to 45 degree

4 views (last 30 days)
I have an image attached with this question. I wanted to remove the unwanted white portion and rotate image to 45 degree angle. The unwanted portion contains values either 255 or 0. Please help me.

Accepted Answer

Image Analyst
Image Analyst on 12 Oct 2018
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);
% Get mask
mask = bwconvhull(grayImage ~= 255 & grayImage ~= 0);
subplot(2, 2, 3);
imshow(mask)
title('mask', 'FontSize', 15);
% Find cropping index
[rows, columns] = find(mask)
% Crop
croppedImage = grayImage(min(rows):max(rows), min(columns):max(columns));
subplot(2, 2, 4);
imshow(croppedImage)
title('Cropped Image', 'FontSize', 15);
  5 Comments
Image Analyst
Image Analyst on 16 Oct 2018
Moved: DGM on 13 Feb 2023
What do you want in place of the white? Because images cannot have ragged bottoms or sides - they MUST remain rectangular.
ashwini patil
ashwini patil on 29 Oct 2018
Now in my project I have to compute energy and entropy of the above cropped Images. Can you please guide me that how should the energy and entropy of an image is calculated??

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!