예제 #1
0
def print_histogram_plt_x_y(k, type, landmarks_arr):
    import matplotlib.ticker as ticker
    import random
    image_utility = ImageUtility()
    num_of_bins = 20

    plt.figure()
    for lndm in landmarks_arr:
        landmark_arr_xy, landmark_arr_x, landmark_arr_y = image_utility.create_landmarks(landmarks=lndm,
                                                                                         scale_factor_x=1,
                                                                                         scale_factor_y=1)
        data = landmark_arr_x
        data = landmark_arr_y
        # plt.plot(landmark_arr_x[0:32], landmark_arr_y[0:32], '-ok', c=color)
        plt.hist(data, bins=num_of_bins, color='blue', edgecolor='blue', alpha=0.3)
        # plt.hist2d(landmark_arr_x, landmark_arr_y, bins=num_of_bins, color='blue', edgecolor='black', alpha=0.5)
        # plt.axis.set_major_formatter(ticker.PercentFormatter(xmax=len(landmark_arr_x)))

    plt.savefig('histo_X_' + str(type) + '_' + str(k) + '.png', bbox_inches='tight')
    plt.clf()

    '''for Y'''
    plt.figure()
    for lndm in landmarks_arr:
        landmark_arr_xy, landmark_arr_x, landmark_arr_y = image_utility.create_landmarks(landmarks=lndm,
                                                                                         scale_factor_x=1,
                                                                                         scale_factor_y=1)
        data = landmark_arr_y
        # plt.plot(landmark_arr_x[0:32], landmark_arr_y[0:32], '-ok', c=color)
        plt.hist(data, bins=num_of_bins, color='green', edgecolor='green', alpha=0.3)
        # plt.axis.set_major_formatter(ticker.PercentFormatter(xmax=len(data)))

    plt.savefig('histo_Y_' + str(type) + '_' + str(k) + '.png', bbox_inches='tight')
    plt.clf()
예제 #2
0
def print_arr(k, type, landmarks_arr):
    import random
    image_utility = ImageUtility()

    plt.figure()
    for lndm in landmarks_arr:
        color = "#"+''.join([random.choice('0123456789ABCDEF') for j in range(6)])

        landmark_arr_xy, landmark_arr_x, landmark_arr_y = image_utility.create_landmarks(landmarks=lndm,
                                                                                         scale_factor_x=1,
                                                                                         scale_factor_y=1)
        if type == 'full':
            plt.scatter(x=landmark_arr_x[:], y=landmark_arr_y[:], c=color, s=2)
        elif type == 'face':
            plt.scatter(x=landmark_arr_x[0:32], y=landmark_arr_y[0:32], c=color, s=5)
            plt.plot(landmark_arr_x[0:32], landmark_arr_y[0:32], '-ok', c=color)

        elif type == 'eyes':
            plt.scatter(x=landmark_arr_x[60:75], y=landmark_arr_y[60:75], c=color, s=5)
            plt.plot(landmark_arr_x[60:75], landmark_arr_y[60:75], '-ok', c=color)

        elif type == 'nose':
            plt.scatter(x=landmark_arr_x[51:59], y=landmark_arr_y[51:59], c=color, s=5)
            plt.plot(landmark_arr_x[51:59], landmark_arr_y[51:59], '-ok', c=color)

        elif type == 'mouth':
            plt.scatter(x=landmark_arr_x[76:95], y=landmark_arr_y[76:95], c=color, s=5)
            plt.plot(landmark_arr_x[76:95], landmark_arr_y[76:95], '-ok', c=color)

        elif type == 'eyebrow':
            plt.scatter(x=landmark_arr_x[33:50], y=landmark_arr_y[33:50], c=color, s=5)
            plt.plot(landmark_arr_x[33:50], landmark_arr_y[33:50], '-ok', c=color)

    plt.axis('off')
    plt.savefig('name_' + str(type) + '_' + str(k) + '.png', bbox_inches='tight')
    # plt.show()
    plt.clf()
예제 #3
0
                                               points_x_arr,
                                               points_y_arr,
                                               no_padding=False)
        xx_s = new_xy_s[0::2]
        yy_s = new_xy_s[1::2]
        #image_utility.print_image_arr(i, crop, xx_s, yy_s)
        resized_img = transform.resize(crop, (224, 224, 3), anti_aliasing=True)
        dims = crop.shape
        height = dims[0]
        width = dims[1]
        scale_factor_y = 224 / height
        scale_factor_x = 224 / width
        '''rescale and retrieve landmarks'''
        landmark_arr_xy, landmark_arr_x, landmark_arr_y = \
            image_utility.create_landmarks(landmarks=new_xy_s,
                                  scale_factor_x=scale_factor_x,
                                  scale_factor_y=scale_factor_y)

        if not (min(landmark_arr_x) < 0.0 or min(landmark_arr_y) < 0.0
                or max(landmark_arr_x) > 224 or max(landmark_arr_y) > 224):

            #image_utility.print_image_arr(i, resized_img, landmark_arr_x, landmark_arr_y)

            im = Image.fromarray((resized_img * 255).astype(np.uint8))
            im.save(str(file_name_image) + png_file_name[i])

            width = len(resized_img[0])
            height = len(resized_img[1])
            x_center = width / 2
            y_center = height / 2
            landmark_arr_flat_normalized = []
예제 #4
0
                points_arr.append(x)
                points_arr.append(y)
                points_x_arr.append(x)
                points_y_arr.append(y)
            line = fp.readline()
            cnt += 1

    img = Image.open(img_file)

    '''normalize image'''
    resized_img = np.array(img) / 255.0

    #resized_img = transform.resize(resized_img, (224, 224))
    '''crop data: we add a small margin to the images'''
    landmark_arr_xy, landmark_arr_x, landmark_arr_y = image_utility.create_landmarks(landmarks=points_arr,
                                                                                    scale_factor_x=1,
                                                                                    scale_factor_y=1)

    '''augment the images, then normalize the landmarks based on the hyperface method'''
    for k in range(IbugConf.augmentation_factor):
        '''save the origin image as well'''
        #print(k)
        if k == 0:
            landmark_arr_flat_aug = landmark_arr_xy
            img_aug = resized_img

        else:
            '''save the augmented images'''
            if k % 2 == 0:
                #print(np.shape(resized_img))
                landmark_arr_flat_aug, img_aug = image_utility.random_augmentation(landmark_arr_xy, resized_img)