Digital image processing (2) Gray transformation and spatial filtering

1. Introduction

Spatial domain method: the process of pixel operation-> direct processing of image pixels.
The spatial domain processing can be defined by this formula: \ (g (x, y) = T [f (x, y)] \)

Among them, f (x, y) is the original image, g (x, y) is the processed image, T is defined in the neighborhood of x, y (not necessarily 4/8 / m neighborhood, may be larger Range, such as an operation (also called an operator) within 3x3, 5x5 mask, et al).

The size of the minimum neighborhood is 1x1. In this case, g (x, y) depends only on the corresponding f (x, y) value. The above formula can be transformed into a grayscale (level) transformation function of the following formula / Grayscale mapping function: \ (s = T (r) \) where r and s are the grayscale of g and f in (x, y) respectively.
When the processing origin is at the image boundary, part of the neighborhood will be outside the image. At this time, either the external neighbor is ignored or the edge of the grayscale image is filled with 0. The thickness of the filled boundary depends on the size of the neighborhood.

Second, the basic grayscale transformation

Due to factors such as underexposure / non-linear imaging equipment / too narrow dynamic range of the image recording equipment, the disadvantage of insufficient contrast will be produced, making it difficult to distinguish image details. Grayscale transformation can be used to solve these problems. The essence of gradation transformation is the 1x1 image transformation (point operation) of the neighborhood.

Linear grayscale transformation

1. Add and subtract constant (equivalent to increase / decrease brightness)

\ (g (x, y) = f (x, y) \ pm C \)
Function: compress the dynamic range and reduce the contrast.

Here is an example:

Image reversal

Image reversal is a simple transformation in the linear transformation-addition and subtraction constant.

In matlab you can use b = imcomplement (a) to reverse the image.

\ (If the gray level is 256 levels (0-255), you can write g (x, y) = 255-f (x, y) \)
\ (More generally, you can write s = L-1-r or g (x, y) = L-1-f (x, y), where L-1 is the maximum gray level \)
transformation function is as follows:

The effect is as follows:

2. Multiplication constant

\ (g (x, y) = C \ times f (x, y) \)
Role: change the dynamic range

Some examples:

The general expression of linear grayscale transformation:

Piecewise linear function

The gray range of interest can be linearly expanded to relatively suppress gray areas that are not of interest.

  • Contrast Stretching
    Contrast stretching is the simplest piecewise linear function. The idea of ​​contrast stretching is to improve the dynamic range of image processing in gray scale. (Low contrast-> high contrast)

An extreme example is a binary transformation, which outputs 1 if it exceeds the threshold, otherwise 0.

  • Grayscale cutting / Grayscale window transformation
    def: A method to increase the brightness of a specific grayscale range in an image.

Method 1: Set the grayscale in the range of interest to a higher value, and set the other grayscale values ​​to a lower value.
Method 2: Make the gray scale variable of the required range, while maintaining the gray tone of other areas.

  • Bitmap cutting
    def: Increase the brightness of a specific bit.

Assuming that the bit depth of each pixel is 8 (0-255), the image plane corresponding to each bit can be separated

The feeling is to use the corresponding bit as the threshold to get a new image corresponding to each threshold.

Logarithmic transformation

\ (s = c \ times \ log (1 + r) \)
where c is a constant, and if r≥0, the output range of the narrow-band low-gray input image is expanded, and this transformation can be used to expand the compressed Dark pixels in high-value images. Compressed dynamic range

To recalibrate / quantize the gray level of the new image, use:

Gamma transform / power transform

\(s=c\times r^\gamma\)

\ (\ gamma curves less than 1 and greater than 1 will produce the opposite effect \) When
less than 1, stretch the low gray value part of the original image to a wider range.If
greater than 1, stretch the high gray value part of the original image to Wider range

\ (Power transformation is also called \ gamma correction, used to correct the non-linear characteristics of the monitor display. \)

Contrast stretch transform

Contrast conversion is an image processing method that changes the contrast of image cells by changing the brightness value of the image cells, thereby improving the image quality. Because the brightness value is a response of the radiation intensity, it is also called radiation enhancement.
Principle: To expand the over-concentrated pixel distribution area (brightness value distribution range) in the image, expand the contrast of the image contrast, and enhance the level of image performance. The purpose of enhancing contrast is mainly achieved by adjusting the histogram.

The function image is similar to the following figure, where r is the brightness of the input image, s is the brightness of the output image, the slope is controlled by the parameter E, and the midpoint is controlled by the parameter m:

