如何在 python 中繪制邏輯陣列,例如,我有以下代碼:
import numpy as np
import matplotlib.pyplot as plt
filename = r"test.jpg"
img = cv2.imread(filename)
cv2.imshow("image", img)
b, g, r = cv2.split(img)
cv2.imshow('Green', g)
g_dominant = (g > b) & (g > r)
我如何繪制并查看“g_dominant”。Matlab 將其視為二進制影像,但我無法將其繪制在 cv2.imshow 上。
謝謝。
uj5u.com熱心網友回復:
您大部分時間都在那里,您需要附上條件陳述句。
代碼:
img = cv2.imread('parrot.jpg')
b, g, r = cv2.split(img)
# create 2-channel image of the same shape
# here is where we will display the result
mask = np.zeros((img.shape[0], img.shape[1]), np.uint8)
# Coordinates where green pixels are dominant are made 255 (white)
mask[(g > r) & (g > b)] = 255
cv2.imshow('Result', mask)
cv2.waitKey(0)
例子:
輸入

結果

輸入

輸出

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/479040.html
下一篇:如何根據類更改抓取蒙版中的顏色
