@@ -5005,6 +5005,54 @@ def test_random_transform_correctness(self, num_input_channels):
5005
5005
assert_equal (actual , expected , rtol = 0 , atol = 1 )
5006
5006
5007
5007
5008
+ class TestGrayscaleToRgb :
5009
+ @pytest .mark .parametrize ("dtype" , [torch .uint8 , torch .float32 ])
5010
+ @pytest .mark .parametrize ("device" , cpu_and_cuda ())
5011
+ def test_kernel_image (self , dtype , device ):
5012
+ check_kernel (F .grayscale_to_rgb_image , make_image (dtype = dtype , device = device ))
5013
+
5014
+ @pytest .mark .parametrize ("make_input" , [make_image_tensor , make_image_pil , make_image ])
5015
+ def test_functional (self , make_input ):
5016
+ check_functional (F .grayscale_to_rgb , make_input ())
5017
+
5018
+ @pytest .mark .parametrize (
5019
+ ("kernel" , "input_type" ),
5020
+ [
5021
+ (F .rgb_to_grayscale_image , torch .Tensor ),
5022
+ (F ._rgb_to_grayscale_image_pil , PIL .Image .Image ),
5023
+ (F .rgb_to_grayscale_image , tv_tensors .Image ),
5024
+ ],
5025
+ )
5026
+ def test_functional_signature (self , kernel , input_type ):
5027
+ check_functional_kernel_signature_match (F .grayscale_to_rgb , kernel = kernel , input_type = input_type )
5028
+
5029
+ @pytest .mark .parametrize ("make_input" , [make_image_tensor , make_image_pil , make_image ])
5030
+ def test_transform (self , make_input ):
5031
+ check_transform (transforms .RGB (), make_input (color_space = "GRAY" ))
5032
+
5033
+ @pytest .mark .parametrize ("fn" , [F .grayscale_to_rgb , transform_cls_to_functional (transforms .RGB )])
5034
+ def test_image_correctness (self , fn ):
5035
+ image = make_image (dtype = torch .uint8 , device = "cpu" , color_space = "GRAY" )
5036
+
5037
+ actual = fn (image )
5038
+ expected = F .to_image (F .grayscale_to_rgb (F .to_pil_image (image )))
5039
+
5040
+ assert_equal (actual , expected , rtol = 0 , atol = 1 )
5041
+
5042
+ def test_expanded_channels_are_not_views_into_the_same_underlying_tensor (self ):
5043
+ image = make_image (dtype = torch .uint8 , device = "cpu" , color_space = "GRAY" )
5044
+
5045
+ output_image = F .grayscale_to_rgb (image )
5046
+ assert_equal (output_image [0 ][0 ][0 ], output_image [1 ][0 ][0 ])
5047
+ output_image [0 ][0 ][0 ] = output_image [0 ][0 ][0 ] + 1
5048
+ assert output_image [0 ][0 ][0 ] != output_image [1 ][0 ][0 ]
5049
+
5050
+ def test_rgb_image_is_unchanged (self ):
5051
+ image = make_image (dtype = torch .uint8 , device = "cpu" , color_space = "RGB" )
5052
+ assert_equal (image .shape [- 3 ], 3 )
5053
+ assert_equal (F .grayscale_to_rgb (image ), image )
5054
+
5055
+
5008
5056
class TestRandomZoomOut :
5009
5057
# Tests are light because this largely relies on the already tested `pad` kernels.
5010
5058
0 commit comments