In [1]:
import numpy as np
import image_registration
%load_ext autoreload
%autoreload 2
%aimport image_registration
In [2]:
im = image_registration.tests.make_extended(100)
In [3]:
yy,xx = np.indices(im.shape)
In [4]:
figure()
imshow(xx)
figure()
imshow(yy)
figure()
imshow(im)
Out[4]:
In [5]:
im2 = image_registration.tests.make_offset_extended(im, -11.7, 10.9)
In [6]:
subplot(121);imshow(im)
subplot(122);imshow(im2)
Out[6]:
In [7]:
xc = image_registration.fft_tools.correlate2d(im,im2)
In [8]:
imshow(xc)
Out[8]:
In [8]:
In [8]:
In [9]:
i1,i2,t = image_registration.tests.make_offset_images(5,-7,100)
In [10]:
subplot(121);imshow(i1)
subplot(122);imshow(i2)
Out[10]:
In [11]:
import astropy.nddata
In [12]:
astropy.nddata.convolve_fft
Out[12]:
In [14]:
#image_registration.tests.registration_testing.test_extended_shifts(1,1,100,False)
In [15]:
image_registration.tests.registration_testing.fit_extended_shifts(1,1,100,True)
Out[15]:
In [22]:
reload(image_registration.tests.registration_testing)
reload(image_registration.tests)
reload(image_registration)
reload(image_registration.chi2_shifts)
Out[22]:
In [23]:
noise_taper=True
In [24]:
imsize=99
xsh=1
ysh=1
image = image_registration.tests.make_extended(imsize)
offset_image = image_registration.tests.make_offset_extended(image, xsh, ysh, noise_taper=noise_taper)
if noise_taper:
noise = 1.0/image_registration.tests.edge_weight(imsize)
else:
noise = 1.0
xoff,yoff,exoff,eyoff,(x,y,c2a) = image_registration.chi2_shift(image,offset_image,1.,return_error=True,verbose=True,upsample_factor='auto',return_chi2array=True)
print "SCALAR error: ",xoff,yoff,exoff,eyoff
print
xoff,yoff,exoff,eyoff,(x,y,c2) = image_registration.chi2_shift(image,offset_image,noise,return_error=True,verbose=True,upsample_factor='auto',return_chi2array=True)
c2map,term1,term2,term3 = image_registration.chi2n_map(image,offset_image,noise,return_all=True)
c2mapA,term1A,term2A,term3A = image_registration.chi2n_map(image,offset_image,1.,return_all=True)
print xoff,yoff,exoff,eyoff
In [19]:
subplot(131); imshow(image)
subplot(132); imshow(offset_image)
subplot(133); imshow(noise)
figure()
imshow(c2.real); colorbar()
figure()
imshow(term2); colorbar()
figure()
imshow(term3); colorbar()
figure()
imshow(c2map); colorbar()
figure()
subplot(131); imshow(image/noise**2); colorbar()
subplot(132); imshow(offset_image**2); colorbar()
subplot(133); imshow(noise**2); colorbar()
Out[19]:
In [20]:
figure()
imshow(c2a.real); colorbar()
figure()
imshow(term2A); colorbar()
figure()
print term1A,term3A
imshow(c2mapA); colorbar()
Out[20]:
In [20]:
In [20]:
In [25]:
x = linspace(-5,5)
In [28]:
g = exp(-x**2)
In [29]:
plot(x,g)
Out[29]:
In [30]:
d = np.ones([3,3])
In [31]:
fft2(d)
Out[31]:
In [33]:
fft.fft(d,axis=0)
Out[33]:
In [34]:
fft.fft(fft.fft(d,axis=0),axis=1)
Out[34]:
In [1]:
x = linspace(-5,5,10)
g = exp(-x**2)
In [2]:
plot(g)
Out[2]:
In [4]:
from numpy.fft import *
In [5]:
gft = fft(g)
In [10]:
guft = np.zeros(g.size*10,dtype=complex)
guft[:5] = gft[:5]
guft[-5:] = gft[-5:]
In [11]:
plot(guft.real)
plot(guft.imag)
Out[11]:
In [25]:
gus=real(ifft(guft))*g.size
plot(linspace(x.min(),x.max(),guft.size),gus)
plot(x,g)
Out[25]:
In [18]:
gft,gft[-5:],gft[:5]
Out[18]:
In [21]:
x2 = linspace(-5,5,11)
g2 = exp(-x2**2)
plot(g2)
Out[21]:
In [22]:
gft2 = fft(g2)
guft2 = np.zeros(g2.size*10,dtype=complex)
guft2[:5] = gft2[:5]
guft2[-5:] = gft2[-5:]
In [23]:
plot(guft2.real)
plot(guft2.imag)
Out[23]:
In [26]:
gus2 = real(ifft(guft2))*g2.size
plot(linspace(x2.min(),x2.max(),guft2.size),gus2)
plot(x2,g2)
Out[26]:
In [28]:
plot(g2)
plot(gus2[::10])
Out[28]:
In [29]:
plot(g)
plot(gus[::10])
Out[29]:
In [44]:
plot(gus[gus.size/2-g.size:gus.size/2+1])
plot(gus2[gus2.size/2-g2.size+1:gus2.size/2+1])
Out[44]:
In [36]:
plot(fft(gus[45:56]).real)
plot(gft)
Out[36]:
In [45]:
gft
Out[45]:
In [46]:
conj(gft)
Out[46]:
In [ ]: