如果我使用matplotlib将图像颜色映射为灰色,OpenCV将显示暗阈值图像区域阈值图像看起来很好。我在将matplotlib的cmap嵌入到tkintergui界面时遇到问题。无法使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()
根据Basic Thresholding Operations — OpenCV 2.4.13.7 documentation:
你的
maxVal
离黑人不太远(0
)。你知道吗您应该指定} to get white 。你知道吗
maxVal =
^{相关问题 更多 >
编程相关推荐