【问题标题】:How to reconstruct an image that has been divided into several pieces?如何重建已分成几块的图像?
【发布时间】:2014-07-20 17:33:10
【问题描述】:

我正在尝试编写一个代码来获取由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 

【问题讨论】:

  • 你卡在什么地方了?您要解决的下一个问题是什么?您尝试了什么,发生了什么?
  • @dg99 我不知道如何开始重建拼图,如何选择从哪一块开始以及如何获得边缘。

标签: python function matrix puzzle


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 2014-10-17
    相关资源
    最近更新 更多