Image Processing and Spatial linear transformations22 Jun 2015
We can think of an image as a function, f, from (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.
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:
For scaling we have \( x’; = s_x \cdot x \) and \( y’; = s_y \cdot y \). The matrix form is:
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:
The package EBImage is an R package which provides general purpose functionality for the reading, writing, processing and analysis of images.
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 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
- Rotation by π/6
- Squeeze mapping with r=3/2
- Scaling by a factor of 3/2
- Scaling horizontally by a factor of 1/2