Пример #1
0
def preprocess(trainingSamples):
    global MS, IS
    XS = l.create_partial_XS(trainingSamples)
    MS = np.zeros((c.get_nb_teeth(), c.get_nb_dim()))
    IS = np.zeros((c.get_nb_teeth(), c.get_nb_dim()))

    for j in range(c.get_nb_teeth()):
        S = XS[j, :, :]
        M, Y = pa.PA(S)
        MS[j, :] = M

        mtx = mty = ms = mtheta = 0
        n = S.shape[0]
        for i in range(n):
            tx, ty, s, theta = mu.full_align_params(
                M, fu.original_to_cropped(S[i, :]))
            mtx += tx
            mty += ty
            ms += s
            mtheta += theta
        n = float(n)
        mtx /= n
        mty /= n
        ms /= n
        mtheta /= n
        IS[j, :] = mu.full_align(M, mtx, mty, ms, mtheta)
Пример #2
0
def test2_combined():
    Results = np.zeros(
        (c.get_nb_trainingSamples(), 3 * c.get_nb_teeth(), c.get_nb_dim()))
    color_lines = np.array([
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
    ])
    for i in c.get_trainingSamples_range():
        trainingSamples = c.get_trainingSamples_range()
        trainingSamples.remove(i)
        preprocess(trainingSamples)

        fname = c.get_fname_vis_pre(i, method)
        img = cv2.imread(fname)

        for f in range(2):
            for j in range(c.get_nb_teeth()):
                fname = c.get_fname_original_landmark(i, (j + 1))
                P = fu.original_to_cropped(
                    np.fromfile(fname, dtype=float, count=-1, sep=' '))
                if f == 0: Results[(i - 1), j, :] = P
                Results[(i - 1), (f + 1) * c.get_nb_teeth() +
                        j, :] = multi_resolution_search(img,
                                                        P,
                                                        j,
                                                        fitting_function=f)

        fname = str(i) + 'm.png'
        cv2.imwrite(
            fname,
            fu.mark_results(np.copy(img), Results[(i - 1), :], color_lines))
Пример #3
0
def test():
    for i in c.get_trainingSamples_range():
        trainingSamples = c.get_trainingSamples_range()
        trainingSamples.remove(i)
        preprocess(trainingSamples)

        fname = c.get_fname_vis_pre(i, method)
        img = cv2.imread(fname)

        for j in range(c.get_nb_teeth()):
            fname = c.get_fname_original_landmark(i, (j + 1))
            P = fu.original_to_cropped(
                np.fromfile(fname, dtype=float, count=-1, sep=' '))
            fname = str(i) + '-' + str((j + 1)) + '.png'
            cv2.imwrite(fname,
                        fu.show_iteration(np.copy(img), 10000, P, IS[j, :]))
Пример #4
0
def test1():
    for i in c.get_trainingSamples_range():
        trainingSamples = c.get_trainingSamples_range()
        trainingSamples.remove(i)
        preprocess(trainingSamples)

        fname = c.get_fname_vis_pre(i, method)
        img = cv2.imread(fname)

        for j in range(c.get_nb_teeth()):
            fname = c.get_fname_original_landmark(i, (j + 1))
            P = fu.original_to_cropped(
                np.fromfile(fname, dtype=float, count=-1, sep=' '))
            R = multi_resolution_search(img, P, j)
            fname = str(i) + '-' + str((j + 1)) + '.png'
            cv2.imwrite(fname, fu.mark_results(np.copy(img), np.array([P, R])))
