1

I have an image. I found the dimensions of the image as the following code:

  ImageDimensions[img]

I found the image dimension as {224, 88}. Now, I run the voronoi mesh by image corners as follows:

c = ImageCorners[img, MaxFeatures -> 20];
vm = VoronoiMesh[c];

Now, I calculate the area of the meshes by following code:

 area = PropertyValue[{vm, 2}, MeshCellMeasure]

I found the following values of the area:

 area = {228.984, 625.627, 355.573, 683.894, 1504.49, 354.351, 1621.32, 
 2025.66, 1705.12, 1372.34, 151.88, 745.945, 3366.67, 272.885, 
 241.687, 345.624, 2768.74, 1836.03, 5300.41, 2275.76}

Now, I want to know the unit of the area of these polygons. Are the in DPI? Is it possible to present them in meter-square?

Odrisso
  • 191
  • 6
  • yes unit is pixels. multiply by the dimension a pixel represents in meters ^2. – george2079 Feb 22 '16 at 22:23
  • Hi, Thanks for your comment. But, I still don't get the answer. So you are saying those values are dot per inch (DPI)? Can you Please explain why? I don't understand it. – Odrisso Feb 22 '16 at 22:39
  • well not "dpi" (dots per inch), just dots. The entire image area is 228*88=19712 "dots" or pixels. Mathematica image data doesn't contain any resolution information to be able to map pixels to a physical size. – george2079 Feb 22 '16 at 22:46
  • @george2079. If the elements give in area were in square-pixels, I would expect Total @ area - 224*88 to be close to zero, but it's 8070.99. So I think we need access to the actual image to figure out what is going on. – m_goldberg Feb 22 '16 at 22:54

1 Answers1

4

I see whats happening:

VoronoiMesh doesn't know the dimensions of the image and produces a meshregion that is larger than the image. You can supply the image dimensions to VoronoiMesh as a second argument and it works out just right.

using the "tower bridge" image from the ImageCorners doc page:

c = ImageCorners[img, MaxFeatures -> 20];
dim = ImageDimensions[img]

{320, 233}

vm = VoronoiMesh[c, {{0, dim[[1]]}, {0, dim[[2]]}}];
area = PropertyValue[{vm, 2}, MeshCellMeasure]
Total@area
Times @@ dim

74560.

74560

Show[img, Graphics[{{Blue, PointSize[.02], Point[c]},
   FaceForm[Transparent], EdgeForm[Red], MeshPrimitives[vm, 2]}]]

enter image description here

so now suppose that image is 160 meters wide (yes I wiki'd the span of the tower bridge), then each pixel is a half meter square, so multiply your areas by (1/2)^2 to get the area values in square meters.

Here is what VoronoiMesh generated originally:

enter image description here

george2079
  • 38,913
  • 1
  • 43
  • 110
  • Hi, that's a great example. So, you are saying that, if I want to convert it in meters then I need to know the actual size of that object. Other wise I can't find how much each pixel is equal to meter square. Right?

    So, In general, can you please tell me what is the unit of the area= 74560 in this image? is it in pixel?or DPI?

    – Odrisso Feb 22 '16 at 23:44
  • 1
    @Odrisso DPI is not a unit of area. It's a unit of linear density. In a digital image, a pixel represents a square region and thus could be considered a geometric area (not an area measurement per se). The measurements above treat the pixel as the unit square and measure areas in units of pixels. – Michael E2 Feb 23 '16 at 12:52