예제 #1
0
    # Get sparsity.
    sparsity = sketch.computeSparsity(block_coefficients)
    print "Sparsity: " + str(sparsity)

    # Compute reconstruction for each block.
    print "Reconstructing..."
    reconstructed_blocks = []
    for i, coefficients in enumerate(block_coefficients):
        print "Progress: %d / %d" % (i, len(block_coefficients))
        reconstructed_blocks.append((basis * coefficients).reshape(
            (blocks[0].shape[0], blocks[0].shape[1])))

    # Reassemble.
    reconstruction = sketch.assembleBlocks_withOverlap(reconstructed_blocks,
                                                       BLOCK_SIZE, img.shape,
                                                       OVERLAP_PERCENT)

    # Note this may not work because the reconstructed_blocks are bigger than expected
    # because of the overlap
    # visualization = sketch.visualizeBlockwiseSparsity(reconstructed_blocks,
    #                                                  sparsity,
    #                                                  img.shape)

    # print estimate of sparsity
    #print np.median(np.asarray(coefficients.T))

    # Plot.
    #max_value = np.absolute(coefficients).max()
    plt.figure(1)
    #plt.subplot(121)
                                                                 BASIS_OVERSAMPLING)

    # Get sparsity.
    sparsity = sketch.computeSparsity(block_coefficients)
    print "Sparsity: " + str(sparsity)
    
    # Compute reconstruction for each block.
    print "Reconstructing..."
    reconstructed_blocks = []
    for i, coefficients in enumerate(block_coefficients):
        print "Progress: %d / %d" % (i, len(block_coefficients))    
        reconstructed_blocks.append((basis * coefficients).reshape((blocks[0].shape[0],
                                                                    blocks[0].shape[1])))
        
    # Reassemble.
    reconstruction = sketch.assembleBlocks_withOverlap(reconstructed_blocks, 
                                                        BLOCK_SIZE, img.shape, OVERLAP_PERCENT)

    # Note this may not work because the reconstructed_blocks are bigger than expected
    # because of the overlap
    # visualization = sketch.visualizeBlockwiseSparsity(reconstructed_blocks,
    #                                                  sparsity,
    #                                                  img.shape)

    
    # print estimate of sparsity
    #print np.median(np.asarray(coefficients.T))
    
    # Plot.
    #max_value = np.absolute(coefficients).max()
    plt.figure(1)
    #plt.subplot(121)