维数
import cv2
labels_path = "test/labels/"
labels2_path = "test/labels2/"
for image in os.listdir(labels_path):
#print(image)
index, _ = os.path.splitext(image)
print(index)
image_file = os.path.join(labels_path, image)
img = cv2.imread(image_file).astype(np.float32)
#img2 = np.array(img);
#print(img2)
save_img = np.zeros((256, 256), dtype=np.uint16)
for i in range(256):
for j in range(256):
#save_img[i][j] = int(img[i][j] / 100.0) #img2
print(img[i][j])
cv2.imwrite(os.path.join(labels_path, index+".png"), save_img)
TypeError系列之:TypeError: only size-1 arrays can be converted to Python scalars&Numpy读取图片遍历像素值
原文:https://www.cnblogs.com/2008nmj/p/13595629.html