|
15 | 15 | flatten_image, |
16 | 16 | get_dtype_info, |
17 | 17 | get_valid_dtypes, |
| 18 | + is_grayscale_image, |
18 | 19 | is_image_stack, |
19 | 20 | merge_images, |
20 | 21 | preprocess_img_stk, |
@@ -751,6 +752,57 @@ def gaussian_2d( |
751 | 752 | ) |
752 | 753 |
|
753 | 754 |
|
| 755 | +is_grayscale_image_test_matrix = ( |
| 756 | + # Shape | Result |
| 757 | + # These should pass |
| 758 | + ((64, 64), True), |
| 759 | + ((1, 64, 64), True), |
| 760 | + ((5, 64, 64), True), |
| 761 | + # These should fail without erroring |
| 762 | + ((64, 64, 3), False), |
| 763 | + ((64, 64, 4), False), |
| 764 | + ((1, 64, 64, 3), False), |
| 765 | + ((5, 64, 64, 3), False), |
| 766 | + ((1, 64, 64, 4), False), |
| 767 | + ((5, 64, 64, 4), False), |
| 768 | +) |
| 769 | + |
| 770 | + |
| 771 | +@pytest.mark.parametrize("test_params", is_grayscale_image_test_matrix) |
| 772 | +def test_is_grayscale_image(test_params: tuple[tuple[int, ...], bool]): |
| 773 | + # Unpack test params |
| 774 | + shape, result = test_params |
| 775 | + |
| 776 | + # Construct array |
| 777 | + array = np.zeros(shape) |
| 778 | + |
| 779 | + # Check that the result is as expected |
| 780 | + assert is_grayscale_image(array) is result |
| 781 | + |
| 782 | + |
| 783 | +is_grayscale_image_error_cases = ( |
| 784 | + # Shape |
| 785 | + # These should all error |
| 786 | + ((64,),), |
| 787 | + ((5, 5, 64, 64),), |
| 788 | + ((5, 64, 64, 5),), |
| 789 | + ((5, 5, 5, 64, 64),), |
| 790 | + ((5, 5, 64, 64, 5),), |
| 791 | +) |
| 792 | + |
| 793 | + |
| 794 | +@pytest.mark.parametrize("test_params", is_grayscale_image_error_cases) |
| 795 | +def test_is_grayscale_image_errors(test_params: tuple[tuple[int, ...]]): |
| 796 | + # Unpack test params |
| 797 | + (shape,) = test_params |
| 798 | + |
| 799 | + # Create array |
| 800 | + array = np.zeros(shape) |
| 801 | + |
| 802 | + with pytest.raises(ValueError): |
| 803 | + is_grayscale_image(array) |
| 804 | + |
| 805 | + |
754 | 806 | image_coloring_test_matrix = ( |
755 | 807 | # Colour | dtype | frames |
756 | 808 | # 0 |
|
0 commit comments