def test_suppress_edges_true(self, mock_seb): image = np.arange(4*4*3).astype(np.uint8).reshape((4, 4, 3)) mock_seb.return_value = np.copy(image[..., 0]) _ = iaa.stylize_cartoon(image, suppress_edges=True) assert mock_seb.call_count == 2
def test_large_image(self, mock_fel): def _side_effect_fel(image, edge_multiplier, from_colorspace): return image[..., 0] mock_fel.side_effect = _side_effect_fel image = np.zeros((10, 401, 3), dtype=np.uint8) _ = iaa.stylize_cartoon(image, segmentation_size=0) assert mock_fel.call_count == 1
def test_segmentation_size_is_0(self, mock_msf): def _side_effect(image, sp, sr, dst): dst[...] = image mock_msf.side_effect = _side_effect image = np.arange(4*4*3).astype(np.uint8).reshape((4, 4, 3)) _ = iaa.stylize_cartoon(image, segmentation_size=0.0) assert mock_msf.call_count == 0
def test_blur_ksize_gt_1(self, mock_blur): def _side_effect(image, ksize): return image mock_blur.side_effect = _side_effect image = np.arange(4*4*3).astype(np.uint8).reshape((4, 4, 3)) _ = iaa.stylize_cartoon(image, blur_ksize=7) assert mock_blur.call_count == 1 assert mock_blur.call_args_list[0][0][1] == 7
def test_blur_ksize_is_1(self, mock_blur): def _side_effect(image, ksize): return image mock_blur.side_effect = _side_effect image = np.arange(4*4*3).astype(np.uint8).reshape((4, 4, 3)) _ = iaa.stylize_cartoon(image, blur_ksize=1) # median blur is called another time in _find_edge_laplacian, but # that function is only called if the image is larger assert mock_blur.call_count == 0
def test_segmentation_size_gt_0(self, mock_msf): def _side_effect(image, sp, sr, dst): dst[...] = image mock_msf.side_effect = _side_effect image = np.arange(4*4*3).astype(np.uint8).reshape((4, 4, 3)) _ = iaa.stylize_cartoon(image, segmentation_size=0.5) assert mock_msf.call_count == 1 assert np.allclose(mock_msf.call_args_list[0][1]["sp"], 10*0.5) assert np.allclose(mock_msf.call_args_list[0][1]["sr"], 20*0.5)
def _test_integrationtest(cls, size, validate_grads): image = ia.quokka_square((size, size)) image_cartoon = iaa.stylize_cartoon(image, blur_ksize=5, segmentation_size=2.0) image_avg = np.average(image.astype(np.float32), axis=2) image_cartoon_avg = np.average(image_cartoon.astype(np.float32), axis=2) if validate_grads: gradx_image = image_avg[:, :-1] - image_avg[:, 1:] grady_image = image_avg[:-1, :] - image_avg[1:, :] gradx_cartoon = image_cartoon_avg[:, :-1] - image_cartoon_avg[:, 1:] grady_cartoon = image_cartoon_avg[:-1, :] - image_cartoon_avg[1:, :] assert ( ( np.average(np.abs(gradx_cartoon)) + np.average(np.abs(grady_cartoon)) ) < ( np.average(np.abs(gradx_image)) + np.average(np.abs(grady_image)) ) ) # average saturation of cartoon image should be increased image_hsv = colorlib.change_colorspace_(np.copy(image), to_colorspace=iaa.CSPACE_HSV) cartoon_hsv = colorlib.change_colorspace_(np.copy(image_cartoon), to_colorspace=iaa.CSPACE_HSV) assert ( np.average(cartoon_hsv[:, :, 1]) > np.average(image_hsv[:, :, 1]) ) # as edges are all drawn in completely black, there should be more # completely black pixels in the cartoon image image_black = np.sum(image_avg <= 0.01) cartoon_black = np.sum(image_cartoon_avg <= 0.01) assert cartoon_black > image_black
def test_suppress_edges_false(self, mock_seb): image = np.arange(4*4*3).astype(np.uint8).reshape((4, 4, 3)) _ = iaa.stylize_cartoon(image, suppress_edges=False) assert mock_seb.call_count == 0