コード例 #1
0
def example_lines():
    """Plot for example_lines, illustrating entire forward process both with and without hanning filter."""
    im = TestImage(shift=True, nx=1000, ny=1000)
    im.addLines(width=10, spacing=75, value=5, angle=45)
    im.zeroPad()
    im.calcAll()
    im.plotMore()
    pylab.savefig('example_lines_a.%s' %(figformat), format='%s' %(figformat))
    pylab.close()
    im = TestImage(shift=True, nx=1000, ny=1000)
    im.addLines(width=10, spacing=75, value=5, angle=45)
    im.hanningFilter()
    im.zeroPad()
    im.calcAll()
    im.plotMore()
    pylab.savefig('example_lines_b.%s' %(figformat), format='%s' %(figformat))
    pylab.close()
    return
コード例 #2
0
# Walk through constructing & inverting the Image/FFT/PSD/ACovF & 1d PSD/1d ACovF. 
# Comment and uncomment lines to do different things (this is really just a sort of convenient working script). 

import numpy
import pylab

from testImage import TestImage
# from pImage import PImage  # if you don't need to do any plotting
from pImagePlots import PImagePlots  # if you do need to use the plotting functions for PImage

# Use TestImage to set up the image
im = TestImage(shift=True, nx=750, ny=750)
im.addLines(spacing=50, width=10, value=10, angle=0)
#im.addGaussian(xwidth=30, ywidth=30)
#im.addSin(scale=100)
#im.addCircle(radius=20)
#im.addEllipseRandom(nEllipse=100, value=5)
im.addNoise(sigma=1.)
#im.hanningFilter()
#im.zeroPad()

# Calculate FFT/PSD2d/ACovF/PSD1d in one go (can do these separately too).
# Use automatic binsize or user-defined binsize.
im.calcAll(min_dr=1.0, min_npix=2)
im.plotMore()

#im.showImage()
#im.showAcovf2d(log=True, imag=False)
#im.showPsd1d()
#im.showAcovf1d()
#im.showSf()
コード例 #3
0
def inversion():
    """Generate some example images & invert them to reconstruct the original image."""
    im = TestImage(shift=True, nx=1000, ny=1000)
    #im.addEllipseGrid(gridX=200, gridY=100, semiX=50, semiY=25, value=1)
    im.addLines(width=20, spacing=200, value=1, angle=45)
    im.addSin(scale=300)
    im.hanningFilter()
    im.zeroPad()
    #cmap = pylab.cm.gray_r
    cmap = None
    clims = im.showImage(cmap=cmap)
    pylab.savefig('invert_image.%s' %(figformat), format='%s' %(figformat))
    im.calcAll(min_npix=1, min_dr=1)
    # Invert from ACovF and show perfect reconstruction.
    im.invertAcovf2d()
    im.invertPsd2d(useI=True)
    im.invertFft(useI=True)
    im.showImageI(clims=clims, cmap=cmap)
    pylab.savefig('invert_acovf2d_good.%s' %(figformat), format='%s' %(figformat))
    # Invert from ACovF 2d without phases
    im.invertAcovf2d(usePhasespec=False, seed=42)
    im.invertPsd2d(useI=True)
    im.invertFft(useI=True)    
    im.showImageI(clims=clims, cmap=cmap)
    pylab.savefig('invert_acovf2d_nophases.%s' %(figformat), format='%s' %(figformat))
    # Invert from ACovF 1d with phases
    im.invertAcovf1d(phasespec=im.phasespec)
    im.invertAcovf2d(useI=True)
    im.invertPsd2d(useI=True)
    im.invertFft(useI=True)
    im.showImageI(clims=clims, cmap=cmap)
    pylab.savefig('invert_acovf1d_phases.%s' %(figformat), format='%s' %(figformat))
    # Invert from ACovF 1d without phases
    im.invertAcovf1d(seed=42)
    im.invertAcovf2d(useI=True)
    im.invertPsd2d(useI=True)
    im.invertFft(useI=True)
    im.showImageI(clims=clims, cmap=cmap)
    pylab.savefig('invert_acovf1d_nophases.%s' %(figformat), format='%s' %(figformat))
    # Recalculate 1-d PSD and ACovF from this last reconstructed image (ACovF1d no phases)
    im2 = PImagePlots()
    im2.setImage(im.imageI)
    im2.calcAll(min_npix=1, min_dr=1)
    legendlabels=['Reconstructed', 'Original']
    im2.showPsd1d(comparison=im, legendlabels=legendlabels)
    pylab.savefig('invert_recalc_ACovF_Psd1d.%s' %(figformat), format='%s' %(figformat))
    im2.showAcovf1d(comparison=im, legendlabels=legendlabels)
    pylab.savefig('invert_recalc_ACovF_Acovf1d.%s' %(figformat), format='%s' %(figformat))
    # Invert from PSD and show perfect reconstruction.                          
    im.invertPsd2d()
    im.invertFft(useI=True)
    im.showImageI(clims=clims, cmap=cmap)
    pylab.savefig('invert_psd2d_good.%s' %(figformat), format='%s' %(figformat))
    # Invert from PSD 2d without phases
    im.invertPsd2d(usePhasespec=False, seed=42)
    im.invertFft(useI=True)
    im.showImageI(clims=clims, cmap=cmap)
    pylab.savefig('invert_psd2d_nophases.%s' %(figformat), format='%s' %(figformat))
    # Invert from PSD 1d with phases                                   
    im.invertPsd1d(phasespec=im.phasespec)
    im.invertPsd2d(useI=True)
    im.invertFft(useI=True)
    im.showImageI(clims=clims, cmap=cmap)
    pylab.savefig('invert_psd1d_phases.%s' %(figformat), format='%s' %(figformat))
    # Invert from PSD 1d without phases                                             
    im.invertPsd1d(seed=42)
    im.invertPsd2d(useI=True)
    im.invertFft(useI=True)
    im.showImageI(clims=clims, cmap=cmap)
    pylab.savefig('invert_psd1d_nophases.%s' %(figformat), format='%s' %(figformat))
    # Recalculate 1-d PSD and ACovF from this last reconstructed image (PSD1d no phases)
    im2 = PImagePlots()
    im2.setImage(im.imageI)
    im2.calcAll(min_npix=1, min_dr=1)
    im2.showPsd1d(comparison=im, legendlabels=legendlabels)
    pylab.savefig('invert_recalc_PSD_Psd1d.%s' %(figformat), format='%s' %(figformat))
    im2.showAcovf1d(comparison=im, legendlabels=legendlabels)
    pylab.savefig('invert_recalc_PSD_Acovf1d.%s' %(figformat), format='%s' %(figformat))
    pylab.close()
    return
コード例 #4
0
ファイル: test.py プロジェクト: rhiannonlynne/powerspectrum
import pylab
from testImage import TestImage

# Plain image, with noise
im = TestImage()
im.addLines(width=10, spacing=50, value=5)
#im.addNoise()
im.hanningFilter()
im.zeroPad()
im.calcAll()
#im.plotAll(title='Gaussian Noise')
im.plotMore(title='Gaussian Noise')
pylab.show()
exit()

# Gaussian image
im = TestImage()
im.addGaussian(xwidth=20, ywidth=20)
im.hanningFilter()
im.zeroPad()
im.calcAll()
im.plotAll(title='Gaussian')

# Sin, s=100
im = TestImage()
im.addSin(scale=100)
im.hanningFilter()
im.zeroPad()
im.calcAll()
im.plotAll(title='Sin, scale=100')