双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

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

宇宙第一小趴菜 宇宙第一小趴菜 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


原图

简单图形|平面|图案|了无人烟 - 原创作品 - 站酷 (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()

 

...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部