Image Processing and Spatial linear transformations
22 Jun 2015We 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.
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
- Rotation by π/6
- Squeeze mapping with r=3/2
- Scaling by a factor of 3/2
- Scaling horizontally by a factor of 1/2
References
- http://www.iitg.ernet.in/scifac/qip/public_html/cd_cell/chapters/dig_image_processin.pdf
- http://www.math.ksu.edu/research/i-center/UndergradScholars/manuscripts/FernandoRoman.pdf
- http://www.statpower.net/Content/310/R%20Stuff/SampleMarkdown.html
- http://linear.ups.edu/html/section-LT.html
- http://www.r-bloggers.com/r-image-analysis-using-ebimage/
- http://www.maa.org/external_archive/joma/Volume8/Kalman/Linear3.html
- https://en.wikipedia.org/wiki/Linear_map
- https://en.wikipedia.org/wiki/Matrix_%28mathematics%29
- https://en.wikipedia.org/wiki/Affine_transformation
- http://mathforum.org/mathimages/index.php/Transformation_Matrix