0

我有一个 RGB 图像,ndarray并希望将它的紧凑抽象计算为位向量,其中每个元素指示像素是否更接近白色。(无需显示此位向量)

我查看了参考资料并找出了一些功能。但到目前为止,我只找到了一种简单的方法来获得ndarray布尔值(这比我的意图多 8 倍)。有没有直接有效的方法来实现我想要的?

到目前为止我所拥有的:

import numpy as np
import cv2

# Grayer than `128` counts as black, otherwise white
gray2bw = np.vectorize(lambda n: n < 128)

# Abstract an RGB image into black/white
def rgb2bw(image_rgb):
    return gray2bw(cv2.cvtColor(image_rgb, cv2.COLOR_BGR2GRAY))
4

0 回答 0