Example #1
0
def my_cpselect(I_path, Im_path):
    # Wrapper around cpselect that returns the point coordinates
    # in the expected format (coordinates in rows).
    # Input:
    # I - fixed image
    # Im - moving image
    # Output:
    # X - control points in the fixed image
    # Xm - control points in the moving image

    Xx = []
    Xy = []
    Xmx = []
    Xmy = []

    cplist = cpselect(I_path, Im_path)
    for ind in cplist:
        Xx.append(ind["img1_x"])
        Xy.append(ind["img1_y"])
        Xmx.append(ind["img2_x"])
        Xmy.append(ind["img2_y"])

    X = np.array([Xx, Xy])
    Xm = np.array([Xmx, Xmy])

    return X, Xm
Example #2
0
def my_cpselect(I_path, Im_path):
    # Wrapper around cpselect that returns the point coordinates
    # in the expected format (coordinates in rows).
    # Input:
    # I - fixed image
    # Im - moving image
    # Output:
    # X - control points in the fixed image
    # Xm - control points in the moving image

    # get the input_points and check if the user specified enough points

    input_points = cpselect(I_path, Im_path)
    # input_points = [{'point_id': 1, 'img1_x': 125.05849883303026, 'img1_y': 108.66886798820963, 'img2_x': 122.08820593487474, 'img2_y': 122.60132079292578}, {'point_id': 2, 'img1_x': 143.85110959287996, 'img1_y': 171.85092140494567, 'img2_x': 136.02065873959083, 'img2_y': 185.78337420966182}, {'point_id': 3, 'img1_x': 158.10757292793835, 'img1_y': 203.6039533784848, 'img2_x': 147.0370167712269, 'img2_y': 220.77651148662332}, {'point_id': 4, 'img1_x': 160.375646640334, 'img1_y': 104.78074162410277, 'img2_x': 157.40535374217842, 'img2_y': 121.62928920189907}, {'point_id': 5, 'img1_x': 160.375646640334, 'img1_y': 169.58284769255002, 'img2_x': 152.54519578704497, 'img2_y': 186.4313952703463}]
    if len(input_points) < 2: raise ValueError('Please select 2 or more points in the image')

    # initialize the array as a list and loop over input_points to extract the values adn add them as a row
    array = []
    for i in range(len(input_points)):
        array.append(list(input_points[i].values())[1:])

    # change from a list to an array, transpose and select the right rows for the output array
    array = np.array(array).transpose()
    X = array[:2, :]
    Xm = array[2:, :]

    return X, Xm
Example #3
0
def my_cpselect(I_path, Im_path):
    # Wrapper around cpselect that returns the point coordinates
    # in the expected format (coordinates in rows).
    # Input:
    # I - fixed image
    # Im - moving image
    # Output:
    # X - control points in the fixed image
    # Xm - control points in the moving image

    #------------------------------------------------------------------#
    #path_1 = '../data/image_data/1_1_t1.tif'
    #path_2 = '../data/image_data/1_1_t2.tif'
    #controlpointlist = cpselect(path_1, path_2)

    controlpointlist = cpselect(I_path, Im_path)

    #number of points

    numberOfPoints = len(controlpointlist)
    X = np.zeros(shape=(2, numberOfPoints))
    Xm = np.zeros(shape=(2, numberOfPoints))

    for i in range(numberOfPoints):
        valuesOfPoint = [*controlpointlist[i].values()]
        X[0][i] = valuesOfPoint[1]
        X[1][i] = valuesOfPoint[2]
        Xm[0][i] = valuesOfPoint[3]
        Xm[1][i] = valuesOfPoint[4]
    #------------------------------------------------------------------#

    return X, Xm
