Salutations,
Note: In picture use, to figure out a distance between two objects, you normally just use a simple ratio approach. In other words, you use the pixels to manipulate a distance. To know the true value of this distance, then you need to know the true value of something else.
Mathematically:
Pixel Size Object 1/Known Size = Pixe Size Object 2/Unknown Size
Where you solve for Unknown Size.
My boss has written a program that does what you're asking, which I will include on this page. However, since this is for "collage", I trust you'll be only using it as a reference and not as something to borrow.
The program is simple enough, load an image, draw a line and enter a true value for that line... then draw another line and the distance will be accounted for. The zoom on it isn't perfect, the lines don't come out in the right places, however, the distances are correct. Just make sure, you calibrate on whatever zoom you're going to use.
Sincerely,
ElSmith