**2. Brief of mathematics for image processing**

Digital image processing has developed rapidly along with the advances in computing and mathematical advances, to nurture the ever-growing demand for technological luxuries.

#### **2.1 Mathematics in image processing**

Mathematical image processing is widely used in fields such as medical imaging, surveillances, video transmission, astrophysics and many more. Signals are one dimensional image. Planar images are in two dimension and volumetric are in three dimensions. Images in grey scale are classified as single valued functions while coloured images are vector valued functions. The imperfections such as blurring and noise reduce the quality of the image.

#### **2.2 Image formation model**

Mathematically a planar image is represented by a function form as spatial domain to a function value,

$$f(\mathbf{x}, \mathbf{y}) \to f(\mathbf{x}, \mathbf{y}) \tag{1}$$

In an image the intensity value is the energy radiated by the physical source.

$$0 < f(\varkappa, y) < \infty \tag{2}$$

*f x*ð Þ , *y* depends on the illumination *i x*ð Þ , *y* and the reflectance *r x*ð Þ , *y* hence,

$$f(\mathbf{x}, \mathbf{y}) = i(\mathbf{x}, \mathbf{y})r(\mathbf{x}, \mathbf{y}) \tag{3}$$

A similar expression is applicable to the images formed by transmission through a medium.

### **2.3 Image sampling**

Sampling means digitalization of coordinate values and digitalizing the amplitude means quantization. A digital image is represented as a matrix and the number of grey levels is taken in powers of 2.

#### **2.4 Intensity transformation and spatial filtering**

For improving contrast, a statistical tool of histogram equalizer is used. Consider a low contrast/dark image or light image as input image *p x*ð Þ , *y* and an output as a high contrasted image *m x*ð Þ , *y* .

Assume that the grey-level range consists of L grey-levels. In the discrete case, let *rk* ¼ *p x*ð Þ , *y* be a gray level of

$$p.k = 0, 1, 2, \dots \\ L-1. \tag{4}$$

Le*sk*¼ *m x*ð Þ , *y* be the desired gray level of output image *m*. A transformation *T* :

$$[0, L - 1] \to [0, L - 1] \text{ such that } \\ \mathfrak{s}\_k = T(r\_k), \text{ for all } k = 0, 1, 2, \dots, L - 1. \tag{5}$$

Define *h r*ð Þ¼ *<sup>k</sup> nk* where *rk i*s the kth grey level, and *nk* is the number of pixels in the image p taking the value *rk*.

Visualization of discrete function gives histogram.

In the discrete case, let *rk* ¼ *p x*ð Þ , *y* . Then we define the histogram-equalized image *m* atð*x*, *y* ) by

$$m(\mathbf{x}, \mathbf{y}) = \mathbf{s}\_k = (L - \mathbf{1}) \sum\_{j=0}^{k} p(r\_j) \tag{6}$$

Theoretical interpretation of histogram equalization (continuous case) considering the grey levels r and s as random variables with associated probability distribution functions *pr*ð Þ*r* and *ps* ð Þ*s* The continuous version uses the cumulative distribution function and we define

$$s = T(r) = (L - 1) \int\_0^r p\_r(w) dw \tag{7}$$

If p*<sup>k</sup>* (r) > 0 on 0, ½ � *L* � 1 , then *T* is strictly increasing from 0, ½ � *L* � 1 *to* ½ � 0, *L* � 1 , thus *T* is invertible. Moreover, if T is differentiable, then we can use a formula from probabilities: if *s* ¼ *T r*ð Þ, the

$$p\_s(\mathbf{s}) = p\_r(r) \frac{\partial r}{\partial \mathbf{s}} \tag{8}$$

where we view s = s(r) = T(r) as a function of r, and r = r(s) = T–1 (s) as a function of s. From the definition of s, we have by differentiating equation (7)

$$\frac{\partial \mathbf{s}}{\partial r} = (L - \mathbf{1}) p\_r(r) = T'(r) \tag{9}$$

