Finding rectangular shape in binary image

2 次查看(过去 30 天)
Hello, I hope all is well with you in current pendemic problem.
I have an issue in processing the attahced images.
I tried to find retangular shape and crop the image but it was failed.
Below is the code I tried.
im = imread('0.3616.jpg')
im = rgb2gray(im);
figure
imshow(im);
BW = im2bw(im, 0.5);
binaryImage = BW;
[rows, columns] = find(binaryImage);
topRow = min(rows);
bottomRow = max(rows);
leftColumn = min(columns);
rightColumn = max(columns);
croppedImage = binaryImage(topRow:bottomRow, leftColumn:rightColumn);
figure
imshow(croppedImage)
Could you help me with this issue?
Thank you!
Wooju

回答(1 个)

Abhisek Pradhan
Abhisek Pradhan 2020-6-4
I was able to reproduce the error. And the reason is quite simple. As you are using min and max to get the boundaries after using find, it is causing it store the position of first white dot in your image ( from all 4 side ).
Refer the following blog as a reference to Image Segmentation.

类别

Help CenterFile Exchange 中查找有关 Geometric Transformation and Image Registration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by