How to convert resolution -> (inches, dpi)

is there a formula which will always convert a image resolution (x pixels by
y pixles) to inches, dpi
I'm assuming that there are some contraints to how high and low dpi can go.
How and what are those contraints.

This is needed since the charting package, that I'm migrating from, used
pixels to detemine the size of the chart.