Пример #5
0
def create_average_models(trainingSamples, method=''):
    XS = l.create_partial_XS(trainingSamples)
    MS = np.zeros((c.get_nb_teeth(), c.get_nb_dim()))
    IS = np.zeros((c.get_nb_teeth(), c.get_nb_dim()))
    
    for j in range(c.get_nb_teeth()):
        S = XS[j,:,:]
        M, Y = pa.PA(S)
        MS[j,:] = M
        
        mtx = mty = ms = mtheta = 0
        n = S.shape[0]
        for i in range(n):
            tx, ty, s, theta = mu.full_align_params(M, fu.original_to_cropped(S[i,:]))
            mtx += tx
            mty += ty
            ms += s
            mtheta += theta
        n = float(n)
        IS[j,:] = mu.full_align(M, (mtx / n), (mty / n), (ms / n), (mtheta / n))  
Пример #6
0
def test3_combined():
    BS = cu.create_bboxes(method)
    Avg = cu.get_average_size(method)

    Results = np.zeros(
        (c.get_nb_trainingSamples(), 3 * c.get_nb_teeth(), c.get_nb_dim()))
    color_lines = np.array([
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 0, 255]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([0, 255, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
        np.array([255, 0, 0]),
    ])

    for i in c.get_trainingSamples_range():
        trainingSamples = c.get_trainingSamples_range()
        trainingSamples.remove(i)
        preprocess(trainingSamples)

        fname = c.get_fname_vis_pre(i, method)
        img = cv2.imread(fname)

        Params = cu.get_average_params(trainingSamples, method)

        x_min = BS[(i - 1), 0]
        x_max = BS[(i - 1), 1]
        y_min = BS[(i - 1), 2]
        y_max = BS[(i - 1), 3]
        ty = y_min + (y_max - y_min) / 2
        for j in range(c.get_nb_teeth() / 2):
            if j == 0: tx = x_min + Avg[0, 0] / 2.0
            if j == 1: tx = x_min + Avg[0, 0] + Avg[1, 0] / 2.0
            if j == 2: tx = x_max - Avg[3, 0] - Avg[2, 0] / 2.0
            if j == 3: tx = x_max - Avg[3, 0] / 2.0

            P = limit(
                img, mu.full_align(MS[j, :], tx, ty, Params[j, 2], Params[j,
                                                                          3]))

            fname = c.get_fname_original_landmark(i, (j + 1))
            I = fu.original_to_cropped(
                np.fromfile(fname, dtype=float, count=-1, sep=' '))
            Results[(i - 1), j, :] = I
            Results[(i - 1), c.get_nb_teeth() + j, :] = limit(
                img,
                multi_resolution_search(img, P,
                                        j))  #only limit for i=9: gigantic fail
            Results[(i - 1), 2 * c.get_nb_teeth() + j, :] = P

        x_min = BS[(i - 1), 4]
        x_max = BS[(i - 1), 5]
        y_min = BS[(i - 1), 6]
        y_max = BS[(i - 1), 7]
        ty = y_min + (y_max - y_min) / 2
        for j in range(c.get_nb_teeth() / 2, c.get_nb_teeth()):
            if j == 4: tx = x_min + Avg[4, 0] / 2.0
            if j == 5: tx = x_min + Avg[4, 0] + Avg[5, 0] / 2.0
            if j == 6: tx = x_max - Avg[7, 0] - Avg[6, 0] / 2.0
            if j == 7: tx = x_max - Avg[7, 0] / 2.0

            P = limit(
                img, mu.full_align(MS[j, :], tx, ty, Params[j, 2], Params[j,
                                                                          3]))

            fname = c.get_fname_original_landmark(i, (j + 1))
            I = fu.original_to_cropped(
                np.fromfile(fname, dtype=float, count=-1, sep=' '))
            Results[(i - 1), j, :] = I
            Results[(i - 1), c.get_nb_teeth() + j, :] = limit(
                img,
                multi_resolution_search(img, P,
                                        j))  #only limit for i=9: gigantic fail
            Results[(i - 1), 2 * c.get_nb_teeth() + j, :] = P

        fname = str(i) + 'c.png'
        cv2.imwrite(
            fname,
            fu.mark_results(np.copy(img), Results[(i - 1), :], color_lines))