OpenCV显示暗阈值imag

2024-05-20 18:21:18 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我使用matplotlib将图像颜色映射为灰色,OpenCV将显示暗阈值图像区域阈值图像看起来很好。我在将matplotlib的cmap嵌入到tkintergui界面时遇到问题。无法使OpenCV正确显示阈值图像。你知道吗

我希望图像看起来像什么。(使用cmap=gray使用matplotlib显示)

How I want the image to look like. (Used <code>cmap=gray</code> to display using matplotlib)

OpenCV的实际外观。(我想要与matplotlib相同的结果)

How it actually looks with OpenCV. (I want the same results as matplotlib)

代码:

import cv2 as cv
import numpy as np

img = cv.imread('dataset.tif')
cv.imshow('Input Image',img)

b,g,r= cv.split(img)
cv.imshow('Red Channel',r)
cv.imshow('Green Channel',g)
cv.imshow('Blue Channel',b)
img2= cv.bitwise_not(g)
cv.imshow('Processed Image',img2)

kernel3 = cv.getStructuringElement(cv.MORPH_ELLIPSE,(13,13))
tophat = cv.morphologyEx(img2, cv.MORPH_TOPHAT, kernel3)
cv.imshow('Top hat',tophat)
thres= 12
maxValue = 14
th, dat = cv.threshold(tophat, thres, maxValue, cv.THRESH_BINARY)

cv.imshow('thresh',dat)
cv.waitKey(0)
cv2.destroyAllWindows()

Tags: 图像imageimportimgmatplotlibtophataschannel