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일

1 개 추천

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

Mor
Mor 2014년 5월 31일
Hi,
It works. Can you explain what this line: [~,idx]=min(IJ*[1 1; -1 -1; 1 -1; -1 1].');?
Matt J
Matt J 2014년 5월 31일
It finds where the sums and differences of the coordinates in the shape are maximized and minimized.
Bálint Udvardy
Bálint Udvardy 2018년 2월 23일
Hi, I have just found this thread. I have a similar problem now: I am working on a nonogram-solver and I want to remove the perspective from the image to get the picture of the puzzle, but after extracting the largest connected component from the image (the puzzle grid) and using convex hull of that component I get a pentagram. Unfortunately, all the corner detectors fail to detect the 5 corners. Using your method detects 4 corners, which itself is an improvement, but I need that 5th corner to calculate the theoretical "true" upper left corner, which i need to remove the perspective.
Matt J
Matt J 2018년 2월 23일
Why do you need the "upper left" corner? Why can't you use the 4 point correspondences that you already have to compute the perspective transform?
Bálint Udvardy
Bálint Udvardy 2018년 2월 26일
How? I only know that the right and the left vertical lines should be paralell to each other and have the same length in real, but on the photo it can be shorter or longer.
Matt J
Matt J 2018년 2월 26일
You know all the little boxes in the puzzle grid are the same size and therefore you know the world coordinates of all corners of those boxes with respect to that grid. That gives you lots of point-to-point correspondence information.
Syed Haider
Syed Haider 2018년 4월 18일
Dear Matt,
Thanks for the code. It did work really well on most of the images. But if I apply the same code to the image attached,
I get the wrong corners. I have attached the output image below. Any suggestions would be highly appreciated.
Thanks,
Irtaza
Matt J
Matt J 2018년 4월 18일
A quick fix would be to imrotate() the image, so the rectangle is better aligned with the edges of the image grid. Then find the corners of the rotated rectangle and then rotate back.
Image Analyst
Image Analyst 2018년 4월 18일
Compute the centroid, then the distances to the boundary points. Then use findpeaks() to find the vertices. I have a demo if you want - start your own brand new thread.
What is the idea behind the code ? Is it a standard kernel ?
[~,idx]=min(IJ*[1 1; -1 -1; 1 -1; -1 1].')
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일

2 개 추천

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일

1 개 추천

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일

1 개 추천

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

Mor
Mor 2014년 5월 24일
Hi Matt,
Here is the result:
The top left and the bottom right are not exactly the corner, It's because it's not a straight lines.
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일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

질문:

Mor
2014년 5월 23일

답변:

2020년 2월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by