python - 如何在给定坐标参考的情况下插入未知像素?
问题描述
我只是将 Python 用于计算机视觉。我需要大量关于使用 Python 在图像中进行像素插值的参考资料。
我有一个如下所示的 RGB 图像。在那张照片中,我有一个白色的未知像素。(x0, y0)
我想使用沿蓝线的颜色强度信息从该点开始插入未知像素。(x0, y0)
有人可以提供代码示例以使用任何插值技术进行点插值吗?输入是坐标颜色参考x,y = np.where(np.all(img == [0,0,255],axis=2))
和像素坐标的集合(x0, y0)
。输出是(x0, y0)
已插值的像素。
解决方案
我将使用一堆函数来解决这个问题。
首先对于给定的坐标(x_i, y_i)
,我在一个特定的大小窗口中获得它两侧的像素坐标列表 =window_size
IE
def derive_adjacent_coords(coord, window_size):
# Coord is a tuple (row, column)
assert (window_size % 2) != 0, "Window size must be odd"
mid_idx = (window_size - 1) / 2)
return [(r, coord[1]) for r in range(coord[0] - mid_idx, coord[0] + mid_idx + 1)]
然后我将使用以下函数提取与图像中这些位置相对应的值:
def derive_adjacent_pixels(list_of_coord_tuples, image):
# Image is your image, list_of_coord_tuples is the output of the first function
return [ image[*i] for i in list_of_coord_tuples]
上面的函数将返回一个列表。然后我将插入列表:
from scipy.interpolate import interp1d
import math
def interpol(list):
# list is the output of the derive_adjacent_pixels(list_of_coord_tuples, image) function
x = [i for i in range len(list)]
interpolated_list = interp1d(x, list, kind='cubic')
return interpolated_list[int(math.floor(len(interpolated_list)/2))]
你必须用我上面展示的这种方法对图像的每个波段进行不同的插值。
您必须在未知像素坐标列表(元组列表)上迭代这些函数,然后为图像中的每个波段单独迭代。
推荐阅读
- regex - 正则表达式递归捕获的字符串
- field - 我如何编写代码来执行“当我在选项窗口中单击取消时,该字段将隐藏。”
- android - Sharedprefrences 不保存?
- google-cloud-platform - 即使第二个 SSL 证书设置为 Google Cloud Platform 负载平衡器,它也会从目标中消失
- c# - 我有 3 个文本框,分别代表日、月和年。由此需要计算日期
- firebase - 单个云函数调用 100+ 本地函数
- react-redux - 为什么会自动创建一个状态?(还原)
- mysql - 拆分值并循环它们
- java - 在一段时间内使用 kafka-streams 处理和检查事件
- amazon-web-services - 如何在 react-native 中将多张图片上传到 s3?