Lecture 2: Transformations and Histograms: H (K) Number of Pixels Whose Shade Equals K (U (I, J) K)
Lecture 2: Transformations and Histograms: H (K) Number of Pixels Whose Shade Equals K (U (I, J) K)
Images often are said to be light or dark or to lack contrast. In an attempt to be more precise about this, we use the matrix representation of an image. Each pixels image intensity is recorded by a component in its matrix. If the component is small (large), then the pixel is dark (light). If there are a large number of dark (light) pixels, then one may say the image is dark (light). Let k be an integer from 0 to 255 and represent a shade for a pixel at some location (i,j) in an mxn image matrix, u. Define a histogram of the image u to be the function from integers 0:1:255 to the integers 0:1:mn given by h(k) = number of pixels whose shade equals k (u(i,j) = k). The normalized histogram is H(k) = h(k)/(mn). If the image is dark (light), the histogram will be shifted to the left (right). If the image lacks contrast, the histogram will be clustered in the center. Example Pollen Histogram.
x 10
0 0
50
100
150
200
250
300
x 10
50
100
150
200
250
300
x 10
50
100
150
200
250
300
The above two Matlab codes transformed the grayscale of each pixel, by shifting the component of the image matrix up or down: T(h(i,j)) = h(i,j) + or - shift = new image matrix component. There are many other possibilities. Generally, any transformation of the image should be given by a mapping from the integers 0:1:255 into the integers 0:1:255. The mapping does not need to be onto the set 0:1:255, and some times there are transformations whose ranges may not be a subset of 0:1:255! Next we present two additional examples of transformation: the piecewise linear and the power transformations Piecewise Linear Transformation with Three Linear Parts. T(r) = s where r and s are in the integers 0:1:255. The new image matrix will have components equal to T(h(i,j)) The values of (r1,s1) and (r2,s2) can be chosen to obtain desired image enhancements. In the following code, they are chosen so as the give better contrast of the pollen image. The histogram of the original pollen image indicated a clustering of the middle shades. The choice of (r1,s1) and (r2,s2) were made so as to spread these over a larger range of shades.
(r1,s1) r
6000
5000
4000
3000
2000
1000
50
100
150
200
250
300
Power Transformation with c(r/255)^p. If 0< x <1, then x^2 (x^.5) will be concave up (down) and between 0 and 1. The transformation T( r) = c255(r/255)^2 ( = c255(r/255)^.5) will tend to move light (dark) pixels to darker (lighter) pixels. The following Matlab codes illustrate these for an aerial photo and a Mars rover photo. It makes use of Matlabs array operations, which are different than matrix operations. For example, matrix squared is the matrix times itself, and array squared is another matrix whose components are the squares of the array components. This is illustrated by a 2x2 array or matrix where matrix^2 is matrix*matrix, and matrix.^2 is another 2x2 matrix whose components are [1^2 2^2; 3^2 4^2].
% array product