extraction of corner points in grid image and how to calculate the distance between corner points
3 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Image Analyst
2017-12-22
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 个评论
Image Analyst
2017-12-22
See my attached shape recognition demo for how to find corners using findpeaks().
Image Analyst
2017-12-23
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
2017-12-23
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
2017-12-23
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
2017-12-23
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
2017-12-23
- 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
2017-12-23
编辑:Image Analyst
2017-12-26
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
2017-12-26
编辑:praveen rai
2017-12-26
[lineNumber, lineCenterY] = kmeans(rows);
[columnNumber, lineCenterX] = kmeans(columns);
_for above code error is showing_ *' *at least two input argument is required**
Image Analyst
2017-12-26
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
2017-12-28
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
2017-12-28
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
2017-12-28
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
2017-12-28
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
2017-12-28
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
2017-12-28
is there any function in matlab like circle detector to detect square and find the corner?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)