Beispiel #1
0
    yc = align_ref_loc[1]
    d = align_ref_loc[2]
    align_ref_data = img[yc-d:yc+d+1, xc-d:xc+d+1,:].mean(axis=2)

# Get data used for co-rotate the images
if rotate_points is not None:
    rx1,ry1,rx2,ry2,rs = rotate_points
    rot1_data = img[ry1-rs:ry1+rs+1,rx1-rs:rx1+rs+1,:].mean(axis=2)
    rot2_data = img[ry2-rs:ry2+rs+1,rx2-rs:rx2+rs+1,:].mean(axis=2)
    rotate_angle = 180*math.atan2((ry2-ry1),(rx2-rx1))/math.pi
    if rotate_angle is not 0:
        print "Rotation angle is %3.3f deg" % rotate_angle
        img = ndimage.rotate(img, rotate_angle, reshape=False)
        # If the base-image got rotated, we need to align it so
        # that the reference point is in the correct place
        b,xb,yb = align(img.mean(axis=2), align_ref_data, area=align_search_area)
        tx = align_ref_loc[0] - xb # translation in x-direction
        ty = align_ref_loc[1] - yb # translation in y-direction
        print "Shift: x: %d, y: %d, correlation (R^2): %1.3f" % (tx,ty,b)
        n_x1,n_x2,n_y1,n_y2,o_x1,o_x2,o_y1,o_y2 = calc_align_area(tx,ty,w,h) 
        # Move image data by the calculated amount
        n_img = 0*img.copy()
        n_img[n_y1:n_y2,n_x1:n_x2,:] = img[o_y1:o_y2,o_x1:o_x2,:]
        img = n_img.copy()

# Calculate normalization value, or normalize the base image to given value
if normalization is not None:
    if normalization_area is None:
        normalization_area = (0,0,w,h)
    x1,y1,x2,y2 = normalization_area