导入相关库
import numpy as np
import glob
from PIL import Image
import cv2
import matplotlib.pyplot as plt
**
遍历文件夹图片
**
imgs = glob.glob("文件夹地址")
**
循环操作并保存
**
for img in imgs:
path = img
# img = cv2.imread(img, 0)[:, 565:565*2] #D
# img = cv2.imread(img, 0)[:, 700:695*2] #S
img = cv2.imread(img, 0)[:, 1000:990*2] #C
colormap = plt.get_cmap('inferno')
heatmap = (colormap(img) * 2**16).astype(np.uint16)[:,:,:3]
heatmap = cv2.cvtColor(heatmap, cv2.COLOR_RGB2BGR)
name = path.split("\\")[-1]
print(f"./C/{name}")
cv2.imwrite(f"./C/{name}", heatmap)
目标分割任务中,常常可以明显区分目标与背景分割程度。