- cv2.imshow()显示图像时,一闪而过
cv.imshow("img", img) cv.waitKey(0) # 无限循环,等待用户按键触发跳出循环
- cv2.imwrite()保存图像为全黑
img = img * 255 cv2.imwrite('img.jpg', img)
原因:原本img的数值是在0-255,但在保存img被标准化了,使得img的值0-1之间,所以在保存时img值需要乘上255。
- 两图像加权融合并保存
img_ori = cv2.imread(Ori_img_path) # img_ori = adaptContrastEnhancement(img_ori, 15, 10) # 颜色增强有杂质 hmap_viridis = cv2.imread(heatmap_path+'_viridis.png') # img_ori = io.imread(Ori_img_path) # gam = exposure.adjust_gamma(img_ori, 0.1) # 调亮如果gamma<1, 新图像比原图像亮,数值越小越亮 # hmap = io.imread(heatmap_path) # gam = exposure.adjust_gamma(hmap, 0.1) img_ori_resize = cv2.resize(img_ori, (hmap_viridis.shape[1], hmap_viridis.shape[0])) combined = cv2.addWeighted(img_ori_resize, 0.6, hmap_viridis, 0.4, 0) # combined = cv2.add(img_ori_resize, hmap) # 用cv2.add方法两图像融合后会变色 # ############ cv2.imwrite方法保存图像 CombinedImgSave_path = savePath + '_combinedImg.png' # cv2.imshow('combined', combined) # cv2.waitKey(0) cv2.imwrite(filename=CombinedImgSave_path, img=combined) # 保存后不变色 # ############ PIL方法保存 from PIL import Image combined = Image.fromarray(combined) combined.save(CombinedImgSave_path) # 会变色 # ############ plt.savefig方法保存 plt.imshow(combined) plt.savefig(CombinedImgSave_path) # 会变色 # ############ imageio.imsave方法保存--待验证 import imageio imageio.imsave(CombinedImgSave_path, combined) # 会变色