python的matplotlib显示的trunc图和opencv展示的不一样

宇宙第一小趴菜 2024-10-18 12:53:00


原图

简单图形|平面|图案|了无人烟 - 原创作品 - 站酷 (ZCOOL)

opencv截断(trunc)处理展示的结果

 matplotlib展示的结果

matplotlib中所展示的trunc和opencv看到的不同

代码

import cv2
import matplotlib.pyplot as plt

def show_img(name, img):
    cv2.imshow(name, img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

heart = cv2.imread('heart.jpg')
heart_gary = cv2.cvtColor(heart, cv2.COLOR_BGR2GRAY)

ret_binary, binary = cv2.threshold(heart_gary, 127, 255, cv2.THRESH_BINARY)
ret_binary_inv, binary_inv = cv2.threshold(heart_gary, 127, 255, cv2.THRESH_BINARY_INV)
ret_trunc,  trunc = cv2.threshold(heart_gary, 127, 255, cv2.THRESH_TRUNC)
ret_to_zero,  to_zero = cv2.threshold(heart_gary, 127, 255, cv2.THRESH_TOZERO)
ret_to_zero_inv,  to_zero_inv = cv2.threshold(heart_gary, 127, 255, cv2.THRESH_TOZERO_INV)

show_img('trunc', trunc)
title = ['PandasGray', 'Binary', 'BinaryInv', 'Trunc', 'ToZero', 'ToZeroInv']
images = [heart_gary , binary, binary_inv, trunc, to_zero, to_zero_inv]

# 使用matplotlib显示图像,并设置色彩映射为'gray'
plt.figure(figsize=(10, 8))  # 可以调整图像大小
for i in range(6):
    plt.subplot(2, 3, i + 1)
    plt.imshow(images[i], 'gray')
    plt.title(title[i])
    plt.xticks([]), plt.yticks([])

plt.tight_layout()  # 调整子图间距
plt.show()

 

...全文
61 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

4,262

社区成员

发帖
与我相关
我的任务
社区描述
OpenCV相关技术交流专区
计算机视觉人工智能opencv 技术论坛(原bbs) 广东省·深圳市
社区管理员
  • OpenCV
  • 幻灰龙
  • OpenCV中国团队
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

OpenCV中国团队官方博客:https://blog.csdn.net/opencvchina

试试用AI创作助手写篇文章吧