1
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ yes unit is pixels. multiply by the dimension a pixel represents in meters ^2. $\endgroup$
    – george2079
    Feb 22, 2016 at 22:23
  • $\begingroup$ 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. $\endgroup$
    – Odrisso
    Feb 22, 2016 at 22:39
  • $\begingroup$ 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. $\endgroup$
    – george2079
    Feb 22, 2016 at 22:46
  • $\begingroup$ @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. $\endgroup$
    – m_goldberg
    Feb 22, 2016 at 22:54

1 Answer 1

4
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – Odrisso
    Feb 22, 2016 at 23:44
  • 1
    $\begingroup$ @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. $\endgroup$
    – Michael E2
    Feb 23, 2016 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.