News classification
Contact us
- Add: No. 9, North Fourth Ring Road, Haidian District, Beijing. It mainly includes face recognition, living detection, ID card recognition, bank card recognition, business card recognition, license plate recognition, OCR recognition, and intelligent recognition technology.
- Tel: 13146317170 廖经理
- Fax:
- Email: 398017534@qq.com
Deep learning image convolution and filtering
Deep learning image convolution and filtering
Before learning CNN, there was some learning and sorting out of convolution, and later, it was finished. Now, a little tidy up, first put up, in order to prompt and exchange.
First, the fundamental concept of linear filtering and convolution
Linear filtering can be regarded as the most fundamental way of image processing. It can allow us to stop disposal of images, resulting in many different effects. The practice is simple. First, we have a two-dimensional filter matrix (a tall name is called convolution kernel) and a two-dimensional image to deal with. Then, with respect to each pixel point of the image, the product of its neighborhood pixels and the corresponding element of the filter matrix is calculated, and then added as the value of the pixel position. This completes the filtering process.
.
The operation of an image and filter matrix that stops each element multiplying and then summing is equivalent to moving one two-dimensional function to the other two dimensional function, which is called convolution or co correlation. The convolution and the co - correlation difference is that the convolution demand first stops the reversal of the filter matrix by 180, but if the matrix is symmetric, there is no difference between the two.
Correlation and Convolution can be regarded as the most fundamental operation of image processing, but they are very useful. These two operations have two very critical characteristics: they are linear and have translation invariance shift-invariant. Translation invariance means that we perform the same operation at every position of the image. Linear means that the operation is linear, that is, we use the linear combination of the neighborhood of each pixel to replace this pixel. These two attributes make the operation very simple, because the linear operation is the simplest, and then do the same operation in all centers.
In practice, in signal processing category, convolution is of universal significance, and has its strict mathematical definition, but it doesn't pay much attention here.
2D convolution needs 4 nested loops 4-double loop, so it is not fast unless we use very small convolution kernels. This is a common use of 3x3 or 5x5. Besides, there are certain rules about filters.
1) the size of the filter should be odd, so that it has a center, for example, 3X3, 5x5 or 7x7. There is a center, also has the radius appellation, for example, the radius of the core of 5x5 size is 2.
2) the sum of all elements of the filter matrix should be equal to 1, which is to ensure that the brightness of the image remains unchanged before and after filtering. Of course, this is not a hard request.
3) if the sum of all elements of the filter matrix is greater than 1, then the filtered image will be brighter than the original image, and conversely, if less than 1, the obtained image will be darkened. If the image is 0, the image will not be black, but it will also be very dark.
4) about the structure after filtering, it may show a negative or greater than 255 value. For this situation, we will directly cut them between 0 and 255. As for the negative number, the absolute value can also be taken.
Two. The magic convolution core
It is said that the filtering of the image is a small convolution core of the image, and what magic the small convolution core has to make an image become beautiful from the disastrous point of view. Now let's take a look at some simple but not simple convolution core magic.
2.1. Nothing to do
Ha ha, what can you see? This filter doesn't do anything. The image obtained is the same as the original one. As long as the value of the center point is 1. The weights of neighborhood points are all 0, which has no effect on the value after filtering.
Here we are moving.
2.2. Image sharpening filter Sharpness Filter
Image sharpening and edge detection are very similar. First, the edge is found, then the edge is added to the original image, which strengthens the edge of the image, making the image look sharper. The same operation is the same as the sharpening filter, that is, on the base of the edge detection filter, and then add 1 at the center position, so that the filtered image will have the same brightness as the original image, but it will be more sharp.
If we increase the core, we will get more precise sharpening effect.
In addition, the following filter will emphasize the edge more:
The emphasis is on the details of the image. The simplest 3x3 sharpening filter is as follows:
In practice, we calculate the difference between the current point and the four week point, and then add the difference to the original position. In addition, the weight of the middle point is more than 1 of all weights, which means that this pixel should stick to its original value.
2.3. Edge detection Edge Detection
We are looking for the edge of the degree: the requirement is to note that the element of the matrix here is 0, so the filtered image will be very dark, as long as the center of the edge is bright.
Why can this filter find the edge of degree? Because the convolution of this filter is equivalent to the discrete version of the derivation, you subtract the current pixel value from the previous pixel value so that you can get the difference or slope of the function in these two locations. The following filter can find the vertical direction of the edge, where the pixels on the upper and lower pixels are applied.
The next filter can find the edge of 45 degrees: -2 is not for anything, just to make the elements of the matrix and 0.
The filter below can detect all directions of edges.
In order to detect edges, we need corresponding images.
First, the fundamental concept of linear filtering and convolution
Linear filtering can be regarded as the most fundamental way of image processing. It can allow us to stop disposal of images, resulting in many different effects. The practice is simple. First, we have a two-dimensional filter matrix (a tall name is called convolution kernel) and a two-dimensional image to deal with. Then, with respect to each pixel point of the image, the product of its neighborhood pixels and the corresponding element of the filter matrix is calculated, and then added as the value of the pixel position. This completes the filtering process.
.
The operation of an image and filter matrix that stops each element multiplying and then summing is equivalent to moving one two-dimensional function to the other two dimensional function, which is called convolution or co correlation. The convolution and the co - correlation difference is that the convolution demand first stops the reversal of the filter matrix by 180, but if the matrix is symmetric, there is no difference between the two.
Correlation and Convolution can be regarded as the most fundamental operation of image processing, but they are very useful. These two operations have two very critical characteristics: they are linear and have translation invariance shift-invariant. Translation invariance means that we perform the same operation at every position of the image. Linear means that the operation is linear, that is, we use the linear combination of the neighborhood of each pixel to replace this pixel. These two attributes make the operation very simple, because the linear operation is the simplest, and then do the same operation in all centers.
In practice, in signal processing category, convolution is of universal significance, and has its strict mathematical definition, but it doesn't pay much attention here.
2D convolution needs 4 nested loops 4-double loop, so it is not fast unless we use very small convolution kernels. This is a common use of 3x3 or 5x5. Besides, there are certain rules about filters.
1) the size of the filter should be odd, so that it has a center, for example, 3X3, 5x5 or 7x7. There is a center, also has the radius appellation, for example, the radius of the core of 5x5 size is 2.
2) the sum of all elements of the filter matrix should be equal to 1, which is to ensure that the brightness of the image remains unchanged before and after filtering. Of course, this is not a hard request.
3) if the sum of all elements of the filter matrix is greater than 1, then the filtered image will be brighter than the original image, and conversely, if less than 1, the obtained image will be darkened. If the image is 0, the image will not be black, but it will also be very dark.
4) about the structure after filtering, it may show a negative or greater than 255 value. For this situation, we will directly cut them between 0 and 255. As for the negative number, the absolute value can also be taken.
Two. The magic convolution core
It is said that the filtering of the image is a small convolution core of the image, and what magic the small convolution core has to make an image become beautiful from the disastrous point of view. Now let's take a look at some simple but not simple convolution core magic.
2.1. Nothing to do
Ha ha, what can you see? This filter doesn't do anything. The image obtained is the same as the original one. As long as the value of the center point is 1. The weights of neighborhood points are all 0, which has no effect on the value after filtering.
Here we are moving.
2.2. Image sharpening filter Sharpness Filter
Image sharpening and edge detection are very similar. First, the edge is found, then the edge is added to the original image, which strengthens the edge of the image, making the image look sharper. The same operation is the same as the sharpening filter, that is, on the base of the edge detection filter, and then add 1 at the center position, so that the filtered image will have the same brightness as the original image, but it will be more sharp.
If we increase the core, we will get more precise sharpening effect.
In addition, the following filter will emphasize the edge more:
The emphasis is on the details of the image. The simplest 3x3 sharpening filter is as follows:
In practice, we calculate the difference between the current point and the four week point, and then add the difference to the original position. In addition, the weight of the middle point is more than 1 of all weights, which means that this pixel should stick to its original value.
2.3. Edge detection Edge Detection
We are looking for the edge of the degree: the requirement is to note that the element of the matrix here is 0, so the filtered image will be very dark, as long as the center of the edge is bright.
Why can this filter find the edge of degree? Because the convolution of this filter is equivalent to the discrete version of the derivation, you subtract the current pixel value from the previous pixel value so that you can get the difference or slope of the function in these two locations. The following filter can find the vertical direction of the edge, where the pixels on the upper and lower pixels are applied.
The next filter can find the edge of 45 degrees: -2 is not for anything, just to make the elements of the matrix and 0.
The filter below can detect all directions of edges.
In order to detect edges, we need corresponding images.