Distance between multiple lines

Say that my images are simple shapes - a lot of lines, points, curves and simple objects. How to calculate the distance between images - length is so important, but the general scale does not matter, the location of the line \ curve is important, angles are important, etc. .

Attached Image For example:

My comparison object is a cube in the upper left corner, the rating is fictitious only for this example.

  • that the distance to the cylinder is 80 (has two lines, but the upper geometry is different).
  • The score for the bottom left cube is 100, because it exactly matches the lines with different scales.
  • The bottom right Rectangle score is 90 because it has exact lines of correspondence from above, but different scale lines to the side.

I am looking for the name of an algorithm or a general approach that will help me start thinking about a solution ...

Thank you for your help.

enter image description here

+4
source share
3 answers

Here you are to get you started. When you encounter new problems, I don’t see much value, trying to perform many complex steps just because they are available somewhere to use. Therefore, I focus on using relatively simple things that will fail in more diverse situations, but I hope you see its value and get some idea of ​​the problem.

The approach is entirely based on determining the angle; The two typical methods for this detection are the Harris detector, or one of them, Shi and Tomashi, described in Good Tracking Features, 1994. I will use the second option only because there is a ready-made implementation in OpenCV, a newer Matlab, and, possibly, in many other places. Its implementation on these packages also allows you to simplify the configuration of parameters related to the quality of the corners and the minimum distance between the corners. So, suppose you can correctly identify all the corner points, how do you measure how close one shape is to the other, based on these points? Images are of arbitrary size, so my idea is to normalize the coordinates of the point to the range [0, 1]. This solves the scaling problem that is required by the original description. Now we need to compare the sets of points in the range [0, 1]. Here we consider the simplest thing: consider one point p from the form a , what is the nearest point in the form b ? Suppose that it is a unit with a minimum absolute different between this point p and any point in b. If we sum all the values, we get a gain between the pieces. The lower the score, the more similar forms (in accordance with this approach).

Here are some of the shapes I painted:

enter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description here

Here are the angles found:

enter image description hereenter image description hereenter image description hereenter image description hereenter image description here <T411>

As you can clearly see in this last set of images, the method easily confuses a rectangle / square with a cylinder. To handle this, you will need to combine the approach with other descriptors. Initially, a simple one that you can consider is the relationship between the area of ​​the form and the area of ​​its bounding rectangle (which will give 1 for the rectangle and lower for the cylinder).

Using the method described above, measurements are made between the first and second figures, the first and third figures, ... 0.02358485, 0.41350339, 0.30128458 0.4980852, 0.18031262. The second cube is a modified version of the first, and, as you can see, they are very similar in this metric. The last form is a modified version of the first cube, but without maintaining the proportion, and the metric gives a much bigger difference.

If you want to play with code that does this, here it is (in Python, depends on OpenCV, numpy):

 import sys import cv2 as cv import numpy inp = [] for fname in sys.argv[1:]: img_color = cv.imread(fname) img = cv.cvtColor(img_color, cv.COLOR_RGB2GRAY) inp.append((img_color, img)) ptsets = [] # Corner detection parameters. params = ( 200, # max number of corners 0.01, # minimum quality level of corners 10, # minimum distance between corners ) # Params for visual circle markers. circle_radii = 3 circle_color = (255, 0, 0) for i, (img_color, img) in enumerate(inp): height, width = img.shape cornerMap = cv.goodFeaturesToTrack(img, *params) corner = numpy.array([c[0] for c in cornerMap]) for c in corner: cv.circle(img_color, tuple(c), circle_radii, circle_color, -1) # Just to visually check for correct corners. cv.imwrite('temp_%d.png' % i, img_color) # Convert corner coordinates to [0, 1] cornerUnity = (corner - corner.min()) / (corner.max() - corner.min()) # You might want to use other descriptors here. XXX ptsets.append(cornerUnity) def compare_ptsets(p): res = numpy.zeros(len(p)) base = p[0] for i in xrange(1, len(p)): sum_min_diff = sum(numpy.abs(p[i] - value).min() for value in base) res[i] = sum_min_diff return res res = compare_ptsets(ptsets) print res 
+2
source

The process to be followed depends on what depth of function you are going to consider and the required accuracy.

If you want something more accurate, search for some technical documents, such as this , that can provide a specific and well-established approach or algorithm.

EDIT:

The idea from the waltz algorithm (one method in AI) can be changed. This is just my thought. Interpret the original image, create some limitations from it. For each candidate, find out the number of restrictions that he meets. One that satisfies more restrictions will be most similar to the original image.

+1
source

Try to calculate the center of mass for each shape. Consider each point in the figure as a particle with a mass equal to 1.

Then calculate each distance as sqrt((x1-x2)^2 + (y1-y2)^2) , where (xi, yi) is the center center coordinate for figure i.

0
source

All Articles