3. Histogram processing

The grayscale histogram of an image is one of the simplest and most useful tools.

Histogram: indicates the frequency of occurrence of each gray-scale pixel in a digital image. (The number of pixels in this gray level)
can be expressed as: \ (p (k) = n_k \) \ (n_k \) is the total number of pixels of the kth gray level in the image
or \ (p (r_k) = n_k / n \) n is the total number of pixels in the image. (Probability density representation)

The nature of grayscale histogram:

  • No space information
  • One-to-many relationship between histogram and image
  • Stackability (the histogram of the entire image can be obtained by superimposing the histogram of the sub-image)

Take the above picture as an example, there are many gray scales and pixels in the middle of the image, the dynamic range is small, and the image contrast is low.

High-gray-scale pixels account for the vast majority, and the image is brighter.

Pixels that are too low or too high in gray level account for the vast majority, and the contrast is too large, similar to a binary image.
The histogram reflects the clarity of the image. When the histogram is evenly distributed, the image is clearest. (Determine whether an image is clear-> whether as many gray levels as possible are fully utilized)

Histogram Equalization

Histogram correction: the original grayscale histogram is converted into the desired histogram through the grayscale mapping function T.
The difference between histogram equalization and histogram regularization (matching) is that an image with a more balanced grayscale is obtained and an image with a grayscale similar to the specified histogram is obtained.

\(G_{new}=T(G_{old})\)

Histogram equalization is the most commonly used histogram correction, which transforms the histogram of a given image into a uniform histogram distribution.
After homogenization, the image histogram is flat, that is, each gray level has the same frequency of appearance, or each gray level has a uniform probability distribution, resulting in a clearer image (image enhancement)

Histogram equalization gray-scale mapping function

Continuous gray level

\ (P (r): probability density function, 0 (black) ≤ r ≤ 1 (white), representing the gray level \)

Find a transformation function \ (s = T (r) \) to flatten the histogram.
In order to make the converted grayscale still maintain a single change order from black to white, and the conversion range is consistent with the original, so as to avoid the overall lightening or darkening.
Regulations:
1. \ (In 0≤r≤1 (L-1), T (r) is a monotonically increasing function, and 0≤T (r) ≤1, to ensure that the gray scale is not inverted before and after. \)
2. \ (Inverse transform r = T ^ {-1} (s), T ^ {-1} is a monotonically increasing function (not sure how to get it), 0≤s≤1 (L-1). Guarantee the gray after transformation The value is still within the range of gray levels allowed before conversion. \)

It can be seen that the slope of the transformation function is also small when r is small, and the larger section can be converted to a grayscale with a smaller grayscale range, while the middle section has a large slope, and the small section can also be converted to a value within a larger grayscale range ( Distribution) (non-linear transformation, matching the situation in the figure)

For the transformation function:

The right side is the cumulative distribution function of r, which is substituted into

available

That is, the probability density distribution of s is uniformly distributed (if the upper limit of s is 1, the density is 1)

Histogram equalization of digital images (discrete)

Let the total number of pixels of a digital image be n, divided into L gray levels.
Probability of the kth gray level:
\ (p_r (r_k) = n_k / n, where n_k is the frequency of the kth gray level, and r_k is the value of the kth gray level of the original image. 0 ~ 1.n is the total number of pixels. K = 0,1, ..., L-1.L is the number of possible gray levels. \)
The discrete form of the corresponding transformation is:
here L-1 is because of the upper limit It is L-1, which can be written as 1 after normalization.

According to the probability density function multiplied by L-1 (maximum gray level), the gray value obtained by rounding down is classified.

nature:

  • Unlike the continuous form, it is generally impossible to prove that the discrete transformation can produce discrete values ​​of uniform probability density functions. (In fact, most of the time it ca n’t)
  • Histogram equalization is fully automated.
  • The gray level of the result image is consistent with the original image.

Histogram matching

Some applications that use histogram equalization for basic enhancement are not suitable, as follows:

By specifying the gray distribution of the output histogram, relatively satisfactory results can be obtained.

\ (Let the mapping from r-> z, calculate the s_j = T (r) corresponding to each r_j; calculate the v_j = G (z) corresponding to each z_j; find the closest v_k for each s_j, the v_k corresponding z_k is gray r_j should be mapped to the gray value. the resulting histogram and histogram provisions similar (well understood, discrete case is certainly approximately). \)
Cou Cou on ah

Local processing

