Find coordinate position (x1, y1, x2, y2) of multiple rectangle from an binary image
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a binary image with multiple rectangle in non-overlapping state. I need to find the coordinates (x1, y1, x2, y2) of each rectangle in matlab. Please suggest me. I have posted my image here.![binary_image.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/195637/binary_image.png)
![binary_image.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/195637/binary_image.png)
0 Kommentare
Antworten (1)
Akira Agata
am 19 Nov. 2018
If your rectangle are always horizontal and/or vertical in your images, regionprops function will work, like:
% Read the image
I = imread('sample.png');
% Binarize, invert and suppress areas connected to image border
BW = imbinarize(rgb2gray(I));
BW = imclearborder(~BW);
% Calculate bounding box for each rectangle
s = regionprops(BW,'BoundingBox');
Then, you can calculate coodinate points (x1,y1) ~ (x4,y4) from the result.
>> struct2table(s)
ans =
4×1 table
BoundingBox
________________________________
16.5 241.5 121 9
31.5 196.5 106 9
31.5 226.5 61 9
106.5 226.5 46 9
0 Kommentare
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!