Message Boards Message Boards

0
|
7401 Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

[?] Measure distance between objects in an image?

Posted 7 years ago

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

POSTED BY: Manoj Imrith
4 Replies
Posted 7 years ago

Hi Vitality/Henrik,

Thanks for help.

Regs

POSTED BY: Manoj Imrith

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}]

enter image description here

POSTED BY: Vitaliy Kaurov

Dear @Vitaliy Kaurov,

excellent - I always prefer simple solutions! Thanks for sharing!

Best regards -- Henrik

POSTED BY: Henrik Schachner

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]

gives

enter image description here

Here the distances are given in terms of image pixels.

Hope that helps, regards -- Henrik

POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract