# Image Processing and Spatial linear transformations

We can think of an image as a function, f, from $\pmb R^2 \rightarrow R$ (or a 2D signal):

• f (x,y) gives the intensity at position (x,y)

Realistically, we expect the image only to be defined over a rectangle, with a finite range:
f: [a,b]x[c,d] -> [0,1]

A color image is just three functions pasted together. We can write this as a “vector-valued” function:

• Computing Transformations

If you have a transformation matrix you can evaluate the transformation that would be performed by multiplying the transformation matrix by the original array of points.

### Examples of Transformations in 2D Graphics

In 2D graphics Linear transformations can be represented by 2x2 matrices. Most common transformations such as rotation, scaling, shearing, and reflection are linear transformations and can be represented in the 2x2 matrix. Other affine transformations can be represented in a 3x3 matrix.

#### Rotation

For rotation by an angle θ clockwise about the origin, the functional form is $x’ = xcosθ + ysinθ$
and $y’ = − xsinθ + ycosθ$. Written in matrix form, this becomes:
$% $

#### Scaling

For scaling we have $x’; = s_x \cdot x$ and $y’; = s_y \cdot y$. The matrix form is:
$% $

#### Shearing

For shear mapping (visually similar to slanting), there are two possibilities.
For a shear parallel to the x axis has $x’; = x + ky$ and $y’; = y$ ; the shear matrix, applied to column vectors, is:
$% $

A shear parallel to the y axis has $x’; = x$ and $y’; = y + kx$ , which has matrix form:
$% $

### Image Processing

The package EBImage is an R package which provides general purpose functionality for the reading, writing, processing and analysis of images. #### Image Properties

Images are stored as multi-dimensional arrays containing the pixel intensities. All EBImage functions are also able to work with matrices and arrays.

• Adjusting Brightness  • Adjusting Contrast  • Gamma Correction   • Cropping Image ### Spatial Transformation

Spatial image transformations are done with the functions resize, rotate, translate and the functions flip and flop to reflect images.

Next we show the functions flip, flop, rotate and translate:    #### All spatial transforms except flip and flop are based on the general affine transformation.

Linear transformations using the function affine:

• Horizontal flip • Horizontal shear ${m} = \left[ \begin{array}{cc} 1, 1/2 \cr \\ 0, 1 \end{array} \right]$ • Rotation by π/6 ${m} = \left[ \begin{array}{cc} cos(pi/6), -sin(pi/6) \cr \\ sin(pi/6), cos(pi/6) \end{array} \right]$ • Squeeze mapping with r=3/2 ${m} = \left[ \begin{array}{cc} 3/2, 0 \cr \\ 0, 2/3 \end{array} \right]$ • Scaling by a factor of 3/2 ${m} = \left[ \begin{array}{cc} 3/2, 0 \cr \\ 0, 3/2 \end{array} \right]$ • Scaling horizontally by a factor of 1/2 ${m} = \left[ \begin{array}{cc} 1/2, 0 \cr \\ 0, 1 \end{array} \right]$ If you liked this post, you can share it with your followers or follow me on Twitter!

comments powered by Disqus
<<<<<<< HEAD