The study and application about image processing.

电子科技大学

格拉斯哥学院

2017级 黄嘉俊

The Foreword

As a photography enthusiast, I often worry about post-processing of pictures. After attending the freshman seminars at the college, I have a great interest in image processing and have done a lot through simple learning and application. Very interesting work.

Main Part

One: what I have learned (from the Internet):

Basic concepts of linear filtering and convolution

Linear filtering can be said to be the most basic method of image processing. It allows us to process images and produce many different effects. First, we need a two-dimensional filter matrix and a two-dimensional image to be processed. Then, for each pixel of the image, the product of its neighborhood pixel and the corresponding element of the filter matrix is calculated and then added up as the value of the pixel location. This completes the filtering process.

      

The operation of multiplying the image and the filter matrix by element by element and summing is equivalent to moving a two-dimensional function to all positions of another two-dimensional function. This operation is called convolution or co-correlation. The difference between convolution and co-correlation is that the convolution needs to flip 180 the filter matrix first, but if the matrix is ​​symmetric, then there is no difference between the two.

Correlation and Convolution can be said to be the most basic operations of image processing, but they are very useful. These two operations have two very critical features: they are linear and have a translation-invariant shift-invariant. Translation invariance means that we perform the same operation at every position of the image. Linear means that this operation is linear, that is, we replace this pixel with a linear combination of the neighborhood of each pixel. These two properties make this operation very simple, because linear operations are the easiest, and then it's much easier to do the same thing everywhere.

In fact, in the field of signal processing, convolution has a wide range of meanings, and has its strict mathematical definition, but does not pay attention to this here.

2D convolution requires 4 nested loops 4-double loop, so it's not fast unless we use a small convolution kernel. Usually 3x3 or 5x5 is used here. Moreover, there are certain rules for filters:

1) The size of the filter should be odd so that it has a center, such as 3x3, 5x5 or 7x7. There is a center, and there is also a radius, for example, the radius of a 5x5 core is 2.

2) The sum of all elements of the filter matrix should be equal to 1, in order to ensure that the brightness of the image before and after filtering remains unchanged. Of course, this is not a hard requirement.

3) If the sum of all elements of the filter matrix is ​​greater than 1, the filtered image will be brighter than the original image. Conversely, if it is less than 1, the resulting image will be darker. If the sum is 0, the image will not turn black, but it will be very dark.

4) For the filtered structure, a negative number or a value greater than 255 may occur. In this case, we can cut them directly between 0 and 255. For negative numbers, absolute values ​​can also be taken.

Magical convolution kernel

As mentioned above, the filtering of the image is to apply a small convolution kernel to the image, then what magic is there in this small convolution kernel. Let's take a look at some of the simple but not simple convolution kernel magic.

1, do nothing

Haha, can you see it? This filter has not been done, and the resulting image is the same as the original image. Because only the value of the center point is 1. The weight of the neighborhood point is 0, which has no effect on the filtered value.
 

 

 

      

Below we move the real thing.

2, image sharpening filter Sharpness Filter

Image sharpening is similar to edge detection by first finding the edge and then adding the edge to the original image, which reinforces the edges of the image and makes the image look sharper. The two operations are unified to sharpen the filter, that is, based on the edge detection filter, and then add 1 to the center position, so that the filtered image will have the same brightness as the original image, but It will be sharper.
 

 

 

      When we increase the nuclear, we can get a more refined sharpening effect.

 

 

     In addition, the following filters will emphasize the edge more:

 

 

    The main emphasis is on the details of the image. The simplest 3x3 sharpening filter is as follows:  

                                      

 

      

You should also see that the sharpening filter actually calculates the difference between the current point and the surrounding points, and then adds this difference to the original position.

3, edge detection Edge Detection

