Edge retention filtering
Gaussian blur only considering the weight, only consider the distribution of the pixel space, without considering the pixel values and another difference between pixel values, if differences between pixels (such as the edge of the image), under the condition of gaussian blur will be processed, but we don't need to deal with the edge to edge, the operation is known as reservation filter (EPF)Copy the code
Two kinds of operations
Gaussian bilateral
The greater the difference, the more complete it will remain If gaussian blur, then the whole blur off, to achieve the filter effect.Use gaussian blur to turn on the filter and double blur to add beauty.
def bilateralFilter(src, d, sigmaColor, sigmaSpace, dst=None,borderType=None): # real signature unknown; Restored from __doc__ # the two sigma variances can be easily set to equal, < 10, not much effect, more than 150, too much effect, like a animation. Filter size D: greater than 5 will be slow (5 forreal-time), d=9, for off-lineapplications, d is pixel neighborhood "diameter". The calculated radius and the number of images within the radius are included in the calculation. If -1 is provided, it is automatically calculated from the following parameter sigmaSpace. Sigma_color Specifies the sigma value of the color space filter. The greater the value of this parameter, the wider the range of colors in the pixel's neighborhood will be mixed together, resulting in a larger semi-equal color region. The sigma value of the filter in the Sigma_space coordinate space. If this value is large, it means that distant pixels with similar colors will influence each other so that similar colors are sufficient in a larger area to obtain the same color. When d>0, d specifies the neighborhood size and is proportional to sigmaSpace, otherwise d is proportional to sigmaSpace.Copy the code
The function is:
The inherent idea of bilateral filtering is to do on the range of the image what the traditional filter does on the domain. Spatial filtering is used to add the weighted average of adjacent points in space, and the weighted coefficient decreases with the increase of distance. Range filtering is the weighted average of points with similar pixel value #, and the weighted coefficient decreases with the increase of value difference.def bi_demo(image):# double blur DST= cv.bilateralFilter(image,0.100.15)
cv.imshow("bi_demo",src)
Copy the code
(My Taylor Swift and my face look ugly)(This is pretty good, but think of what happens when you use Gaussian blur, everything gets blurry.)
Average migration
def pyrMeanShiftFiltering(src, sp, sr, dst=None, maxLevel=None, termcrit=None): # real signature unknown; Restored from __doc__ first parameter SRC, input image, 8-bit, three-channel color image, does not require RGB format, HSV, YUV and other Opencv color image format can be; The second parameter, sp, defines the radius of the drift physical space; The third parameter, SR, defines the size of drift color space radius; The fourth parameter, DST, outputs the image, which has the same size and data format as the input SRC. The fifth parameter, maxLevel, defines the maximum number of layers of the pyramid; The sixth parameter, TERmcrit, defines the termination condition of drift iteration, which can be set as the number of iterations satisfying termination, the iteration target and center point deviation satisfying termination, or a combination of the two.Copy the code
The function is:
def shift_demo(image):# mean migration DST= cv.pyrMeanShiftFiltering(image,10.50)
cv.imshow("shift_demo",dst)
Copy the code
(Kind of like a painting, isn’t it?)