Finding rectangular shape in binary image
2 views (last 30 days)
Show older comments
Wooju Kim on 28 May 2020
Answered: Abhisek Pradhan on 4 Jun 2020
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);
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);
Could you help me with this issue?
Abhisek Pradhan on 4 Jun 2020
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.
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!