Detect all the rectangles in image
Show older comments
Hey all,
in the following image, all the rectangles are a little bit deformed due to power leakage effect. I want to detect all the rectangles and obtain the positions of the rectangles.

Is there a way to detect all rectangles?
Thank you
Accepted Answer
More Answers (1)
KSSV
on 18 Feb 2019
I = imread('myImage.jpeg') ;
[y,x] = find(I>50) ;
imshow(I)
hold on
idx = kmeans([x y],4) ;
for i = 1:4
plot(x(idx==i),y(idx==i),'.')
% GEt L and B of rectangles
x0 = min(x(idx==i)) ; x1 = max(x(idx==i)) ;
y0 = min(y(idx==i)) ; y1 = max(y(idx==i)) ;
%
L = x1-x0 ;
B = y1-y0 ;
coor = [x0 y0 ; x0 y1 ; x1 y1 ; x1 y0] ;
patch(coor(:,1),coor(:,2),rand(1,3))
end
3 Comments
simon xu
on 18 Feb 2019
islam elsayed
on 11 Jun 2020
can you please explain in brief
islam elsayed
on 11 Jun 2020
Categories
Find more on Labels and Annotations 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!




