This post implements core image restoration algorithms in Go and Rust, comparing the two languages’ approaches to image processing through practical code.
原始图像 退化图像 — — Go Implementation Go’s standard image library provides image encoding/decoding and pixel access. The following implementation demonstrates how to implement bicubic interpolation, Gaussian blur, and Laplacian sharpening in Go.
2014 SRCNN 三层卷积 · 3-layer CNN pioneered DL SR 2016 SRGAN 感知损失 + GAN visual quality leap 2018 ESRGAN RRDB + RaGAN richer features, no BN 2021 Real-ESRGAN 真实退化建模 · Real-world works on real photos 2021 SwinIR Transformer 注意力 global context modeling 2022 Diffusion 迭代去噪 · Iterative best quality, slowest From SRGAN to ESRGAN (2018) SRGAN (Super-Resolution GAN) introduced Generative Adversarial Networks (GANs) to super-resolution in 2016, achieving significant visual quality improvements over traditional PSNR-optimization methods through perceptual loss. However, SRGAN still had room for improvement. ESRGAN (Enhanced Super-Resolution GAN) by Wang et al. in 2018 optimized four key directions.
From Mathematical Models to Data-Driven Learning In super-resolution tasks, traditional methods rely on carefully designed mathematical models—interpolation algorithms, sparse representation, prior constraints, and so on. But deep learning brought a paradigm shift: directly learning the mapping from degraded space to clear space from massive paired low-resolution (LR) and high-resolution (HR) image data.
The core idea is simple: train a neural network $F_{\theta}$ that can map low-resolution images to high-resolution images:
The previous post introduced frequency domain image processing methods — transforming images to the frequency domain via Fourier transform, then performing filtering, restoration, and other operations. However, frequency domain methods are sometimes less intuitive, especially when we’re more accustomed to directly manipulating pixels.
Spatial domain methods process images directly in pixel space, without requiring transformations. This chapter introduces spatial domain image restoration, edge-preserving filtering, and sharpening techniques.
Lucy-Richardson Iterative Deconvolution The goal of deconvolution is to recover the original image from a degraded image. The degradation process is typically modeled as convolution: degraded image = original image convolved with blur kernel + noise.
Why Work in the Frequency Domain In the previous post we built the image degradation model: the observed image $g(x,y)$ is the original image $f(x,y)$ convolved with a degradation function $h(x,y)$ and corrupted by additive noise $n(x,y)$:
$$g(x,y) = h(x,y) * f(x,y) + n(x,y)$$Restoration means: given $g$ and $h$, recover $f$ as closely as possible.
In the spatial domain, this requires solving a deconvolution problem. Deconvolution is a massive linear system. For a $512 \times 512$ image, you face 260,000 unknowns. Direct solving is practically impossible.
Why Interpolation Matters Imagine you have a low-resolution photo and want to print it larger. Between every two pixels in the original image is now a “blank space” — where do the new pixels come from?
Interpolation is the solution: using known pixel values to estimate values at unknown positions. Image upscaling is essentially an interpolation problem.
$$ \text{Upscaled Image} = \text{Interpolation Algorithm}(\text{Original Pixels}) $$The quality of interpolation directly affects the upscaled image. Too simple methods produce mosaic artifacts, while too complex methods may introduce ringing artifacts. Let’s progress step by step, from the simplest nearest neighbor interpolation to the most commonly used bicubic interpolation.
Why Do Photos Get Blurry? Scrolling through your phone gallery, you will always encounter such regrets: at the moment you pressed the shutter, you captured a beautiful moment, but the photo turned out blurry — maybe due to shaky hands, insufficient light, or the subject moving too fast. Old photos are even worse — the passage of time makes memories from back then become fuzzy.
Blur is not accidental. In the world of digital imaging, every photo undergoes a complex transformation process from the real scene to digital signals. Light passes through the lens, falls on the sensor, gets recorded by electronic systems — every link may introduce “degradation.” Understanding how these degradations occur is the first step to studying image restoration from a mathematical perspective.
In engineering practice, the most time-consuming and experience-dependent part of an active noise control system is not algorithm selection, but parameter tuning and stability debugging. Filter order, step size, sampling rate — each parameter interacts with the others in ways that are not always obvious. This article draws from hands-on experience to cover the key parameter selection logic and common troubleshooting approaches in ANC tuning.
Filter Order Selection The FIR filter order $N$ directly determines two core metrics: frequency resolution and computational complexity. Getting this choice wrong reveals itself early in debugging — poor noise reduction, slow convergence, or outright divergence.
The ESP32-S3’s dual-core Xtensa LX7 processor with vector instruction set extensions is well-suited for the real-time DSP workloads required by embedded ANC. Combined with the ESP-DSP library, efficient adaptive filtering becomes practical on this platform.
I2S Microphone Capture ANC requires at least two synchronous input channels: a reference microphone (capturing ambient noise) and an error microphone (capturing residual error). The ESP32-S3 I2S peripheral supports simultaneous multi-channel ADC data reception. Configuring it for 16-bit, 16 kHz sampling suffices for consumer-grade ANC.
Hardware Architecture Implementing real-time ANC begins with selecting the right hardware platform. The controller must complete adaptive filtering within microseconds while managing multiple audio data streams.
Module Function Typical Choice Main Controller Executes adaptive algorithm STM32F4/F7, ESP32-S3, nRF5340 Reference Mic Captures ambient noise Knowles SPH0645, Infineon IM69D130 Error Mic Captures residual noise Knowles SPH0645, TDK ICS-43434 Audio DAC Outputs anti-noise signal ES9218, PCM5102 Amplifier Drives speaker Class-D The reference microphone sits outside the earcup and captures external ambient noise as the algorithm’s reference input. The error microphone sits inside the earcup near the speaker, capturing residual noise for evaluating cancellation performance and driving adaptive updates. The audio DAC converts the digital anti-noise signal to analog, which is amplified by a Class-D amplifier to drive the speaker.