Finding rectangular shape in binary image

3 Ansichten (letzte 30 Tage)
Wooju Kim
Wooju Kim am 28 Mai 2020
Beantwortet: Abhisek Pradhan am 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);
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

Antworten (1)

Abhisek Pradhan
Abhisek Pradhan am 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.

Kategorien

Mehr zu Geometric Transformation and Image Registration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by