コード例 #1
0
ファイル: gridoverlap.py プロジェクト: Germanc/supreme
def plot_overlap(n):
    # Select an overlapping pixel and highlight it
    p1 = grid1[n]
    p2 = grid2[n]
    overlap = zip(*ext.poly_clip(p2.x, p2.y,
                                 p1.x.min(), p1.x.max(),
                                 p1.y.max(), p1.y.min()))

    ax = plt.subplot(121)
    ax.add_patch(patches.Polygon(zip(p1.x,p1.y), facecolor=[0.7, 0.7, 0.9]))
    ax.add_patch(patches.Polygon(zip(p2.x,p2.y), facecolor=[0.9, 0.8, 0.9]))
    ax.add_patch(patches.Polygon(overlap, facecolor=[0.3,0.9,0.3]))

    plotgrid(ax, grid1, 'r-')
    plotgrid(ax, grid2, 'b-')
    ax.axis('equal')
    ax.set_xticks([])
    ax.set_yticks([])
    ax.axis([-2,12,-2,12])

    f = plt.subplot(122).get_frame()
#    print [f.get_x(),f.get_y(),f.get_width()/2,f.get_height()/2]
#    plt.axes()

    coords = poly_coords(Polygon([0,1,1,0],[0,0,1,1]))
    angles = np.linspace(-np.pi,np.pi,50)
    offsets = np.linspace(-1,1.5,50)
    weights = np.zeros((len(angles),len(offsets)))
    print "Calculating overlaps..."
    for i,theta in enumerate(angles):
        for j,offset in enumerate(offsets):
            x,y = np.dot(tf(theta,offset,offset), coords)[:2]
            x,y = ext.poly_clip(x,y,0,1,1,0)
            if len(x) >= 3:
                weights[i,j] = Polygon(x,y).area()


    plt.rcParams['figure.figsize'] = (6.67,3.335)
    plt.imshow(weights)
    plt.subplots_adjust(wspace=0.4)
    plt.xlabel("Offset")
    plt.ylabel("Angle")
    plt.xlim([0,50])
    plt.ylim([0,50])
    plt.xticks([0,25,50],('-1','0.25','1.5'))
    plt.yticks([0,25,50],('$\pi$','0','$-\pi$'))

    mkdir('output')
    plt.savefig('output/gridoverlap.eps')
コード例 #2
0
def plot_overlap(n):
    # Select an overlapping pixel and highlight it
    p1 = grid1[n]
    p2 = grid2[n]
    overlap = zip(*ext.poly_clip(p2.x, p2.y, p1.x.min(), p1.x.max(),
                                 p1.y.max(), p1.y.min()))

    ax = plt.subplot(121)
    ax.add_patch(patches.Polygon(zip(p1.x, p1.y), facecolor=[0.7, 0.7, 0.9]))
    ax.add_patch(patches.Polygon(zip(p2.x, p2.y), facecolor=[0.9, 0.8, 0.9]))
    ax.add_patch(patches.Polygon(overlap, facecolor=[0.3, 0.9, 0.3]))

    plotgrid(ax, grid1, 'r-')
    plotgrid(ax, grid2, 'b-')
    ax.axis('equal')
    ax.set_xticks([])
    ax.set_yticks([])
    ax.axis([-2, 12, -2, 12])

    f = plt.subplot(122).get_frame()
    #    print [f.get_x(),f.get_y(),f.get_width()/2,f.get_height()/2]
    #    plt.axes()

    coords = poly_coords(Polygon([0, 1, 1, 0], [0, 0, 1, 1]))
    angles = np.linspace(-np.pi, np.pi, 50)
    offsets = np.linspace(-1, 1.5, 50)
    weights = np.zeros((len(angles), len(offsets)))
    print "Calculating overlaps..."
    for i, theta in enumerate(angles):
        for j, offset in enumerate(offsets):
            x, y = np.dot(tf(theta, offset, offset), coords)[:2]
            x, y = ext.poly_clip(x, y, 0, 1, 1, 0)
            if len(x) >= 3:
                weights[i, j] = Polygon(x, y).area()

    plt.rcParams['figure.figsize'] = (6.67, 3.335)
    plt.imshow(weights)
    plt.subplots_adjust(wspace=0.4)
    plt.xlabel("Offset")
    plt.ylabel("Angle")
    plt.xlim([0, 50])
    plt.ylim([0, 50])
    plt.xticks([0, 25, 50], ('-1', '0.25', '1.5'))
    plt.yticks([0, 25, 50], ('$\pi$', '0', '$-\pi$'))

    mkdir('output')
    plt.savefig('output/gridoverlap.eps')
コード例 #3
0
ファイル: match.py プロジェクト: Germanc/supreme
# Astronomy
#out[out > 10] = 10
#out /= out.max()


print "Stacking using polygon overlap..."
out2 = np.zeros(oshape,float)
for i,(img,M) in enumerate(zip(images,tf_matrices)):
    print "Stacking frame %d" % i
    out2 += sr.ext.interp_transf_polygon(img,np.linalg.inv(M),oshape)
out2 /= len(images)
out2[out2 > 500] = 500

import scipy as S
imsave = S.misc.pilutil.imsave
mkdir('output')

imsave('output/original.png', images[0])
imsave('output/_linear.png', out1)
imsave('output/_polygon.png', out2)

plt.subplot(121)
plt.imshow(out1,interpolation='nearest',cmap=plt.cm.gray)
plt.subplot(122)
plt.imshow(out2,interpolation='nearest',cmap=plt.cm.gray)
plt.show()

print "Valid image files:"
print ' '.join([image_files[i] for i, v in enumerate(valid_matrices)
                if v])
コード例 #4
0
out1 = sr.register.stack.with_transform(images, tf_matrices, oshape=oshape)

# Astronomy
#out[out > 10] = 10
#out /= out.max()

print "Stacking using polygon overlap..."
out2 = np.zeros(oshape, float)
for i, (img, M) in enumerate(zip(images, tf_matrices)):
    print "Stacking frame %d" % i
    out2 += sr.ext.interp_transf_polygon(img, np.linalg.inv(M), oshape)
out2 /= len(images)
out2[out2 > 500] = 500

import scipy as S
imsave = S.misc.pilutil.imsave
mkdir('output')

imsave('output/original.png', images[0])
imsave('output/_linear.png', out1)
imsave('output/_polygon.png', out2)

plt.subplot(121)
plt.imshow(out1, interpolation='nearest', cmap=plt.cm.gray)
plt.subplot(122)
plt.imshow(out2, interpolation='nearest', cmap=plt.cm.gray)
plt.show()

print "Valid image files:"
print ' '.join([image_files[i] for i, v in enumerate(valid_matrices) if v])