自动摘要: 首先用opencv保存失败,或者保存出来与原图效果一样,但是矩阵不一致,所以采用PIL保存; ```python importos importcv2 importnumpyasnp ……..
- 首先用opencv 保存失败,或者保存出来与原图效果一样,但是矩阵不一致,所以采用PIL保存;
1
2
3
4
5
6
7
8
9
10
11import os
import cv2
import numpy as np
import PIL.Image
import imgviz
if __name__ == '__main__':
path = r"F:\My_Github\test_demo\merge2.jpg"
path_out = r"F:\My_Github\test_demo\merge_out.jpg"
img1 = cv2.imread(path,0)
cv2.imwrite(path_out,img1)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21import os
import cv2
import numpy as np
import PIL.Image
import imgviz
# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
# 在下面的代码行中使用断点来调试脚本。
path = r"F:\My_Github\test_demo\merge2.jpg"
path_out = r"F:\My_Github\test_demo\merge_out.jpg"
img_label = PIL.Image.open(path)
img_label=np.array(img_label)
lbl_pil = PIL.Image.fromarray(img_label.astype(np.uint8), mode="P")
colormap = imgviz.label_colormap()
lbl_pil.putpalette(colormap.flatten())
lbl_pil.save(path_out)
# 或者保存原图
image = PIL.Image.fromarray(img_label)
image.save(path_out)