OpenCV image filter operation - blur

Tip: Aim high and keep your feet on the ground

Article directory

  • I. Introduction
  • 2. Main content
    1. Vague

    2. edge

    3. relief

    4. contour

    5. sharpen

  • Summarize


I. Introduction

opencv filter - use opencv to achieve various image filter effects

2. Main content

1. Fuzzy

Image blurring is also called image smoothing. It mainly processes points in the image that are quite different from the surrounding points, and adjusts their pixel values ​​to values ​​similar to those of the surrounding points. The purpose is to eliminate image noise and edges.

There are several types of filtering

<1> mean filtering

<2> Gaussian filter

<3> Box filtering

<4> Median filtering

<5>Bilateral filtering

<6>2D filtering

<1> mean filtering

Mean filtering is centered on the current point, and replaces the pixel value of the current point with the average value of the pixels of the surrounding N * N points

im=cv2.imread('lena.jpg')
cv2.imshow('input',im)
im2=cv2.blur(im,(5,5))
# im2=cv2.blur(im,(20,20))
cv2.imshow('output',im2)
cv2.waitKey(0)

<2> Gaussian filter

Gaussian filtering first assigns different weights to each pixel according to the distance between the pixel point and the center point: the closer to the center point, the greater the weight; the farther away from the center point, the smaller the weight. Then calculate the sum of all pixels in the field according to the weight, and use the sum as the center pixel value.

import cv2
im=cv2.imread('lena.jpg')
cv2.imshow('input',im)
im2=cv2.GaussianBlur(im,(5,5),0,0)
cv2.imshow('output',im2)
cv2.waitKey(0)

<3> Box filtering

Box filtering is based on mean filtering, and you can choose whether to normalize the filtering results. If True , the filter result is the average of the sum of pixel values ​​of points in the domain, otherwise the sum of pixel values.

import cv2
im=cv2.imread('lena.jpg')
cv2.imshow('input',im)
im2=cv2.boxFilter(im, -1, (5,5),
normalize=True)
# im2=cv2.blur(im,(20,20))
cv2.imshow('output',im2)
cv2.waitKey(0)

<4> Median filtering

Median filtering first sorts all pixel values ​​in the neighborhood, and takes the median value as the pixel value of the center point of the neighborhood

import cv2
im=cv2.imread('lena.jpg')
cv2.imshow('input',im)
im2=cv2.medianBlur(im, 21)
# im2=cv2.blur(im,(20,20))
cv2.imshow('output',im2)
cv2.waitKey(0)

<5>Bilateral filtering

Bilateral filtering considers distance and color difference information while calculating pixel values, thereby preserving edge information while eliminating noise.

import cv2
im=cv2.imread('lena.jpg')
cv2.imshow('input',im)
im2=cv2.bilateralFilter(im, 50, 100, 100)
# im2=cv2.blur(im,(20,20))
cv2.imshow('output',im2)
cv2.waitKey(0)

<6>2D filtering

2D convolution can use a custom convolution kernel to perform filtering operations.


Summarize

Image common blur filter operation

  1. mean filtering

  2. Gaussian filter

  3. box filtering

  4. median filter

  5. bilateral filtering

  6. 2D filtering

  • contour

  • relief

  • sharpen

Guess you like

Origin blog.csdn.net/CHENG15234944691/article/details/123678520