pythonnumpydistancepixelunits-of-measurement

Distance measurements unit in 2d image points (python)


I used Python + Numpy to calculate the distance perpendicular to a point to a line defined by two points in a two-dimensional image (the coordinates of each point are the location of the point in the two-dimensional matrix of pixels.)

    p1, p2, p3 # as the points    
    
    # calculating the distance of p3 to the line constructed out of the p1 and p2
    # distance formula using the cross product approach
    d = numpy.linalg.norm(np.cross(p2-p1, p1-p3))/numpy.linalg.norm(p2-p1)

The question is :

What is the output measurement unit of distances that is calculated in this way?

Is the distance d calculated in 'pixel'?

If the answer is yes, How can I convert it to the millimeter and other measurement units?


Solution

  • I had the same problem when i worked on dicom images. If you are working on dicom, you can find a dicom tag named PixelSpacing. This tag is defined as two numbers like (0.02, 0.08); which the first number indicates the the row spacing in mm (vertical distance between two adjacent centers) and the second number indicates the column spacing in mm (horizontal distance between two adjacent centers.)