Finding rectangular shape in binary image

2 visualizaciones (últimos 30 días)
Wooju Kim
Wooju Kim el 28 de Mayo de 2020
Respondida: Abhisek Pradhan el 4 de Jun. de 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

Respuestas (1)

Abhisek Pradhan
Abhisek Pradhan el 4 de Jun. de 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.

Categorías

Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by