You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
extraction of corner points in grid image and how to calculate the distance between corner points
2 views (last 30 days)
Show older comments
I ma providing the grid image & i want to find the each corner points of box/square in my image and want to calculate the distance between each corner points
Accepted Answer
Image Analyst
on 22 Dec 2017
You can use the sqrt function. So if x and y are 4 element arrays, then do get the diagonal distances, use the appropriate indexes, for example
diagonalDistance1 = sqrt((x(1)-x(3))^2 + (y(1)-y(3))^2);
diagonalDistance2 = sqrt((x(2)-x(4))^2 + (y(2)-y(4))^2);
You forgot to provide your image (so read this), but assuming you have a white square box on a black background, you can use regionprops to find the centroid of the box, then use bwboundaries to find all the (x,y) coordinates of the perimeter. Then use sqrt() to find the distances of every point to the centroid, and use findpeaks() (in the Signal Processing Toolbox) to find the 4 peaks, which should be at the corners.
19 Comments
Image Analyst
on 22 Dec 2017
See my attached shape recognition demo for how to find corners using findpeaks().
Image Analyst
on 23 Dec 2017
See how it helps to post the image? Now my answer is totally different.
What I'd do first is to snap another image of a white sheet and divide the images to get rid of the illumination gradient. Or if you can do that, then try to flatten the image with adapthisteq(). Then threshold to find the black lines, then call bwmorph(bw, 'skel', inf) to skeletonize it, then call bwmorph(bw, 'branchpoints') to find the line crossing locations.
If you need diagonal distances, you can use find() and kmeans() to find clusters of x and y points, then you know which points are where and you can get the distances.
My first method will still work but it will get the corners of the white squares while the other method will get the center of the black line crossing points, which is nearby but not the same location.
praveen rai
on 23 Dec 2017
earlier I forgot to upload my image
diagonalDistance1 = sqrt((x(1)-x(3))^2 + (y(1)-y(3))^2);
diagonalDistance2 = sqrt((x(2)-x(4))^2 + (y(2)-y(4))^2);
_with above lines can we find diagonals in my image & what about_ *shape_recognition_demo1.m* _is that relavent in my case??_
Image Analyst
on 23 Dec 2017
It depends on whether you want to find the center of the black crossing points, or the corner of the white quadrilaterals. If you want the corners of the white quadrilaterals, then the shape recognition demo will work.
praveen rai
on 23 Dec 2017
I want the points where black lines r intersecting 'do first is to snap another image of a white sheet and divide the images to get rid of the illumination gradient.' didnt understand this pint which u suggest and flattening the image is different from illumiantion gradient or it is step 2
praveen rai
on 23 Dec 2017
- i have to run this demo with my image den apply these thngs*' Then threshold to find the black lines, then call bwmorph(bw, 'skel', inf) to skeletonize it, then call bwmorph(bw, 'branchpoints') to find the line crossing locations.??
Image Analyst
on 23 Dec 2017
Edited: Image Analyst
on 26 Dec 2017
I don't understand the question. Did you run the functions as I suggested? It's trivial and I practically gave you the code already, so did you try it?
binaryImage = grayImage < threshold;
binaryImage = bwmorph(binaryImage, 'skel', inf);
endPointsImage = bwmorph(binaryImage, 'branchpoints');
[rows, columns] = find(endPointsImage);
% Find horizontal lines
[lineNumber, lineCenterY] = kmeans(rows, 7);
[columnNumber, lineCenterX] = kmeans(columns, 10);
and so on. Please try it. You're a smart engineer so I'm sure you can do it.
praveen rai
on 26 Dec 2017
Edited: praveen rai
on 26 Dec 2017
[lineNumber, lineCenterY] = kmeans(rows);
[columnNumber, lineCenterX] = kmeans(columns);
_for above code error is showing_ *' *at least two input argument is required**
Image Analyst
on 26 Dec 2017
When it says something like that you should look in the help. Pass in the number of lines in each direction for k.
praveen rai
on 28 Dec 2017
a = imread('Picture 20.jpg');
% Convert the image to gray level image
b= rgb2gray(a);
% smoothing image
Iblur1 = imgaussfilt(b,2);
% % figure,imshow(Iblur1);
% Apply adaptive histogram eqaulization to enahnce the contrast of the
% image
c=adapthisteq(Iblur1);
% Illumination Correction
MN=size(c);
background = imopen(c,strel('rectangle',MN));
I2 = imsubtract(c,background);
I3= imadjust(I2);
% figure,imshow(I3);
% % Convert to binary image
level = graythresh(b);
d=im2bw(I3,level);
bw = bwareaopen(d, 50);
% figure,imshow(bw);
binaryImage =bw<0.5;
binaryImage = bwmorph(binaryImage, 'skel', inf);
se=strel('line',8,1);
BW=imdilate( binaryImage,se);
se1=strel('line',8,90);
BW=imdilate(BW,se1);
% figure,imshow(BW);
% Convert to binary image to gray
uint8Image = uint8(255 *BW);
c=uint8Image;
figure,imshow(c);
bw3 = bwmorph(c, 'shrink',Inf);
figure,imshow(bw3);
c = detectHarrisFeatures(c);
plot(c);
endPointsImage = bwmorph(BW, 'branchpoints');
[rows, columns] = find(endPointsImage);
% Find horizontal lines
[lineNumber, lineCenterY] = kmeans(:,1);
[columnNumber, lineCenterX] = kmeans(1,:);
_i have applied this code but didnt find the corners and there respective (x,y) locations_
Image Analyst
on 28 Dec 2017
Look how you've called kmeans(), then compare to how I showed you and how it shows you in the help. Why do you think you're supposed to pass in colon and one to kmeans()???
praveen rai
on 28 Dec 2017
ya i have seen in help wrongly i have pasted this can u explain y we r finding endpointsImage and horizontal lines and is there any method like diffrentiating the horizontal and vertical lines and by doing that corner ponts will get am just asking m not sure about that?!
Image Analyst
on 28 Dec 2017
endpoints just gets the ends of the line. If you were to use find() on the entire image, then you'd get a bunch of points along the lines that would confuse the kmeans() in each direction.
praveen rai
on 28 Dec 2017
what is d purpose of finding end points and horizontal lines i mean to say i need d corners points and there respective location(x,y)
praveen rai
on 28 Dec 2017
is there any function in matlab like circle detector to detect square and find the corner?
More Answers (0)
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Tags
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)