将矩阵数组合并为一个矩阵

时间:2018-04-10 15:01:48

标签: python numpy matrix

我会尽量保持清醒。

我正在尝试实现LBP(本地二进制模式)算法。

我的实施的基本全球版本工作良好。我以这种方式运行我的算法:

img = Image.open("path/of/my/image.png").convert("L") # read the image
lbpObject = LBP( numpy.array(img) ) #pass the numpy array of the img
lbpObject.execute()
result = lbpObject.getImageArray()

结果包含灰度等级正确的矩阵(我做了很多测试,相信我)

我使用LBP来实现面部识别,因此我使用该数据来执行SVM分类。 但是使用这种算法的全球版本,我的准确度非常低。 所以我正在尝试执行多块LBP。

img = Image.open("path/of/my/image.png").convert("L") # read the image
imgArray = numpy.array(img)
# Create blocks 16*16 of the original image
shaped = imgArray.reshape(16, 16, -1)
xBlocks = []

#perform LBP for each block and store the value on xBlocks
for s in shaped:
    lbpObject = LBP(s)
    lbpObject.execute()
    xBlock.append(lbpObject.getImageArray())

现在xBlock是矩阵的向量,具有我需要的值。 如何将所有值放入一个矩阵中,就像第一个结果变量一样?

Ps:LBP是我的班级。

1 个答案:

答案 0 :(得分:0)

我认为这应该有效 -

L=np.array(xBlock)
image=L.reshape((16,16,np.shape(imgArray)[0]/16,-1)).swapaxes(1,2).reshape((np.shape(imgArray)[0],-1))

我从here

获得了一些帮助
相关问题