Remove the unwanted region from an image and rotate it to 45 degree
4 views (last 30 days)
Show older comments
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.
1 Comment
KALYAN ACHARJYA
on 12 Oct 2018
Remove the unwanted region
What does it mean?
Remove the pixel?? Then what remains there?
Accepted Answer
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
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.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!