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))
Exemple #2
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, :]))
def create_partial_X(trainingSamples, nr_tooth=1):
    '''
    Creates an array that contains all the training samples
    corresponding to the given training samples and tooth number.
    @param trainingSamples:      the training samples
    @param nrTooth:              the number of the tooth
    @return np.array, shape=(nb of training samples, nb of dimensions)
    '''
    X = np.zeros((len(trainingSamples), c.get_nb_dim()))
    index = 0
    for i in trainingSamples:
        fname = c.get_fname_original_landmark(i, nr_tooth)
        print("loaded: " + fname)
        X[index,:] = np.fromfile(fname, dtype=float, count=-1, sep=' ')
        index += 1
    return X
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])))
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))