$$\begin{split} \frac{dr}{ds} &= \frac{\partial}{\partial s} \left( T^{-1}(s) \right) = \frac{1}{T'(s)} = \frac{1}{(L-1)p\_r(r(s))}\\ p\_r(s) &= p\_r(r) \frac{\partial r}{\partial s} = p\_r(r) \frac{1}{(L-1)p\_r(r(s))} = \frac{1}{(L-1)} \end{split} \tag{10}$$

So, the uniform probability distribution function *ps* in the interval 0, ½ � *L* � 1 , corresponding to a flat histogram in the discrete case.

#### **2.5 Image enhancement**

Considering an image function *f* with second order partial derivatives, Laplacian of *f* in continuous form is defined as,

$$
\Delta f = \frac{\partial^2 f}{\partial \mathbf{x}^2} + \frac{\partial^2 f}{\partial \mathbf{y}^2} \tag{11}
$$

*Δf* ! *f* is linear and rotationally invariant.

Implementing numerical analysis finite difference approximation, the second derivatives can be approximated as,

$$\frac{\partial^2 f}{\partial \mathbf{x}^2}(\mathbf{x}, y) \approx \frac{f(\mathbf{x} + h, y) - \mathfrak{F}(\mathbf{x}, y) + f(\mathbf{x} - h, y)}{h^2} \tag{12}$$

and

$$\frac{\partial^2 f}{\partial y^2}(\mathbf{x}, y) \approx \frac{f(\mathbf{x}, y + k) - 2f(\mathbf{x}, y) + f(\mathbf{x}, y - k)}{k^2} \tag{13}$$

Here second derivative of *f x*ð Þ , *y* is approximated using the function values of *f* at *x*, *x* þ *h*, *x* � *h* keeping *y* constant for second derivative with x. Similar approach is used for second derivative of *f* with y.

Considering h=k=1 for any image a Laplacian 5-point formula given by

$$\Delta f(\mathbf{x}, \mathbf{y}) \approx f(\mathbf{x} + \mathbf{1}, \mathbf{y}) + f(\mathbf{x} - \mathbf{1}, \mathbf{y}) + f(\mathbf{x}, \mathbf{y} + \mathbf{1}) + f(\mathbf{x}, \mathbf{y} - \mathbf{1}) - 4f(\mathbf{x}, \mathbf{y}) \tag{14}$$

which can be applied to discrete images.

The Laplacian mask defined for a spatial filter is

*Mathematical Basics as a Prerequisite to Artificial Intelligence in Forensic Analysis DOI: http://dx.doi.org/10.5772/intechopen.108416*

$$m = \begin{bmatrix} \mathbf{0} & \mathbf{1} & \mathbf{0} \\ \mathbf{1} & -\mathbf{4} & \mathbf{1} \\ \mathbf{0} & \mathbf{1} & \mathbf{0} \end{bmatrix} \tag{15}$$

Laplacian operator can be discretized with 9-point Laplacian formula as,

$$\begin{aligned} \Delta f(\mathbf{x}, \mathbf{y}) &\approx f(\mathbf{x} + \mathbf{1}, \mathbf{y}) + f(\mathbf{x} - \mathbf{1}, \mathbf{y}) + f(\mathbf{x}, \mathbf{y} + \mathbf{1}) + f(\mathbf{x}, \mathbf{y} - \mathbf{1}) \\ &+ f(\mathbf{x} + \mathbf{1}, \mathbf{y} + \mathbf{1}) + f(\mathbf{x} - \mathbf{1}, \mathbf{y} + \mathbf{1}) + f(\mathbf{x} - \mathbf{1}, \mathbf{y} - \mathbf{1}) + f(\mathbf{x} + \mathbf{1}, \mathbf{y} - \mathbf{1}) - 8f(\mathbf{x}, \mathbf{y}) \end{aligned} \tag{16}$$

$$
\begin{bmatrix} \text{with Laplacian mask } m \\ \end{bmatrix} = \begin{bmatrix} 1 & 1 & 1 \\ 1 & -8 & 1 \\ 1 & 1 & 1 \\ \end{bmatrix}
$$

The sum of coefficients is 0 for both the Laplacian masks m, which is related with the sharpening property of the filter. The Laplacian can be used to enhance images. For example, in 1D a smooth-edged image can be enhanced to a sharp-edged profile by applying the operator *e* ¼ *f* � *f* " *:* In 2D for a blurry image an operator *e x*ð Þ¼ , *y f x*ð Þ� , *y* Δ*f x*ð Þ , *y* . In discrete case if 5-point Laplacian is used, we obtain the linear spatial filter and mask as,

$$e(\mathbf{x}, \boldsymbol{y}) = f(\mathbf{x}, \boldsymbol{y}) - \Delta f(\mathbf{x}, \boldsymbol{y}) = \mathbf{\tilde{y}}f(\mathbf{x}, \boldsymbol{y}) - f(\mathbf{x} + \mathbf{1}, \boldsymbol{y}) - f(\mathbf{x} - \mathbf{1}, \boldsymbol{y}) - f(\mathbf{x}, \boldsymbol{y} + \mathbf{1}) - f(\mathbf{x}, \boldsymbol{y} - \mathbf{1}) \tag{17}$$

and

$$
\boldsymbol{m} = \begin{bmatrix} \mathbf{0} & -\mathbf{1} & \mathbf{0} \\ -\mathbf{1} & \mathbf{5} & -\mathbf{1} \\ \mathbf{0} & -\mathbf{1} & \mathbf{0} \end{bmatrix}
$$

Similarly, the 9-point Laplacian mask

$$m = \begin{bmatrix} -1 & -1 & -1 \\ -1 & 9 & -1 \\ -1 & -1 & -1 \end{bmatrix} \tag{18}$$

#### **2.6 Image denoising**

Human vision can classify and categorize the image into different levels but for a digital camera denoising is difficult. Enhance observations, interpolating missing image data are to be performed rigorously to improve image quality. There are many reasons for image contamination such as heat generated by camera or external sources which might emit free electrons from the image sensor itself, thus contaminating the true photoelectrons.

Mathematically, one can write the observed image captured by devices as [6]:

$$
\nu(i) = \mu(i) + n(i), \tag{19}
$$

where *v i*ð Þ is the observed value, *u i*ð Þ is the true value, which needs to be recovered from *v i*ð Þ. *n i*ð Þ is the noise perturbation.

For a grey value image, the range of the pixel value is (0, 255), where 0 represents black and 255 represents white. To measure the amount of noise of an image, one may use the signal noise ratio (SNR),

$$\text{SNR} = \frac{\sigma(u)}{\sigma(n)},\tag{20}$$

where σ(u) denotes the empirical standard deviation of u(i),

$$\sigma(u) = \sqrt{\frac{\sum\_{i} (u(i) - \overline{u})^2}{N}} \tag{21}$$

$$
\sigma(n) = \sqrt{\frac{\sum\_{i} (u(i) - v(i))^2}{N}} \tag{22}
$$

where *u* ¼ P*u i*ð Þ *<sup>N</sup>* the average grey level values computed from a clean image.

SNRs are usually expressed in terms of the logarithmic decibel scale as signals have a wide dynamic range. In decibels, the SNR is, by definition, 10 times the logarithm of the power ratio:

$$\text{SNR} = 10 \log\_{10} \left( \frac{\sum\_{i} (u(i) - \overline{u})^2}{\sum\_{i} (u(i) - v(i))^2} \right) \tag{23}$$

A denoising method can be defined as *Dh* working on an image u:

$$u = D\_h u + n(D\_h, u) \tag{24}$$

where *h* is the filtering parameter, *Dh* is the denoised image, and *n D*ð Þ *<sup>h</sup>*, *u* is the noise guessed by the method.

It is not sufficient to just smooth*u* and get the denoised image. The more recent methods are not only working on smoothing, but also try to recover lost information in *n D*ð Þ *<sup>h</sup>*, *u* as needed as discussed by [7, 8], i.e. in an image captured by digital SLR cameras, we often need to keep the sharpness and the detailed information while the noise is being blurred. In the literature, work has been done on local filtering methods which include Gaussian smoothing model [9], Bilateral filters (Elad), PDE based methods, including anisotropic filtering model [10, 11] and total variation model (F. Guichard). Approaches using frequency domain filtering [12], Steering kernel regression [13] and so on.

#### **2.7 Order statistics filters**

Order filters are used in image processing. Non-linear spatial filters are classified as Order statistic filters, whose response is based on the ordering of the pixels contained in the image area encompassed by the filter, and then replacing the value in the centre pixel with the value determined by the ranking result.

It is an estimator of mean which uses a linear combination of order statistics. Now the question is how is it different from the mean filter? It is known that the mean filter *Mathematical Basics as a Prerequisite to Artificial Intelligence in Forensic Analysis DOI: http://dx.doi.org/10.5772/intechopen.108416*

is a simple sliding-window of spatial filter that replaces the centre value in the window with the average of all the pixel values in the window but for order statistic filter we consider N observations arranged in ascending order,

$$X\_1 < X\_2 < \dots < X\_N \tag{25}$$

f g *Xi* are the order statistics of the N observations [14]. An orders statistics filter is an estimator of *F X*ð Þ 1, *X*2, … , *XN* of the mean of X as

$$F(X\_1, X\_2, \dots, X\_N) = a\_1 X\_1 + a\_2 X\_2 + \dots + a\_N X\_N \tag{26}$$

The linear average which has coefficients *ai* <sup>¼</sup> <sup>1</sup> *<sup>N</sup>* and the median filter which has coefficients

$$a\_i = \begin{cases} 1 & i = \frac{N+1}{2}, \\\\ 0 & \text{otherwise} \end{cases} \tag{27}$$

The trimmed mean filter has coefficients,

$$a\_i = \begin{cases} \frac{1}{M} & \frac{N-M+1}{2} \le i < \frac{N+M+1}{2}, \\ 0 & \text{otherwise} \end{cases} \tag{28}$$

For any distribution one can determine the optimal coefficient by minimizing the criteria function

*J a*ð Þ¼ *E aTX* � *<sup>μ</sup>* � �<sup>2</sup> h i with *<sup>a</sup>* being the vector of order statistics filter coefficient, *<sup>X</sup>* P

is the vector of order statistics and is the mean of *X*, here, *E X*½ �¼ *i Xi <sup>N</sup>* . The order statistic filters which turns out to be important for Grid Filters is that they are piecewise linear. Order statistic filter is generally applied to 3x3, 5x5 or 7x7 windows.

#### **2.8 Convolution in image processing**

Filter effect for images is due to convolution. A matrix operation is applied to an image in which a mathematical operation comprised of integers is performed. The idea is to determine the value of a central pixel by adding the weighted values of all its neighbours together. The outcome is a new modified filtered image. Convolution is performed to obtain a smooth/enhance/intensity/sharpen an image.

A convolution is done by multiplying a pixel to its neighbouring pixels colour value by a matrix called kernel. Kernel is a small matrix of numbers that is used in image convolutions. Differently sized kernels containing different patterns of numbers produce different results under convolution. The size of a kernel is arbitrary but 3x3 is often used [15].

Formula for convolution is given by,

$$\mathcal{W} = \frac{\sum\_{i=1}^{q} \sum\_{j=1}^{q} f\_{ij} d\_{ij}}{F} \tag{29}$$

*W* is the output pixel value.

*fij* the coefficient of the convolution kernel at position *i*,*j* in the kernel matrix

*dij*data value of the pixel that corresponds to *fij*

*F* sum of the coefficients of kernel matrix

*q* dimension of the kernel.

Now in next section a connection between mathematics behind the image processing and forensic based image processing is handled.
