[英]Moving and writing pixels of an image -Python-
好的,我在 python 有一个新手问题。 所以我有一个列表,其中包含我感兴趣的一些像素的坐标。 我想将这些像素移动到另一个图像中或将这些像素保存在新图像中。 到目前为止,我正在使用 cv2 和 matplotlib ,我什至想用 RGB 值保存坐标并将其写入另一个图像,但我不知道如何开始。 对不起,如果这是一个愚蠢的问题,谢谢
您可以像在 numpy 阵列中一样执行此操作。 例如,您想使用所有三个通道获取 RGB 图像的前 10x10 部分。 基本上;
new_image = np.zeros([10, 10, 3], dtype=np.uint8)
new_image[:, :, :] = old_image[:10, :10, :]
img_src = cv2.imread('someimg.jpg')
h, w, c = img_src.shape
# an empty black image for saving pixels
img_dest = np.zeros((h, w, c), dtype=np.uint8)
for ixy in xy_list:
x, y = xy_list[ixy]
# copy pixels at given locations
img_dest[x, y, :] = img_src[x, y, :]
cv2.imwrite('output.jpg', img_dest)
这能解决你的问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.