Welcome to K230 Vision Module repository
23.Gaussian Blur
Gaussian Blur
Gaussian BlurExample ResultsPrinciple ExplanationWhat is Image Gaussian Filtering?Code OverviewImporting ModulesSetting the Image SizeInitialize the camera (RGB888 format)Initialize the display moduleInitialize the media manager and start the cameraSet Gaussian filter parametersImage processing and Gaussian filteringResource ReleaseParameter Adjustment Instructions
Example Results
Run this section's example code [Source Code/06.cv_lite/17.rgb888_gaussian_blur.py]
In this section, we will use the cv_lite extension module to implement Gaussian filtering of RGB888 images on an embedded device.

Principle Explanation
What is Image Gaussian Filtering?
Gaussian Blur is a commonly used image smoothing technique used to reduce noise and blur details. It uses a filter kernel designed based on a Gaussian distribution (normal distribution) and achieves smoothing by performing a convolution operation on the image. Gaussian filtering is widely used in image processing, particularly in the preprocessing stage.
- How it works: Gaussian filtering uses a convolution kernel (or weight matrix) based on a Gaussian distribution to perform a weighted average of each pixel in an image and its surrounding pixels. The center of the kernel has the highest weight, and the weight gradually decreases with increasing distance from the center (in accordance with a normal distribution). This weighted average results in smoother pixel value variations, blurring details, and suppressing noise.
- Effect: Gaussian filtering effectively removes high-frequency noise (such as random noise) from an image while preserving low-frequency information (such as overall structure and large edges). Compared to mean filtering, Gaussian filtering is more natural because it is closer to human visual perception and does not introduce noticeable blocky artifacts.
- Applications: Gaussian filtering is commonly used for image denoising, preprocessing before edge detection (to reduce noise interference on edge detection), image downsampling (to prevent aliasing), and special effects (such as background blur).
In Gaussian filtering, the size of the convolution kernel (which must be an odd number) significantly affects the result: larger kernels result in stronger blurring, but also increase the computational effort. In addition, the parameters of the Gaussian filter may also include the standard deviation (sigma), which is used to control the weight distribution of the kernel (not explicitly specified in this code, it may be a fixed value or handled internally by the library).
Code Overview
Importing Modules
import time, os, sys, gcfrom machine import Pinfrom media.sensor import * # Camera interfacefrom media.display import * # Display interfacefrom media.media import * # Media managerimport _threadimport cv_lite # cv_lite extension (includes the gaussian_blur API)import ulab.numpy as np # NumPy-like ndarray for MicroPythonSetting the Image Size
xxxxxxxxxximage_shape = [480, 640] # Height x WidthDefine the image resolution to 480x640 (height x width). The camera and display modules will be initialized based on this size.
Initialize the camera (RGB888 format)
xxxxxxxxxxsensor = Sensor(id=2, width=1280, height=960, fps=30)sensor.reset()sensor.set_framesize(width=image_shape[1], height=image_shape[0])sensor.set_pixformat(Sensor.RGB888) # Set pixel format to RGB888- Initialize the camera, set the resolution to 1280x960 and the frame rate to 30 FPS.
- Resize the output frame to 640x480 and set it to RGB888 format (three-channel color image, suitable for Gaussian filtering of color images).
Initialize the display module
xxxxxxxxxxDisplay.init(Display.ST7701, width=image_shape[1], height=image_shape[0], to_ide=True, quality=100)Initialize the display module, using the ST7701 driver chip, with a resolution consistent with the image size. to_ide=True indicates that the image will be simultaneously transmitted to the IDE for virtual display, and quality=100 sets the image transmission quality to the highest.
Initialize the media manager and start the camera