distance

Fastest available algorithm for distance transform

有些话、适合烂在心里 提交于 2020-01-19 04:48:45
问题 I am looking for the fastest available algorithm for distance transform. According to this site http://homepages.inf.ed.ac.uk/rbf/HIPR2/distance.htm, it describes: "The distance transform can be calculated much more efficiently using clever algorithms in only two passes (e.g. Rosenfeld and Pfaltz 1968)." Searching around, I found: "Rosenfeld, A and Pfaltz, J L. 1968. Distance Functions on Digital Pictures. Pattern Recognition, 1, 33-61." But I believe we should have a better and faster

Fastest available algorithm for distance transform

倖福魔咒の 提交于 2020-01-19 04:48:26
问题 I am looking for the fastest available algorithm for distance transform. According to this site http://homepages.inf.ed.ac.uk/rbf/HIPR2/distance.htm, it describes: "The distance transform can be calculated much more efficiently using clever algorithms in only two passes (e.g. Rosenfeld and Pfaltz 1968)." Searching around, I found: "Rosenfeld, A and Pfaltz, J L. 1968. Distance Functions on Digital Pictures. Pattern Recognition, 1, 33-61." But I believe we should have a better and faster

Computing the distance to a convex hull

会有一股神秘感。 提交于 2020-01-14 12:59:23
问题 I am using the ConvexHull class of scipy to construct a convex hull for a set of points. I am interested in a way to compute the minimum distance of a new point P from the convex hull. With the help of the internet and a little tweaking by myself I came up with this formula to compute the distance of a point P or a set of points points to the convex hull facets: np.max(np.dot(self.equations[:, :-1], points.T).T + self.equations[:, -1], axis=-1) For a convex hull in 2D the equation above will

Effificient distance-like matrix computation (manual metric function)

倖福魔咒の 提交于 2020-01-14 05:55:08
问题 I want to compute a "distance" matrix, similarly to scipy.spatial.distance.cdist, but using the intersection over union (IoU) between "bounding boxes" (4-dimensional vectors), instead of a typical distance metric (like the Euclidean distance). For example, let's suppose that we have two collections of bounding boxes, such as import numpy as np A_bboxes = np.array([[0, 0, 10, 10], [5, 5, 15, 15]]) array([[ 0, 0, 10, 10], [ 5, 5, 15, 15]]) B_bboxes = np.array([[1, 1, 11, 11], [4, 4, 13, 13], [9

Effificient distance-like matrix computation (manual metric function)

帅比萌擦擦* 提交于 2020-01-14 05:54:05
问题 I want to compute a "distance" matrix, similarly to scipy.spatial.distance.cdist, but using the intersection over union (IoU) between "bounding boxes" (4-dimensional vectors), instead of a typical distance metric (like the Euclidean distance). For example, let's suppose that we have two collections of bounding boxes, such as import numpy as np A_bboxes = np.array([[0, 0, 10, 10], [5, 5, 15, 15]]) array([[ 0, 0, 10, 10], [ 5, 5, 15, 15]]) B_bboxes = np.array([[1, 1, 11, 11], [4, 4, 13, 13], [9

Distance between two rectangles

北慕城南 提交于 2020-01-13 19:09:03
问题 How can I find the distance between two rectangles? Intersects should return 0 in distance. 回答1: Here's a quick function for calculating distance between two CGRects represented by a CGSize: CGSize CGSizeDistanceBetweenRects(CGRect rect1, CGRect rect2) { if (CGRectIntersectsRect(rect1, rect2)) { return CGSizeMake(0, 0); } CGRect mostLeft = rect1.origin.x < rect2.origin.x ? rect1 : rect2; CGRect mostRight = rect2.origin.x < rect1.origin.x ? rect1 : rect2; CGFloat xDifference = mostLeft.origin

Algorithm to find all points on a 2D grid some distance away from another point

喜你入骨 提交于 2020-01-13 09:32:34
问题 I have some point on a 2D grid (x, y) and I need to find all points that are n distance away from that point. The way I'm measuring distance is by using the distance formula between the two points. Anyone know how to do this? Edit: Just for reference, what I'm trying to do is to write some AI path finding that will maintain some distance away from a target in a system that uses grid based locations. Currently I'm using A* path finding, but I'm not sure if that matters or makes a difference

Fastest way to find the closest point to a given point in 3D, in Python

拟墨画扇 提交于 2020-01-12 07:07:29
问题 So lets say I have 10,000 points in A and 10,000 points in B and want to find out the closest point in A for every B point. Currently, I simply loop through every point in B and A to find which one is closest in distance. ie. B = [(.5, 1, 1), (1, .1, 1), (1, 1, .2)] A = [(1, 1, .3), (1, 0, 1), (.4, 1, 1)] C = {} for bp in B: closestDist = -1 for ap in A: dist = sum(((bp[0]-ap[0])**2, (bp[1]-ap[1])**2, (bp[2]-ap[2])**2)) if(closestDist > dist or closestDist == -1): C[bp] = ap closestDist =

“Distance” (or angular magnitude) between two quaternions?

谁说我不能喝 提交于 2020-01-12 05:45:06
问题 I want to find the "distance" between two quaternions. By "distance" I mean a single float or int, not another quaternion (that would be the difference, i.e. inverse(q1)*q2 ). I guess you could call what I want "angular magnitude". I need to apply more torque to a physics object the further it's rotated from its original angle. I don't understand the maths involved in quaternions, so a code-based example would be most helpful. I've looked at several other questions but I don't believe any

geodesic distance transform in python

岁酱吖の 提交于 2020-01-11 23:08:42
问题 In python there is the distance_transform_edt function in the scipy.ndimage.morphology module. I applied it to a simple case, to compute the distance from a single cell in a masked numpy array. However the function remove the mask of the array and compute, as expected, the Euclidean distance for each cell, with non null value, from the reference cell, with the null value. Below is an example I gave in my blog post: %pylab from scipy.ndimage.morphology import distance_transform_edt l = 100 x,