1. Apply histogram for local enhancement
Local histogram equalization: find histogram equalization for all pixels in the mask

Histogram statistics

\ (Let r represent the discrete random variable representing discrete gray scale on [0, L-1], let p (r_i) represent the normalized histogram component corresponding to the i-th value of r, and p (r_i) Seen as the estimated value of the probability of gray level r_i. \) The average value of r is \ (m = \ sum_ {i = 0} ^ {L-1} r_ip (r_i) \)
the variance of r (second moment, The measurement of contrast) is:
\ (\ mu_2 (r) = \ sum_ {i = 0} ^ {L-1} (r_i-m) ^ 2p (r_i) = \ sigma ^ 2 (r) \)
local mean ( Average gray value) / Variance (a measure of neighborhood contrast):
\ (m_ {s_ {xy}} = \ sum_ {i = 0} ^ {L-1} r_ip_ {s_ {xy}} (r_i) \ )
\ (\ sigma ^ 2_ {s_ {xy}} = \ sum_ {i = 0} ^ {L-1} (r_i-m_ {s_ {xy}}) ^ 2p_ {s_ {xy}} (r_i) \ )

Four, spatial filtering

Fundamental

Move the mask point by point to the image to be processed. Simply put, the actual pixel value is multiplied by the template value in the neighborhood of the mask and then summed.
Linear filtering is similar to convolution, so the mask is also called a convolution template / convolution kernel.

For n * n mask, when the center of the mask and the edge of the image are less than or equal to (n-1) / 2 pixels, there will be values ​​outside the image. The processing method is as follows:

1. Do not operate on (n-1) / 2 pixels on the edge, the result will be a smaller image than the original image, you can copy the edge pixels of the unprocessed image to the resulting image, and then use partial filtering masks on the edge pixel bands模 处理。 Modular processing.
2. The (n-1) / 2 rows and columns of the boundary are supplemented with pixels whose gray level is 0. (Black border) Or copy the border to fill the image.

Smoothing filter

The smoothing filter is used to blur / reduce noise. Often used for pretreatment.

Smooth linear filter

The response of the smoothed linear filter is the weighted average of pixels in the neighborhood of the mask. Therefore, it is also called an average filter.
Because the edge of the image is caused by the sharp change of the grayscale of the image, the mean filtering process will bring about the edge blur.

Statistical sorting filter

The statistical filter is a non-linear spatial filter, the response is based on the speed of pixels in the image area surrounded by the filter, and then the value determined by the statistical ranking results replaces the central pixel value. A common example is the median filter
. The median filter replaces the value of the pixel with the median (median) of the grayscale in the neighborhood of the pixel.
The blur degree is significantly lower than that of a linear smoothing filter of small size.

Sharpen filter

The purpose of the sharpening process is to highlight the details of the image or enhance the details that are blurred.
Sharpening can be done through spatial differentiation. The response strength of the differential operator is related to the abrupt change of the image at this point, which enhances the edges and other abrupt changes (noise) and weakens the areas where the gray scale changes slowly.
Define the second-order differential with difference:

among them

1. Differentiation is 0 in the flat area
2. Differential is non-zero at the starting point of
the slope 3. The differential value along the slope surface is 0

First define a discrete formula of second-order differential, and then construct a filter based on this formula. An isotropic filter is required. The response of this filter is independent of the abrupt direction of the image of the filter. (Detect all directions?)

Image enhancement based on second-order differentiation——Laplace operator

Continuous definition:

The second-order partial differential in the x direction is as follows:

The same is true for y.

Add the two to get the second-order Laplace operator:

Four forms of second-order Laplacian:

Left one: Directly derived template (isotropy rotated at 90 °)
Right one: Diagonal direction added
Left two and right two: Deformation of the top two.

Image enhancement based on first-order differential-gradient method

Definition of gradient:

The modulus of the gradient is given by:

The gradient vector itself is a linear operator, but its modulus uses square and square root operations. Generally, the modulus of the gradient is called a gradient operator.
The absolute value is often used instead of the square / square approximation to find the modulus of the gradient.

Think of the template center as f (x, y) to differentiate x and y.

Robert operator

Propose a new definition to calculate differential:

The corresponding algorithm and mask form are:

Even-sized masks are not easy to use. In order to obtain a 3x3 minimum filter mask, the approximation to the above formula is:

The mask form is:

Hybrid space enhancement

Using multiple complementary image enhancement techniques, an example:

Guess you like

Origin www.cnblogs.com/Valeyw/p/12568347.html