使用numpy读取图像中的非0值的代码如下:
import numpy as np
from PIL import Image
# 读取图像
img = Image.open("image.png")
# 将图像转换为numpy数组
img_np = np.array(img)
# 获取非0值的坐标
non_zero_coords = np.argwhere(img_np != 0)
这段代码使用PIL库读取图像,然后将图像转换为numpy数组,最后使用np.argwhere
函数获取非0值的坐标。