标签:code font copy microsoft 平均值 rac ros 填充 区域
图源自skimage
1 import numpy as np 2 3 4 def means_filter(input_image, filter_size): 5 ‘‘‘ 6 均值滤波器 7 :param input_image: 输入图像 8 :param filter_size: 滤波器大小 9 :return: 输出图像 10 11 注:此实现滤波器大小必须为奇数且 >= 3 12 ‘‘‘ 13 input_image_cp = np.copy(input_image) # 输入图像的副本 14 15 filter_template = np.ones((filter_size, filter_size)) # 空间滤波器模板 16 17 pad_num = int((filter_size - 1) / 2) # 输入图像需要填充的尺寸 18 19 input_image_cp = np.pad(input_image_cp, (pad_num, pad_num), mode="constant", constant_values=0) # 填充输入图像 20 21 m, n = input_image_cp.shape # 获取填充后的输入图像的大小 22 23 output_image = np.copy(input_image_cp) # 输出图像 24 25 # 空间滤波 26 for i in range(pad_num, m - pad_num): 27 for j in range(pad_num, n - pad_num): 28 output_image[i, j] = np.sum(filter_template * input_image_cp[i - pad_num:i + pad_num + 1, j - pad_num:j + pad_num + 1]) / (filter_size ** 2) 29 30 output_image = output_image[pad_num:m - pad_num, pad_num:n - pad_num] # 裁剪 31 32 return output_image
标签:code font copy microsoft 平均值 rac ros 填充 区域
原文地址:https://www.cnblogs.com/iwuqing/p/11380131.html