6.6 Image Affine Transformation and Scaling

Affine transformation is the process of using geometric transformations of translation, scaling, rotation, shearing, and reflection on an image to produce another image.

For details and examples, see the SDO_GEOR.affineTransform reference topic.

Image scaling is the process of enlarging or shrinking an image by changing the pixel size for the row and column dimensions of an image. Image scaling resamples the pixel values from the original image to construct the rescaled version of that image. Image scaling can be performed in several ways:

  • Use the SDO_GEOR.scaleCopy procedure and specify for scaleParam a scaleFactor to be applied to the input image dimensions or a maxDimSize for the output image.

  • Use the SDO_GEOR.rectify procedure and specify the resolution of the output image. (This procedure can be executed in parallel.)

  • During affine transformation, use the scales parameter of the SDO_GEOR.affineTransform procedure. In that procedure, the scales parameter is a two-number array where you can specify a scale factor for rows and for columns independently. (This procedure can be executed in parallel.)

Example 6-9 Image Scaling Using SDO_GEOR.scaleCopy

This example performs rescaling by using SDO_GEOR.scaleCopy and specifying the scaleFactor value as 2. The input image will have 2 times more rows and 2 times more columns than the original, and the values will be resampled by the average16 algorithm. Note that the image will be 4 times larger than the original.

DECLARE
  gr_src  sdo_georaster;
  gr_out  sdo_georaster;
BEGIN
  select georaster into gr_src from georaster_table where georid = 7;
  -- Rescale
  delete from georaster_table where georid = 9;
  insert into georaster_table values(9, 're-scaled by scaleCopy',
              sdo_geor.init('rdt_4',9)) 
              returning georaster into gr_out;
  sdo_geor.scaleCopy(inGeoRaster      => null,
                     scaleFactor      => 'scaleFactor=2',
                     resampleParam    => 'resampling=AVERAGE16',
                     storageParam     => null,
                     outGeoraster     => gr_out);
  update georaster_table set georaster = gr_out where georid = 9;
  commit;
END;
/

Example 6-10 Image Scaling Using SDO_GEOR.rectify

This example performs rescaling by using SDO_GEOR.rectify and specifying the outResolutions parameter. The input image is already rectified, and the output will have the same SRID as the input.

DECLARE
  gr_src     sdo_georaster;
  gr_out     sdo_georaster;
BEGIN
  select georaster into gr_src from georaster_table where georid = 7;
  -- Rescale
  delete from georaster_table where georid = 10;
  insert into georaster_table values(10, 're-scaled by rectify',
              sdo_geor.init('rdt_4',10)) 
              returning georaster into gr_out;
  sdo_geor.rectify(inGeoRaster      => null,
                   pyramidLevel     => null,
                   elevationParam   => null,
                   dem              => null,
                   outSRID          => null,
                   outModelCoordLoc => null,
                   cropArea         => null,
                   polygonClip      => null,
                   layerNumbers     => null,
                   outResolutions   => sdo_number_array(1.2,1.2),
                   resolutionUnit   => null,
                   referencePoint   => null,
                   resampleParam    => 'resampling=CUBIC',
                   storageParam     => null,
                   outGeoraster     => gr_out,
                   parallelParam    => 'parallel=4');
  update georaster_table set georaster = gr_out where georid = 10;
  commit;
END;
/

Example 6-11 Rescaling Using SDO_GEOR.affineTransform

This example performs rescaling by using the SDO_GEOR.affineTransform procedure and specifying the scales parameter as sdo_number_array(2, 2), indicating that the image will be enlarged 2 times on the rows dimension and 2 times on the columns dimension.

DECLARE
  gr1 sdo_georaster;
  gr2 sdo_georaster;  
BEGIN
  select georaster into gr1 from georaster_table where georid = 1;

  insert into georaster_table values(2, 'Rotated 90 left',
         sdo_geor.init('rdt0',2)) returning georaster into gr2;

  sdo_geor.affineTransform(inGeoRaster   => gr1,
                           translation   => null,
                           scales        => sdo_number_array(2,2),
                           rotatePt      => null,
                           rotateAngle   => null,
                           shear         => null,
                           reflection    => null,
                           storageParam  => null,
                           outGeoraster  => gr2,
                           parallelParam => 'parallel=4');

  update georaster_table set georaster = gr2 where georid = 2;
  commit;
END;