Azzera filtri
Azzera filtri

Finding rectangular shape in binary image

1 visualizzazione (ultimi 30 giorni)
Wooju Kim
Wooju Kim il 28 Mag 2020
Risposto: Abhisek Pradhan il 4 Giu 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

Risposte (1)

Abhisek Pradhan
Abhisek Pradhan il 4 Giu 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.

Community Treasure Hunt

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

Start Hunting!

Translated by