ISP-BNR 模块去噪方法对比

在图像信号处理(ISP)中,Bayer噪声去除(BNR)是关键的一步。本文将介绍几种常用的去噪方法,包括中值滤波、均值滤波、双边滤波、高斯滤波和非局部均值滤波,并通过示例代码进行对比分析。

1. 图像去噪方法简介

中值滤波 (Median Filtering)

中值滤波是一种非线性滤波方法,通过取窗口内所有像素值的中值来替代中心像素值。它对椒盐噪声有很好的去除效果。

均值滤波 (Mean Filtering)

均值滤波是一种线性滤波方法,通过取窗口内所有像素值的平均值来替代中心像素值。它可以平滑图像,但会使边缘变得模糊。

双边滤波 (Bilateral Filtering)

双边滤波结合了空间邻近和像素值相似度的双重加权,能够在平滑图像的同时保留边缘细节。

高斯滤波 (Gaussian Filtering)

高斯滤波使用高斯核对图像进行卷积,能够平滑图像,同时保留部分边缘信息。

非局部均值滤波 (Non-Local Means Denoising)

非局部均值滤波根据像素与其邻域的相似性来平滑图像,能够在保留更多细节的同时有效去除噪声。

2. 代码实现

import cv2
import numpy as np
import matplotlib.pyplot as plt

# 读取图像并转换为灰度图像
image_path = 'images/kodak_fence.tif'
image = cv2.imread(image_path, cv2.IMREAD_COLOR)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 添加噪声到图像
def add_noise(img):
    noise = np.random.randn(*img.shape) * 25
    noisy_img = img + noise
    noisy_img = np.clip(noisy_img, 0, 255).astype(np.uint8)
    return noisy_img

noisy_image = add_noise(gray_image)

# 中值滤波
median_filtered = cv2.medianBlur(noisy_image, 5)

# 均值滤波
mean_filtered = cv2.blur(noisy_image, (5, 5))

# 双边滤波
bilateral_filtered = cv2.bilateralFilter(noisy_image, 9, 75, 75)

# 高斯滤波
gaussian_filtered = cv2.GaussianBlur(noisy_image, (5, 5), 0)

# 非局部均值滤波
nlm_filtered = cv2.fastNlMeansDenoising(noisy_image, None, 30, 7, 21)

# 可视化结果
plt.figure(figsize=(20, 10))

plt.subplot(2, 4, 1)
plt.imshow(gray_image, cmap='gray')
plt.title('Original Image')
plt.axis('off')

plt.subplot(2, 4, 2)
plt.imshow(noisy_image, cmap='gray')
plt.title('Noisy Image')
plt.axis('off')

plt.subplot(2, 4, 3)
plt.imshow(median_filtered, cmap='gray')
plt.title('Median Filtered')
plt.axis('off')

plt.subplot(2, 4, 4)
plt.imshow(mean_filtered, cmap='gray')
plt.title('Mean Filtered')
plt.axis('off')

plt.subplot(2, 4, 5)
plt.imshow(bilateral_filtered, cmap='gray')
plt.title('Bilateral Filtered')
plt.axis('off')

plt.subplot(2, 4, 6)
plt.imshow(gaussian_filtered, cmap='gray')
plt.title('Gaussian Filtered')
plt.axis('off')

plt.subplot(2, 4, 7)
plt.imshow(nlm_filtered, cmap='gray')
plt.title('Non-Local Means Filtered')
plt.axis('off')

plt.show()

3. 去噪方法的对比分析

通过以上方法的对比,可以看出:

  • 中值滤波在去除椒盐噪声方面效果显著,但对细节保留较差。
  • 均值滤波能够平滑图像,但会使图像变得模糊。
  • 双边滤波在平滑图像的同时,能够很好地保留边缘细节。
  • 高斯滤波在平滑图像的同时也能保留一定的边缘信息。
  • 非局部均值滤波能够在保留更多细节的同时有效去除噪声,效果最好。

 

  • 13
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ARINC 429是一种数据通信协议,它用于航空电子系统中的数字信息传输。在ARINC 429中,数据可以以不同的格式进行传输,其中一种格式是BNR格式(Binary Coded Decimal with Sign and Range)。BNR格式用于传输带符号十进制数值,并且可以指定范围。 以下是一个简单的BNR编解码的示例代码: ```c #include <stdio.h> #include <stdint.h> // BNR解码 float bnr_decode(uint32_t bnr_data, uint8_t bnr_bits, float bnr_range) { int32_t sign = (bnr_data >> (bnr_bits - 1)) & 0x01; // 获取符号位 int32_t value = bnr_data & ((1 << (bnr_bits - 1)) - 1); // 获取数值部分 float result = (float)value * bnr_range / ((1 << (bnr_bits - 1)) - 1); // 将数值部分转化为浮点数 if (sign) { result = -result; // 如果符号位为1,则结果为负数 } return result; } // BNR编码 uint32_t bnr_encode(float value, uint8_t bnr_bits, float bnr_range) { uint32_t bnr_data = 0; int32_t sign = value < 0 ? 1 : 0; // 获取数值的符号位 value = value < 0 ? -value : value; // 取绝对值 int32_t max_value = (1 << (bnr_bits - 1)) - 1; float delta = bnr_range / max_value; // 计算单位间隔值 int32_t int_value = (int32_t)(value / delta + 0.5); // 将浮点数转化为整数 if (int_value > max_value) { int_value = max_value; } bnr_data = (sign << (bnr_bits - 1)) | int_value; // 组合符号位和数值部分 return bnr_data; } int main() { uint32_t bnr_data = 0x00001F80; float bnr_value = bnr_decode(bnr_data, 16, 100.0); printf("BNR解码结果:%f\n", bnr_value); float value = 55.0; uint32_t encode_data = bnr_encode(value, 16, 100.0); printf("BNR编码结果:%04X\n", encode_data); return 0; } ``` 在上面的示例代码中,`bnr_decode`函数用于将BNR格式的数据解码为浮点数,`bnr_encode`函数用于将浮点数编码为BNR格式的数据。`bnr_bits`参数表示BNR格式中数值部分的位数,`bnr_range`参数表示数值的范围。在本例中,BNR格式使用16位的数值部分,表示的范围是-100到100。 在`main`函数中,我们首先使用`bnr_decode`函数将BNR格式的数据解码为浮点数,并输出解码结果。然后我们使用`bnr_encode`函数将一个浮点数编码为BNR格式的数据,并输出编码结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值