Package mapproxy :: Package core :: Module image :: Class ImageTransformer
[hide private]
[frames] | no frames]

Class ImageTransformer

source code

object --+
         |
        ImageTransformer

Transform images between different bbox and spatial reference systems.

Note:

The transformation doesn't make a real transformation for each pixel, but a mesh transformation (see PIL Image.transform). It will divide the target image into rectangles (a mesh). The source coordinates for each rectangle vertex will be calculated. The quadrilateral will then be transformed with the source coordinates into the destination quad (affine).

This method will perform good transformation results if the number of quads is high enough (even transformations with strong distortions). Tests on images up to 1500x1500 have shown that meshes beyond 8x8 will not improve the results.

        src quad                   dst quad
        .----.   <- coord-           .----.
       /    /       transformation   |    |
      /    /                         |    |
     .----.   img-transformation ->  .----.----
               |                     |    |
---------------.
large src image                   large dst image

Instance Methods [hide private]
 
__init__(self, src_srs, dst_srs, resampling=None, mesh_div=8)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
ImageSource
transform(self, src_img, src_bbox, dst_size, dst_bbox)
Transforms the src_img between the source and destination SRS of this ImageTransformer instance.
source code
 
_transform_simple(self, src_img, src_bbox, dst_size, dst_bbox)
Do a simple crop/extend transformation.
source code
 
_transform(self, src_img, src_bbox, dst_size, dst_bbox)
Do a 'real' transformation with a transformed mesh (see above).
source code
 
_no_transformation_needed(self, src_size, src_bbox, dst_size, dst_bbox) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, src_srs, dst_srs, resampling=None, mesh_div=8)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Parameters:
  • src_srs - the srs of the source image
  • dst_srs - the srs of the target image
  • resampling (nearest|bilinear|bicubic) - the resampling method used for transformation
  • mesh_div - the number of quads in each direction to use for transformation (totals to mesh_div**2 quads)
Overrides: object.__init__

transform(self, src_img, src_bbox, dst_size, dst_bbox)

source code 

Transforms the src_img between the source and destination SRS of this ImageTransformer instance.

When the src_srs and dst_srs are equal the image will be cropped and not transformed. If the src_bbox and dst_bbox are equal, the src_img itself will be returned.

Parameters:
  • src_img - the source image for the transformation
  • src_bbox - the bbox of the src_img
  • dst_size ((int(width), int(height))) - the size of the result image (in pizel)
  • dst_bbox - the bbox of the result image
Returns: ImageSource
the transformed image