1

In a similar question, I read that one can create a GeoTIFF image from a JPEG using the Python GDAL API. I created a small example here:

def translateIMG(path_in, path_out, in_format = "GTiff"):
    from osgeo import gdal
    ds = gdal.Open(path_in)
    ds = gdal.Translate(path_out, ds)
    ds = None

inp = "C:\\Users\\Manuel\\Nextcloud\\Masterarbeit\\dat\\tls\\Test\\X\\0\\X00000029_X.tif"
oup = "C:\\Users\\Manuel\\Nextcloud\\Masterarbeit\\dat\\tls\\Test\\X\\0\\X00000029_X.jpg"
translateIMG(inp, oup)

In the process, a .aux.xml file is created that enables GDAL to translate the JPEG back to a GeoTIFF.

Now, my problem is the following: I don't have GeoTIFFs to translate to JPEG and back, but I have a large number of JPEG images with geo information (lon, lat, z). The images are drone images; I know the flight altitude, the camera properties, the angle at which they were taken, etc. I would like to do some "rough" geo referencing based on those data.

Hence, I wondered whether there is a way to translate the information I have to create an .aux.xml file similar to the one that gets created when translating a GeoTIFF. With this, I imagine, I could transform the JPEGs to GeoTIFFs with approximately correct spatial information. I don't know if information about the orientation of the drone (North/West/etc) could be extracted, though, but it would even help if I could visualise where the images were taken, relatively to each other, to see how they approximately tile the area.

The background is to see how the images are distributed in space, what area they cover (or don't cover) and to mark certain areas/points on the images in a shapefile (again, exact spatial position matters only relative to the image content).

The .aux.xml files look like this:

<PAMDataset>
  <SRS dataAxisToSRSAxisMapping="1,2">PROJCS["WGS 84 / UTM zone 35S",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",27],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32735"]]</SRS>
  <GeoTransform>  6.3783880884774099e+05,  1.1203100148122758e-02,  0.0000000000000000e+00,  7.3644023382299999e+06,  0.0000000000000000e+00, -1.1203100148122758e-02</GeoTransform>
  <Metadata domain="IMAGE_STRUCTURE">
    <MDI key="COMPRESSION">JPEG</MDI>
    <MDI key="INTERLEAVE">PIXEL</MDI>
    <MDI key="SOURCE_COLOR_SPACE">YCbCr</MDI>
  </Metadata>
  <Metadata>
    <MDI key="AREA_OR_POINT">Area</MDI>
  </Metadata>
  <PAMRasterBand band="1">
    <NoDataValue>2.55000000000000E+02</NoDataValue>
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG</MDI>
    </Metadata>
    <Metadata>
      <MDI key="STATISTICS_MAXIMUM">52</MDI>
      <MDI key="STATISTICS_MEAN">1.#SNAN</MDI>
      <MDI key="STATISTICS_MINIMUM">0</MDI>
      <MDI key="STATISTICS_STDDEV">1.#SNAN</MDI>
    </Metadata>
  </PAMRasterBand>
  <PAMRasterBand band="2">
    <NoDataValue>2.55000000000000E+02</NoDataValue>
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG</MDI>
    </Metadata>
    <Metadata>
      <MDI key="STATISTICS_MAXIMUM">62</MDI>
      <MDI key="STATISTICS_MEAN">1.#SNAN</MDI>
      <MDI key="STATISTICS_MINIMUM">0</MDI>
      <MDI key="STATISTICS_STDDEV">1.#SNAN</MDI>
    </Metadata>
  </PAMRasterBand>
  <PAMRasterBand band="3">
    <NoDataValue>2.55000000000000E+02</NoDataValue>
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG</MDI>
    </Metadata>
    <Metadata>
      <MDI key="STATISTICS_MAXIMUM">49</MDI>
      <MDI key="STATISTICS_MEAN">1.#SNAN</MDI>
      <MDI key="STATISTICS_MINIMUM">0</MDI>
      <MDI key="STATISTICS_STDDEV">1.#SNAN</MDI>
    </Metadata>
  </PAMRasterBand>
</PAMDataset>

I guess the extent of the raster image is stored in the GeoTransform tag, but I don't know how...

1 Answer 1

0

I had this same problem (jpeg and lat/long boundbox info) but couldn't directly use gdal.Translate within Python.

I was successful after converting the image to GTiff using gdal_translate (command line)

gdal_translate -of GTiff in.jpeg tif_out.tif

Then running gdal.Translate (within Python) on the converted tif file worked!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.