Example #4
0
def my_cpselect(I_path, Im_path):
    # Wrapper around cpselect that returns the point coordinates
    # in the expected format (coordinates in rows).
    # Input:
    # I - fixed image
    # Im - moving image
    # Output:
    # X - control points in the fixed image
    # Xm - control points in the moving image

    #------------------------------------------------------------------#
    # TODO: Call cpselect and modify the returned point coordinates.
    controlpointlist = cpselect(I_path, Im_path)

    #number of points
    numberOfPoints = len(controlpointlist)

    X = np.zeros(shape=(2, numberOfPoints))
    Xm = np.zeros(shape=(2, numberOfPoints))
    for i in range(numberOfPoints):

        valuesOfPoint = [*controlpointlist[i].values()]
        X[0][i] = valuesOfPoint[1]
        X[1][i] = valuesOfPoint[2]

        Xm[0][i] = valuesOfPoint[3]
        Xm[1][i] = valuesOfPoint[4]

    #------------------------------------------------------------------#

    return X, Xm
def my_cpselect(I_path, Im_path):
    # Wrapper around cpselect that returns the point coordinates
    # in the expected format (coordinates in rows).
    # Input:
    # I - fixed image
    # Im - moving image
    # Output:
    # X - control points in the fixed image
    # Xm - control points in the moving image

    p = cpselect(I_path, Im_path)

    X = np.zeros([2, len(p)])
    Xm = np.zeros([2, len(p)])

    for i in range(0, len(p)):
        X[0, i] = p[i]['img1_x']
        X[1, i] = p[i]['img1_y']
        Xm[0, i] = p[i]['img2_x']
        Xm[1, i] = p[i]['img2_y']

    return X, Xm
Example #6
0
def my_cpselect(I_path, Im_path):
    # Wrapper around cpselect that returns the point coordinates
    # in the expected format (coordinates in rows).
    # Input:
    # I - fixed image
    # Im - moving image
    # Output:
    # X - control points in the fixed image
    # Xm - control points in the moving image

    #------------------------------------------------------------------#
    # TODO: Call cpselect and modify the returned point coordinates.

    controlpointdictlist = cpselect(
        I_path, Im_path)  #indicate corresponding points on images
    k = len(controlpointdictlist)

    if k <= 2:
        raise AssertionError("More points must be selected")

    X = np.zeros((2, k))  #reserve memory
    Xm = np.zeros((2, k))  #reserve memory

    #Take the values of the i'th dictionaries using the corresponding keys
    for i in range(k):

        I_x = controlpointdictlist[i]['img1_x']
        I_y = controlpointdictlist[i]['img1_y']
        Im_x = controlpointdictlist[i]['img2_x']
        Im_y = controlpointdictlist[i]['img2_y']

        X[:, i] = np.array([I_x, I_y])
        Xm[:, i] = np.array([Im_x, Im_y])

    #------------------------------------------------------------------#

    return X, Xm
Example #7
0
def my_cpselect(I_path, Im_path):
    # Wrapper around cpselect that returns the point coordinates
    # in the expected format (coordinates in rows).
    # Input:
    # I - fixed image
    # Im - moving image
    # Output:
    # X - control points in the fixed image
    # Xm - control points in the moving image
    #------------------------------------------------------------------#
    controlpointlist = cpselect(I_path, Im_path)
    #------------------------------------------------------------------#
    X_xcoor = []
    X_ycoor = []
    Xm_xcoor = []
    Xm_ycoor = []
    for ind in controlpointlist:
        X_xcoor.append(ind['img1_x'])
        X_ycoor.append(ind['img1_y'])
        Xm_xcoor.append(ind['img2_x'])
        Xm_ycoor.append(ind['img2_y'])
    X = np.array([X_xcoor, X_ycoor])
    Xm = np.array([Xm_xcoor, Xm_ycoor])
    return X, Xm
Example #8
0
def my_cpselect(I_path, Im_path):
    # Wrapper around cpselect that returns the point coordinates
    # in the expected format (coordinates in rows).
    # Input:
    # I - fixed image
    # Im - moving image
    # Output:
    # X - control points in the fixed image
    # Xm - control points in the moving image

    #------------------------------------------------------------------#
    controlpointlist = cpselect(I_path, Im_path)
    l = len(controlpointlist)
    X = np.zeros((2, l))
    Xm = np.zeros((2, l))
    for i in range(l):
        coordinates = list(controlpointlist[i].values())
        X[i] = coordinates[1:3]
        Xm[i] = coordinates[3:5]
    X = np.transpose(X)
    Xm = np.transpose(Xm)
    #------------------------------------------------------------------#

    return X, Xm
