如何重建已分成几部分的图像?

时间:2014-05-30 21:01:20

标签: python function matrix puzzle

我正在尝试编写一个获取图像片段的代码,这些代码由m X m矩阵表示。如果一件矩阵的右侧与另一件的左侧相同,则两件件属于一起,这两件应该“胶合”。

我编写了将两张图片连接在一起的函数join,我开始编写拼图解决功能,但我卡住了,我不知道如何继续。

def join_h(mat1, mat2):
    """ joins two matrices, side by side with some separation """
    n1,m1 = mat1.dim()
    n2,m2 = mat2.dim()
    m = m1+m2+10
    n = max(n1,n2)
    new = Matrix(n, m, val=255)  # fill new matrix with white pixels

    new[:n1,:m1] = mat1
    new[:n2,m1+10:m] = mat2
    '''
    #without slicing:
    for i in range(n1):
        for j in range(m1):
            new[i,j] = mat1[i,j]

    for i in range(n2):
        for j in range(m2):
            new[i,j+m1+10] = mat2[i,j]
    '''
    return new

def reconstruct_image(m):
    matlst=getlistmatrix()
    for i in range(len(matlst)):
        if matlst[i][i]==matls[i+1][i+1]


def getlistmatrix():
    matrixlst=[]
    for i in range(1,1601):
        matrixlst.append(Matrix.load('./im'+str(i) +'.bitmap'))
    return matrixlst 

1 个答案:

答案 0 :(得分:0)

scikit-learn 库为您提供了“reconstruct_from_patches_2d” - sklearn.feature_extraction.image.reconstruct_from_patches_2d

如果您知道重叠块的顺序,那么您应该能够使用它。

参考:http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.image.reconstruct_from_patches_2d.html#sklearn.feature_extraction.image.reconstruct_from_patches_2d

他们为同一个提供的示例 - http://scikit-learn.org/stable/auto_examples/decomposition/plot_image_denoising.html#example-decomposition-plot-image-denoising-py