def test_sat_value_distribution(self): file_photo = os.path.join(DATA_PATH, "base_dataset/photo") file_photo = os.path.join(file_photo, "funny-game-of-thrones-memes-fb__700.jpg") im_photo = load_image_as_array(file_photo) print(im_photo.shape) file_paint = os.path.join(DATA_PATH, "base_dataset/painting") file_paint = os.path.join(file_paint, "5d646e19b30e1.jpeg") im_paint = load_image_as_array(file_paint) print(im_paint.shape) spatial_variance = HsvAnalyser() features_photo = spatial_variance.sat_value_distribution(im_photo) features_paint = spatial_variance.sat_value_distribution(im_paint) x = np.arange(len(features_photo)) # the label locations width = 0.35 # the width of the bars fig, ax = plt.subplots(1, 1, figsize=(15, 5)) ax.bar(x - width / 2, features_photo, width, label='photo') ax.bar(x + width / 2, features_paint, width, label='painting') fig.legend() plt.show() # Histograms have a very high not saturated pixels. # It is probably cased by white and black background and text in memes. self.assertTrue(True)
def test_norm_color_count(self): file_photo = os.path.join(DATA_PATH, "photo") file_photo = os.path.join(file_photo, "funny-game-of-thrones-memes-fb__700.jpg") im_photo = load_image_as_array(file_photo) # print(im_photo.shape) file_paint = os.path.join(DATA_PATH, "text") file_paint = os.path.join(file_paint, "FB_IMG_1482177388795.jpg") im_paint = load_image_as_array(file_paint) # print(im_paint.shape) file_cartoon = os.path.join(DATA_PATH, "cartoon") file_cartoon = os.path.join(file_cartoon, "cartoon_1.jpg") im_cartoon = load_image_as_array(file_cartoon) color_counter = ColorCounter() features_photo = color_counter.norm_color_count(im_photo) features_paint = color_counter.norm_color_count(im_paint) features_cartoon = color_counter.norm_color_count(im_cartoon) print(features_paint) print(features_cartoon, '\n') diff_painting = features_photo - features_paint diff_cartoon = features_photo - features_cartoon print(diff_painting) self.assertGreater(0, diff_painting) print(diff_cartoon) self.assertGreater(diff_cartoon, 0)
def test_angle_cos_var(self): file_path = os.path.join(DATA_PATH, "photo") file_path = os.path.join(file_path, "funny-game-of-thrones-memes-fb__700.jpg") im = load_image_as_array(file_path) print(im.shape) spatial_variance = HsvAnalyser() features = spatial_variance.hsv_var(im, (5, 5)) expected = np.array([8.20562953e-04, 4.93038066e-32, 2.67054637e-09, 1.96633129e-07, 9.88124716e-07, 6.82860813e-05, 1.10551960e-02, 0.00000000e+00, 1.71209412e-05, 1.81389472e-04, 1.07205008e-03, 3.37056916e-02, 2.28070797e-02, 2.46059208e-06, 8.48904268e-05, 5.61654748e-04, 5.68519800e-03, 1.17176111e-01]) print(np.mean(features - expected)) self.assertEqual(str(features), str(expected))
def test_grayscale_edges_factor(self): file_photo = os.path.join( DATA_PATH, "base_dataset/photo/pics/pexels-photo-2873992.jpeg") im_photo = load_image_as_array(file_photo) print(im_photo.shape) file_paint = os.path.join( DATA_PATH, "base_dataset/painting/pics/5d5781fd76e1b3f6ece694f7f421b9a5.jpg") im_paint = load_image_as_array(file_paint) print(im_paint.shape) edges_detector = EdgesDetector() features_photo = edges_detector.grayscale_edges_factor(im_photo) features_paint = edges_detector.grayscale_edges_factor(im_paint) print(features_photo.shape) print(features_paint.shape) diff = np.mean(features_photo - features_paint) print(diff) self.assertGreater(diff, 0)
def test_load_image_as_array(self): path_to_dir = os.path.join(DATA_PATH, "photo") files = os.listdir(path_to_dir) file_path = os.path.join(path_to_dir, files[0]) im = load_image_as_array(file_path) self.assertEqual(type(im), np.ndarray)