numpy数组-像素坐标

我正在尝试转换一张黑白图片,将其表示为具有(640,480,1)形状的numpy数组-其中640 is the x的值,-480 the y的值以及最后一个是0 or a 1代表掩码。 现在,我尝试将此数组隐藏在(640*480,2)数组中,其中rows represent 0 or 1columns代表x and y值。 我绝对不知道如何做到这一点。任何帮助表示赞赏。

urboat19 回答:numpy数组-像素坐标

听起来(我认为)您是一种热门编码,而使用numpy进行编码的最简单方法是索引np.eye(number_of_categories)

img = np.random.randint(2,(640,480,1))
out = np.eye(2)[img.ravel()]

out.shape
Out[]: (307200,2)

不确定为什么要对二进制值进行一次热编码。

本文链接:https://www.f2er.com/2952441.html

大家都在问