Example #9
0
                             good_points,
                             None,
                             matchColor=(0, 255, 0),
                             singlePointColor=(255, 0, 0))
    plt.imshow(result), plt.show()
    cv2.imshow("result", cv2.resize(result, None, fx=0.4, fy=0.4))
    path = '....'
    cv2.imwrite(os.path.join(path, "U_match_W%d.jpg" % (i)),
                img1_miss_matched_kp)
    cv2.imwrite(os.path.join(path, "U_match_W%d.jpg" % (i + 1)),
                img2_miss_matched_kp)
    cv2.imwrite(os.path.join(path, "result%d.jpg" % (i)), result)

    #-----------------------third part--------------------------------
    # affine Transformation
    cppoints = cpselect("path" % (i + 1))
    src_points = []
    dst_points = []
    (rows, cols, ch) = original.shape
    for u in cppoints:
        src_points.append([u['img1_x'], u['img1_y']])
        dst_points.append([u['img2_x'], u['img2_y']])
    src_points_np = np.asarray(src_points, dtype=np.float32)
    dst_points_np = np.asarray(dst_points, dtype=np.float32)

    affine_matrix = cv2.getAffineTransform(src_points_np, dst_points_np)
    img_output = cv2.warpAffine(original, affine_matrix, (cols, rows))
    # plt.imshow(img_output), plt.show()

    #----------------------fourth part----------------------------------
    #find location of mismatched points in transformed image
Example #10
0
    pt1List = []
    pt2List = []

    for item in controlpointlist:
        pt1List.append([item['img1_x'], item['img1_y']])
        pt2List.append([item['img2_x'], item['img2_y']])
    pt1Array = np.float32(np.array(pt1List))
    pt2Array = np.float32(np.array(pt2List))
    return pt1Array, pt2Array

#the two images to panorama
imageLeftPath = "n1.jpg"
imageRightPath = "n2.jpg"

#Select corresponding points manually
controlpointlist = cpselect(imageRightPath, imageLeftPath)
imgLeft = cv.imread(imageLeftPath)
imgRight = cv.imread(imageRightPath)

#conver point Map to point array
leftPtArray, rightPtArray = controlpointListToArray(controlpointlist)

#compute homograpy matrix
H, mask = cv.findHomography(leftPtArray, rightPtArray, cv.RANSAC, 5.0)
rows, cols = imgLeft.shape[0], imgLeft.shape[1]

#Wrap right image according to homography
dst = cv.warpPerspective(imgRight, H, (rows * 2, cols))

#combine two images to panorama
wrappedImg = dst.copy()
Example #11
0
from cpselect.cpselect import cpselect

path_1 = '../data/image_data/1_1_t1.tif'
path_2 = '../data/image_data/1_1_t2.tif'
controlpointlist = cpselect(path_1, path_2)
Example #12
0
        gaupt1 = pts[simplex[0]]
        gaupt2 = pts[simplex[1]]
        gaupt3 = pts[simplex[2]]
        print("%f,%f,%f,%f,%f,%f" % (
            gaupt1[0],
            gaupt1[1],
            gaupt2[0],
            gaupt2[1],
            gaupt3[0],
            gaupt3[1],
        ),
              file=imFile)

    print("Finished %d" % (i))

pts = cpselect(sys.argv[1], sys.argv[2])
im1 = skio.imread(sys.argv[1])
im2 = skio.imread(sys.argv[2])
gaupts = np.array([[pt['img1_x'], pt['img1_y']] for pt in pts])
obpoints = np.array([[pt['img2_x'], pt['img2_y']] for pt in pts])
gauTri = Delaunay(gaupts)
plt.figure()
plt.imshow(im1)
plt.triplot(gaupts[:, 0], gaupts[:, 1], gauTri.simplices.copy())
plt.plot(gaupts[:, 0], gaupts[:, 1], 'o')
plt.show()
plt.figure()
plt.imshow(im2)
plt.triplot(obpoints[:, 0], obpoints[:, 1], gauTri.simplices.copy())
plt.plot(obpoints[:, 0], obpoints[:, 1], 'o')
plt.show()