How to find "rectangular" corners?

22 ビュー (過去 30 日間)
Mor
Mor 2014 年 5 月 23 日
回答済み: Matt J 2020 年 2 月 6 日
Hey,
I have this image:
I want to find the 4 corners of the "rectangular", but I don't want to use the "corner" function. What can I do?
Thanks.
  1 件のコメント
Cedric
Cedric 2014 年 5 月 24 日
If your rectangles are not too degenerate, you could get corners with four 2D convolutions using appropriate kernels.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2014 年 5 月 24 日
編集済み: Matt J 2014 年 5 月 24 日
If the quadrilateral is roughly aligned with the edges of the image, you could also find the corners as follows,
[I,J]=find(Image>max(Image(:))/2);
IJ=[I,J];
[~,idx]=min(IJ*[1 1; -1 -1; 1 -1; -1 1].');
corners=IJ(idx,:)
  13 件のコメント
Balkrishna Patankar
Balkrishna Patankar 2019 年 6 月 25 日
Thank you (y)
Matt J
Matt J 2019 年 10 月 22 日
編集済み: Matt J 2019 年 10 月 22 日
Here is a generalization of the approach to arbitrary convex quadrilaterals. No particular orientation is assumed.
N=360;
theta=linspace(0,360,N);
[I,J]=find(Image);
IJ=[I,J];
c=nan(size(theta));
for i=1:N
[~,c(i)]=max(IJ*[cosd(theta(i));sind(theta(i))]);
end
H=histcounts(c,1:numel(I)+1);
[~,k] = maxk(H,4);
corners=IJ(k,:)

サインインしてコメントする。

その他の回答 (4 件)

Matt J
Matt J 2020 年 2 月 6 日
Use pgonCorners from the File Exchange (Download). It applies to any convex polyhedron.
numVertices=4;
corners=pgonCorners(Image,numVertices)

Image Analyst
Image Analyst 2014 年 5 月 23 日
編集済み: Image Analyst 2014 年 5 月 23 日
Why not try the corner() function in the Image Processing Toolbox. What do you have against using that?
Or else call bwboundaries() and go along the coordinates looking for kinks in the curve as shown by the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_find_.22kinks.22_in_a_curve.3F
  1 件のコメント
Mor
Mor 2014 年 5 月 24 日
Hi,
Thanks for your answer. The reason I don't want to use the corner() function is because I have more pictures and in some of them the corner function doesn't work good (detects 2 corners is the same place) I think it's because the lines are not straight. maybe there is some configuration to make it work for every picture.

サインインしてコメントする。


Matt J
Matt J 2014 年 5 月 24 日
Maybe use edge() followed by houghlines() with an appropriate FillGap selection? The endpoints of the line segments returned by houghlines would be the corners of the quadrilateral.
  3 件のコメント
Image Analyst
Image Analyst 2014 年 5 月 24 日
If you need the exact corner, use (untested)
boundaries = bwboundaries(binaryImage);
x = boundaries{:,1};
y = boundaries{:,2};
and compare every x and y to see which is closest to the hough points
distances = sqrt((xh - x).^ 2 + (yh - y) .^ 2)
[minDistance, indexOfMin] = min(distances);
xc = x(indexOfMin);
yc = y(indexOfMin);
Do the above for each hough estimated point to find the point in the blob which is closest to the hough point (xh, yh).
Matt J
Matt J 2014 年 5 月 24 日
編集済み: Matt J 2014 年 5 月 24 日
You can be generous with the RhoResolution, given the large size of the quadrilateral. I get a pretty good fit to the edges with the following,
[H,T,R] = hough(E,'RhoResolution',4,'Theta',-90:.5:89);
Similar to what ImageAnalyst was saying, this initial line fit should allow you to segment the boundary points into 4 separate edges. You do this by finding the closest point to each initial line. You can then do a more refined line fit to each edge using each group of points (e.g., using polyfit).

サインインしてコメントする。


Image Analyst
Image Analyst 2014 年 5 月 24 日
If the quad is roughly aligned with the edges of the image you could also get the distance from the 4 corners. For each corner, take the one point on the white boundary that has the minimum distance. No need to mess with hough in that case.

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by