We need to find the horizontal edge: It should be noted that the element sum of the matrix here is 0, so the filtered image will be very dark, only the edge is bright.
 

 

      Why is this filter looking for horizontal edges? Because using this filter convolution is equivalent to the discrete version of the derivative: you subtract the current pixel value from the previous pixel value, so you can get the difference or slope of the function at these two positions. The following filter finds the edges in the vertical direction, where the pixel values above and below the pixel are used:

 

 

     The following filter can find the edge of 45 degrees: take -2 for nothing, just to make the element of the matrix sum to 0.

 

 

      The filter below can detect edges in all directions:

 

                                      

 

    In order to detect the edges, we need to calculate the gradient in the direction corresponding to the image. Use the following convolution kernel to convolve the image, and that's it. But in practice, this simple method will also amplify the noise. In addition, it should be noted that all values of the matrix add up to 0.

 

                                       

 

4, Embossing Filter

The embossed filter gives the image a 3D shadow effect. Just subtract the pixels on the center side from the pixels on the other side. At this time, the pixel value may be negative, we treat the negative as a shadow, the positive as light, and then we add a 128 offset to the resulting image. At this time, most of the image becomes gray.

Below is a 45 degree relief filter

 

 

      As long as we increase the filter, we can get more exaggerated effects.

 

 

     This effect is very beautiful, like carving an image on a stone and then illuminating it from one direction. It is different from the previous filter and is asymmetric. In addition, it produces a negative value, so we need to offset the result to get the range of image grayscale.

 

 

                                                      

A: Original image. B: Sharpening. C: Edge detection. D: relief

5, motion blur Motion Blur

Motion blur can be achieved by blurring in only one direction, such as the 9x9 motion blur filter below. Note that the summation result is divided by 9.
 

 

      

This effect is like the camera is moving from the upper left corner to the lower right corner.

After reading some fun filters, we can enter the theme, first look at the mean blur:
 

Mean Fuzzy Box Filter (Averaging)

We can average the current pixel and its four neighborhood pixels together, then divide by 5, or take the value of 0.2 directly in the 5 places of the filter, as shown below:


     As you can see, this blur is still relatively gentle. We can make the filter bigger, which will become rude: pay attention to divide and divide by 13.
 

 

      So, if you want a more blurry effect, increase the size of the filter. Or apply multiple blurs to the image.

 

 

 

 

 

 

 

Gaussian blur

In fact, the fuzzy filter is to perform weighted averaging on the surrounding pixels. The mean blur is very simple, and the weights of the surrounding pixels are the same, so it is not very smooth. Gaussian blur has this advantage, so it is widely used in image noise reduction. Especially before edge detection, it will be used to remove details. So let's take a look at how the weights of Gaussian blurs are allocated.

Weight of normal distribution

A normal distribution is obviously a desirable weight distribution model. On the graph, the normal distribution is a bell curve. The closer to the center, the larger the value, the farther away from the center, the smaller the value. When calculating the average value, we only need to use the "center point" as the origin. Other points can be assigned a weight according to their position on the normal curve, and a weighted average can be obtained.

Gaussian function

The normal distribution above is one-dimensional, the images are two-dimensional, so we need a two-dimensional normal distribution.

The density function of a normal distribution is called a "Gaussian function". Its one-dimensional form is:

一维形式

 Where μ is the mean of x and σ is the standard deviation of x. Because the center point is the origin when calculating the average, μ is equal to zero. which is:

进一步推导

  According to the one-dimensional Gaussian function, a two-dimensional Gaussian function can be derived:

二维高斯函数

  

With this function, you can calculate the weight of each point.

Assuming the coordinates of the center point are (0,0), the coordinates of the 8 points closest to it are as follows:

权重矩阵

  Farther points and so on. Here is the 5*5 Gaussian filter and smoothing effect:

 

Two: Works display:

1: Using edge blurring

2: Use image sharpening

3: Slightly using the relief effect

The End

By utilizing the image processing, I have successfully achieved the aim to make beautiful photos. Thanks for the freshman seminars which offer me the opportunity that acknowledges me with the incredible image processing.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值