コード例 #1
0
def AlignImagesWithFiducials(img1,img2,xf1,yf1,xf2,yf2):
    """
    Aligns img2 to img1 based on an array listing the x,y coordinates of common fiducials.
    Arguments:
    img1 - the reference image to be aligned to.
    img2 - the image to be aligned to the reference image.
    xf1 - an array containing the x coordinates of the fiducials in img1
    yf1 - an array containing the y coordinates of the fiducials in img1.
    xf2 - an array containing the x coordinates of the fiducials in img2.
    yf2 - an array containing the y coordinates of the fiducials in img2.
    Returns:
    newimg - img2 as aligned and interpolated to the coordinates of img1.
    """
    #Match them
    tx,ty,theta,mag = matchFiducials_wMag(yf1,xf1,yf2,xf2)

    x2_wNaNs,y2_wNaNs,z2_wNaNs = man.unpackimage(img2,remove = False,xlim=[0,np.shape(img2)[1]],\
                           ylim=[0,np.shape(img2)[0]])
    #Apply transformations to x,y coords
    x2_wNaNs,y2_wNaNs = transformCoords_wMag(x2_wNaNs,y2_wNaNs,ty,tx,theta,mag)
    
    #Get x,y,z points from reference image
    x1,y1,z1 = man.unpackimage(img1,remove=False,xlim=[0,np.shape(img1)[1]],\
                           ylim=[0,np.shape(img1)[0]])

    #Interpolate stitched image onto expanded image grid
    newimg = griddata((x2_wNaNs,y2_wNaNs),z2_wNaNs,(x1,y1),method='linear')
    print 'Interpolation ok'
    newimg = newimg.reshape(np.shape(img1))

    #Images should now be in the same reference frame
    #Time to apply tip/tilt/piston to minimize RMS
    newimg = matchPistonTipTilt(img1,newimg)

    return newimg
コード例 #2
0
def stitchImages(img1,img2):
    """Allows user to pick fiducials for both images.
    Function then computes the transform to move img2
    to img1 reference frame.
    Updated
    """
    #Get both fiducials
    xf1,yf1 = getPoints(img1)
    xf2,yf2 = getPoints(img2)

    #Match them
    tx,ty,theta = matchFiducials(xf1,yf1,xf2,yf2)

    #Pad img1 based on translations
    img1 = man.padNaN(img1,n=round(tx),axis=1)
    img1 = man.padNaN(img1,n=round(ty),axis=0)
    #Shift img1 fiducial locations
    if tx<0:
        xf1 = xf1 - tx
    if ty<0:
        yf1 = yf1 - ty

    #Get x,y,z points from stitched image
    x2,y2,z2 = man.unpackimage(img2,xlim=[0,shape(img2)[1]],\
                           ylim=[0,shape(img2)[0]])

    #Apply transformations to x,y coords
    x2,y2 = transformCoords(x2,y2,ty,tx,theta)

    #Get x,y,z points from reference image
    x1,y1,z1 = man.unpackimage(img1,remove=False,xlim=[0,shape(img1)[1]],\
                           ylim=[0,shape(img1)[0]])

    #Interpolate stitched image onto expanded image grid
    newimg = griddata((x2,y2),z2,(x1,y1),method='linear')
    print 'Interpolation ok'
    newimg = newimg.reshape(shape(img1))

    #Images should now be in the same reference frame
    #Time to apply tip/tilt/piston to minimize RMS
    newimg = matchPistonTipTilt(img1,newimg)

    #Would like list of enlarge image showing all valid data, this is final step
    #Avoid overwritting fiducials
    #Save indices of NaNs near fiducials
    find = logical_and(sqrt((y1-xf1[0])**2+(x1-yf1[0])**2) < 15.,\
                       isnan(img1).flatten())
    for i in range(1,size(xf1)):
        find = logical_or(find,\
                logical_and(sqrt((y1-xf1[i])**2+(x1-yf1[i])**2) < 15.,\
                        isnan(img1).flatten()))

    #Include newimg data
    img1[isnan(img1)] = newimg[isnan(img1)]
    #Reset fiducials to NaNs
    img1[find.reshape(shape(img1))] = NaN

    #Return translations to automatically pad next image
    return img1,tx,ty