# [✓] Measure distance between objects in an image?

GROUPS:
 Hello, I would require to create an image measurement tool (to measure distance between objects in an image) in Mathematica. It is not available in the documentation.Thanks
1 year ago
4 Replies
 Henrik Schachner 3 Votes Hello Man Oj,with Mathematica it is no problem to make such a tool. Here comes a simple example: fourLocators[img_Image, mag_: 1] := DynamicModule[{imgdim, pt0, pt}, imgdim = ImageDimensions[img]; pt0 = {imgdim[[1]]/2, imgdim[[2]]/2}; pt = {pt0 + {1, 1}, pt0 + {1, -1}, pt0 + {-1, 1}, pt0 + {-1, -1}}; Column@{LocatorPane[Dynamic[pt], Image[img, ImageSize -> mag imgdim], Appearance -> {Style["+", Red], Style["+", Red], Style["+", Green], Style["+", Green]}], Dynamic["DistRed" -> EuclideanDistance[pt[[1]], pt[[2]]]], Dynamic["DistGreen" -> EuclideanDistance[pt[[3]], pt[[4]]]]} ] Let's try: img = Image@DensityPlot[Sin[x] Cos[y/2], {x, -5, 5}, {y, -5, 5}, Frame -> False, PlotPoints -> 50]; fourLocators[img] givesHere the distances are given in terms of image pixels.Hope that helps, regards -- Henrik
 Vitaliy Kaurov 2 Votes A simpler alternative to @Henrik's nice version: i = ExampleData[{"TestImage", "House"}]; Manipulate[ Labeled[Show[i, Graphics[Line[pt]]], EuclideanDistance @@ pt], {{pt, Min[ImageDimensions[i]] {{.3, .3}, {.6, .6}}}, Locator}]