@@ -16,6 +16,8 @@ class RandomBackgroundLines(A.DualTransform):
1616 @param line_thickness: Range of line thickness. Defaults to (10, 50).
1717 @type line_length: tuple
1818 @param line_length: Range of line lengths as a fraction of the diagonal of the image. Defaults to (0.1, 0.5).
19+ @type gray_range: tuple
20+ @param gray_range: Range of grayscale values for the line color (0=black, 255=white). Defaults to (0, 80).
1921 @type p: float
2022 @param p: Probability of applying the transform. Defaults to 0.5.
2123 """
@@ -25,12 +27,14 @@ def __init__(
2527 num_lines : tuple = (3 , 10 ),
2628 line_thickness : tuple = (10 , 50 ),
2729 line_length : tuple = (0.1 , 0.5 ),
30+ gray_range : tuple = (0 , 127 ),
2831 p : float = 0.5 ,
2932 ):
3033 super ().__init__ (p = p )
3134 self .num_lines = num_lines
3235 self .line_thickness = line_thickness
3336 self .line_length = line_length
37+ self .gray_range = gray_range
3438
3539 @override
3640 def get_params_dependent_on_data (
@@ -138,8 +142,22 @@ def apply(
138142 if np .any (np .logical_and (line_mask > 0 , foreground_mask )):
139143 continue
140144
141- color = (0 , 0 , 0 )
145+ gray_value = random .randint (
146+ self .gray_range [0 ], self .gray_range [1 ]
147+ )
148+ color = (gray_value , gray_value , gray_value )
142149 cv2 .line (result , (x1 , y1 ), (x2 , y2 ), color , thickness )
143150 break
144151
145152 return result
153+
154+ @override
155+ def apply_to_mask (self , mask : np .ndarray , ** params ) -> np .ndarray :
156+ """Keep the mask unchanged during augmentation.
157+
158+ @type mask: np.ndarray
159+ @param mask: The input segmentation mask.
160+ @return: The unmodified mask.
161+ @rtype: np.ndarray
162+ """
163+ return mask
0 commit comments