def main(): I = read_image('camera.jpg') display_image(I, "Original image") # Arrange image in column vector. I = I.flatten(1).T # Generate Haar basis vector (rows of H). H = numpy.asmatrix(haar.haar(len(I))) # Project image on the new basis. I_haar = H * I # Remove the second half of the coefficient. I_haar[len(I_haar)/2:, 0] = 0 # Recover the image by inverting change of basis. I_haar = H.T * I_haar error = I - I_haar distance = numpy.sqrt(error.T * error) # Rearrange pixels of the image. I_haar = numpy.reshape(I_haar, (64, 64), 'F') display_image(I_haar, "Recoevered image, distance = {}".format(distance)) pylab.show()
def apply(infile, outfile): im = Image.open(infile) pixels = list(im.getdata()) print "Olength", len(pixels) #print "Orig", pixels res = h.haar(pixels) print "Tlen", len(res) print "Tav", res[0] #print "Trans", res im.putdata(res) im.save(outfile)