Reputation: 865
I have an image of indoor map on my browser and I could calculate the coordinates of random points on the image in pixels. I want to convert these coordinates to meters. For example, I want to convert (123, 246) in pixels to (10, 20) in meters.
I have the width and height of the building in meters and also the size of the image in pixels. What would be the best way to calculate the pixels to meter ratio so that I can convert these back and forth?
I am using mostly JavaScript to do all this.
Upvotes: 2
Views: 2070
Reputation: 4318
If you know the width of the building in pixel and meters, the ratio meters:pixels is simply widthInMeters / widthInPixels
. Your question suggests you have the width of the image, but not that of the building, but also that you are able to calculate the location of random points in pixels. Therefore all you have to do is measure the width of the building in pixels as it is represented in the image, then divide the actual width by this number.
You should note that a pixel is not a continuous measure like a meter, so the precision is going to be limited by your scale (e.g. 6.3 pixels looks the same as 6 pixels). Also, if the image has not been accurately drawn or encoded, the ratio horizontally could be different to the one vertically.
Upvotes: 1