import numpy import pylab from dispims import dispims trainimages = numpy.loadtxt("cifarmini_gray_images_train.txt") testimages = numpy.loadtxt("cifarmini_gray_images_test.txt") trainspectra = numpy.array([numpy.fft.fftshift(numpy.fft.fft2(im)) for im in trainimages.reshape(2000, 32, 32)]) trainamplitudes = numpy.abs(trainspectra) trainphases = numpy.angle(trainspectra) testspectra = numpy.array([numpy.fft.fftshift(numpy.fft.fft2(im)) for im in testimages.reshape(2000, 32, 32)]) testamplitudes = numpy.abs(testspectra) testphases = numpy.angle(testspectra) #SHOW SOME AMPLITUDE SPECTRA: #dispims(numpy.log(1+trainamplitudes[:25].reshape(25,32**2).T), 32, 32, 1) #SHOW SOME PHASE SPECTRA: #dispims(trainphases[:25].reshape(25,32**2).T, 32, 32, 1) #SHOW AVERAGE SPECTRA: pylab.subplot(1,2,1) pylab.imshow(numpy.log(1+trainamplitudes.mean(0))) pylab.subplot(1,2,2) pylab.plot(numpy.log(1+trainphases.mean(0))[:,5]) #SHOW PHASE/AMPLITUDE MIX: reconstructions_singlephase = numpy.fft.ifft2(numpy.fft.ifftshift(trainamplitudes[:10] * numpy.exp(1j*trainphases[0][None,:,:]))).real reconstructions_singleamplitude = numpy.fft.ifft2(numpy.fft.ifftshift(trainamplitudes.mean(0)[None,:,:] * numpy.exp(1j*trainphases[:10]))).real f2 = pylab.figure() pylab.subplot(1,2,1) dispims(reconstructions_singlephase.reshape(-1,32**2).T, 32, 32, 1) pylab.subplot(1,2,2) dispims(reconstructions_singleamplitude.reshape(-1,32**2).T, 32, 32, 1)