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(bf.rescale((basis * coefficients).reshape((BLOCK_SIZE, BLOCK_SIZE)))) # Reassemble. reconstruction = sketch.assembleBlocks(reconstructed_blocks, img.shape) 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) plt.imshow(reconstruction, cmap="gray") plt.colorbar() #plt.title("Reconstruction using DCT basis \n %.2f%% sparsity" % # (100.0-((np.absolute(coefficients) > 0.01*max_value).sum()*100.0/(SIZE[0]*SIZE[1]))))
blocks, RHO, ALPHA, 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( bf.rescale((basis * coefficients).reshape( (BLOCK_SIZE, BLOCK_SIZE)))) # Reassemble. reconstruction = sketch.assembleBlocks(reconstructed_blocks, img.shape) 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) plt.imshow(reconstruction, cmap="gray") plt.colorbar() #plt.title("Reconstruction using DCT basis \n %.2f%% sparsity" % # (100.0-((np.absolute(coefficients) > 0.01*max_value).sum()*100.0/(SIZE[0]*SIZE[1]))))