OpenCV显示深色阈值图像,如果我使用matplotlib将图像颜色映射为灰色,则阈值图像看起来很好。我在将matplotlib的cmap嵌入到我的tkinter gui界面时遇到问题。无法使OpenCV正确显示我的阈值图像。
我希望图像看起来如何。 (使用cmap = gray使用matplotlib进行显示)
OpenCV的实际外观。 (我想要与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()
答案 0 :(得分:0)
根据Basic Thresholding Operations — OpenCV 2.4.13.7 documentation:
阈值二进制
此阈值运算可以表示为:
您的maxVal
是14
-与黑色(0
)距离不太远。
您应指定maxVal =
255
to get white。