1.Scanner - Geometric transformation

2 minute read

Image filtering



1. Transformation of image and shear transition

  • Meaning of geometric transformation
    • The task to change the whole image by altering arrangement of pixel composing image.
    • ex) Image registration, removal of geometric distortion, etc.

image

  • Translation transformation
    • The transformation moving the image as specific size to horizontal or vertical direction.
    • It have to set the translation displacement of x-axis and y-axis


image


  • Affine transformation function

cv2.warpAffine(src, M, dsize, dst=None, flags=None, borderMode=None, borderValue=None) -> dst

  • src : Input image
  • M : 2 x 3 affine metrix
  • dsize : Result image size
  • dst : Output image
  • flags : Interpolation type
  • borderMode : Edge pixel expension method
  • borderValue : default value is 0


  • Example of translation transformation of the image

image


  • Shear transformation
    • It have to set each x-axis and y-axis.



2. Shrinkage and enlargement of image


  • Scale transformation
    • The transformation that size of image make larger or smaller than original image.
    • Specifying the scale factor of x-axis and y-axis


image


  • Scale transformation code
cv2.resize(src, dsize, dst=None, fx=None, fy=None, interpolation=None) -> dst
  • src : Input image
  • dsize : Output image size
  • dst : Out image
  • fx,fy : scale factor of x,y direction
  • interpolation : decide interpolation


  • Scale transformation example


image


  • Scale transformaion precaution
    • When scale transformation be applied to image, Detail of image disappear
    • After Filtering smoothly input image, It apply to step by step shirinkage.
    • cv2.INTER_AREA flag is used in cv2.resize() function of OpenCV


image



3. Image pyramid


  • Image pyramid
    • Image sets of various resolution for one of image
    • Generally, It’s consist of shrinkage size using Gaussian blurring & Down sampleing


image


  • Image pyramid downsampling code


cv2.pyrDown(src, dst=None, dstsize=None, borderType=None) -> dst
  • src : Input image
  • dst : Output image
  • dstsize : Output image size
  • borderType : Edge pixel expansion method *** note
    • Firstly, It’s applied to Gaussian filter of 5x5 size. Then, Small size of image is made from delete even number of column and row.


  • Image pyramid upsmapling code
cv.pyrUp(src, dst=None, dstsize=None, borderType=None) -> dst
  • src : Input image
  • dst : Output image
  • dstsize : Output image size
  • borderType : Edge pixel expansion method


  • Image pyramid example


image



4. Rotaion of image


  • Rotation transformation
    • Transformating image to rotate by specific angle


image


  • Rotation transformation code


cv2.getRotationMatrix2D(center, angle, scale) -> retval


  • center : Rotational center coordination
  • angle : Rotaion degree
  • scale : Additional magnification ratio
  • retval : 2 X 3 Affine transformation matrix


image



5. Affine Tansform and Perspective Transform

  • Diffrent point between affine transform and perspectiv transform


image


image


  • To get affine transform matrix


cv2.getAffineTransfrom(src, dst) -> retval


  • src : Three point of original coordinate
  • dst : Three point of result coordinate
  • retval : 2 x 3 perspective transform matrix


cv2.getPerspectiveTransfrom(src, dst) -> retval


  • src : Four point of original coordinate
  • dst : Four point of result coordinate
  • retval : 3 x 3 perspective transform matrix


  • Perspective transform example


image



6. Remapping


  • Remapping
    • Normal process specific position pixel of image rearranes to other position


image


image


  • Remapping could express various trasformation with affine transform, perspective transform


  • Remapping code


cv2.remap(src, map1, map2, interpolation, dst=None, borderMode=None, borderValue=None) -> dst


  • src : Input image
  • map1 : x-coordination of input image
  • map2 : y-coordination of output image
  • interpolation : Interpolation
  • dst : Output image
  • borderMode : Edge pixel expansion method
  • borderValue : Constant value


  • Remapping example using trigonometic function


image


Leave a comment