宇宙第一小趴菜 2024-10-18 12:39
浏览 5

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

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

原图

img

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

img

matplotlib展示的结果

img

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()
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 创建了问题 10月18日

    悬赏问题

    • ¥15 fastreport怎么判断当前页数
    • ¥15 Kylin-Desktop-V10-GFB-Release-JICAI_02- 2207-Build14-ARM64.iso有没有这个版本的系统啊
    • ¥15 能不能通过蓝牙将传感器数据传送到手机上
    • ¥20 100元python和数据科学实验项目
    • ¥15 根据时间在调用出列表
    • ¥15 R 包chipseeker 安装失败
    • ¥15 Veeam Backup & Replication 9.5 还原问题
    • ¥15 vue-print-nb
    • ¥15 winfrom的datagridview下拉框变成了黑色,渲染不成功
    • ¥20 利用ntfy实现短信推送