Imported .obj has UV offset
The texture show up in the positive XY plane of the UV space, the unwrapped UV islands are placed where the creator of the obj positioned them. It may happens if someone is using repeated tiled textures (it's easy to lose the origin) or creating the model with another piece of software.

I think there may be lots of possible different cases, you shoul try to find the pattern that all the offsets have in common before writting a script for moving/resizing the UV islands for each one of the sources your files are coming from.

Automatic matching between rastered pixels of the texture sounds quite hard and just scaling &amp; resizing to the UV texture space size won't work in may cases.



In the provided example, I would say the UV islands are's just shifted below by the height of the texture in pixel. 

So grabbing the UV islands up by the amount of pixels your texture is high would be enough.