signature:
def extract_from_image ( self , image , size = 1 , pad = True , pad_max = None , antialiased = True , prevent_zero_size = True ) :
    """Extract the image pixels covered by the line string .
 It will only extract pixels overlapped by the line string .
 This function will by default zero - pad the image if the line string is
 partially / fully outside of the image . This is for consistency with
 the same implementations for bounding boxes and polygons .
 Parameters
 image : ndarray
 The image of shape ` ( H , W , [ C ] ) ` from which to extract the pixels
 within the line string .
 size : int , optional
 Thickness of the line .
 pad : bool , optional
 Whether to zero - pad the image if the object is partially / fully
 outside of it .
 pad _ max : None or int , optional
 The maximum number of pixels that may be zero - paded on any side ,
 i . e . if this has value ` ` N ` ` the total maximum of added pixels
 is ` ` 4 * N ` ` .
 This option exists to prevent extremely large images as a result of
 single points being moved very far away during augmentation .
 antialiased : bool , optional
 Whether to apply anti - aliasing to the line string .
 prevent _ zero _ size : bool , optional
 Whether to prevent height or width of the extracted image from
 becoming zero . If this is set to True and height or width of the
 line string is below 1 , the height / width will be increased to 1.
 This can be useful to prevent problems , e . g . with image saving or
 plotting . If it is set to False , images will be returned as
 ` ` ( H ' , W ' ) ` ` or ` ` ( H ' , W ' , 3 ) ` ` with ` ` H ` ` or ` ` W ` ` potentially
 being 0.
 Returns
 image : ( H ' , W ' ) ndarray or ( H ' , W ' , C ) ndarray
 Pixels overlapping with the line string . Zero - padded if the
 line string is partially / fully outside of the image and
 ` ` pad = True ` ` . If ` prevent _ zero _ size ` is activated , it is
 guarantueed that ` ` H ' > 0 ` ` and ` ` W ' > 0 ` ` , otherwise only
 ` ` H ' > = 0 ` ` and ` ` W ' > = 0 ` ` ."""

implementation:
from . bbs import BoundingBox
assert image . ndim in [ 2 , 3 ] , ( "Expected image of shape (H,W,[C]), " "got shape %s." % ( image . shape , ) )
if len ( self . coords ) == 0 or size <= 0 :
    if prevent_zero_size :
        return np . zeros ( ( 1 , 1 ) + image . shape [ 2 : ] , dtype = image . dtype )
    return np . zeros ( ( 0 , 0 ) + image . shape [ 2 : ] , dtype = image . dtype )
xx = self . xx_int
yy = self . yy_int
# this would probably work if drawing was subpixel - accurate
# x1 = np . min ( self . coords [ : , 0 ] ) - ( size / 2)
# y1 = np . min ( self . coords [ : , 1 ] ) - ( size / 2)
# x2 = np . max ( self . coords [ : , 0 ] ) + ( size / 2)
# y2 = np . max ( self . coords [ : , 1 ] ) + ( size / 2)
# this works currently with non - subpixel - accurate drawing
sizeh = ( size - 1 ) / 2
x1 = np . min ( xx ) - sizeh
y1 = np . min ( yy ) - sizeh
x2 = np . max ( xx ) + 1 + sizeh
y2 = np . max ( yy ) + 1 + sizeh
bb = BoundingBox ( x1 = x1 , y1 = y1 , x2 = x2 , y2 = y2 )
if len ( self . coords ) == 1 :
    return bb . extract_from_image ( image , pad = pad , pad_max = pad_max , prevent_zero_size = prevent_zero_size )
heatmap = self . draw_lines_heatmap_array ( image . shape [ 0 : 2 ] , alpha = 1.0 , size = size , antialiased = antialiased )
if image . ndim == 3 :
    heatmap = np . atleast_3d ( heatmap )
image_masked = image . astype ( np . float32 ) * heatmap
extract = bb . extract_from_image ( image_masked , pad = pad , pad_max = pad_max , prevent_zero_size = prevent_zero_size )
return np . clip ( np . round ( extract ) , 0 , 255 ) . astype ( np . uint8 )


signature:
def concatenate ( self , other ) :
    """Concatenate this line string with another one .
 This will add a line segment between the end point of this line string
 and the start point of ` other ` .
 Parameters
 other : imgaug . augmentables . lines . LineString or ndarray or iterable of tuple of number
 The points to add to this line string .
 Returns
 imgaug . augmentables . lines . LineString
 New line string with concatenated points .
 The ` label ` of this line string will be kept ."""

implementation:
if not isinstance ( other , LineString ) :
    other = LineString ( other )
return self . deepcopy ( coords = np . concatenate ( [ self . coords , other . coords ] , axis = 0 ) )


signature:
def subdivide ( self , points_per_edge ) :
    """Adds ` ` N ` ` interpolated points with uniform spacing to each edge .
 For each edge between points ` ` A ` ` and ` ` B ` ` this adds points
 at ` ` A + ( i / ( 1 + N ) ) * ( B - A ) ` ` , where ` ` i ` ` is the index of the added
 point and ` ` N ` ` is the number of points to add per edge .
 Calling this method two times will split each edge at its center
 and then again split each newly created edge at their center .
 It is equivalent to calling ` subdivide ( 3 ) ` .
 Parameters
 points _ per _ edge : int
 Number of points to interpolate on each edge .
 Returns
 LineString
 Line string with subdivided edges ."""

implementation:
if len ( self . coords ) <= 1 or points_per_edge < 1 :
    return self . deepcopy ( )
coords = interpolate_points ( self . coords , nb_steps = points_per_edge , closed = False )
return self . deepcopy ( coords = coords )


signature:
def to_keypoints ( self ) :
    """Convert the line string points to keypoints .
 Returns
 list of imgaug . augmentables . kps . Keypoint
 Points of the line string as keypoints ."""

implementation:
# TODO get rid of this deferred import
from imgaug . augmentables . kps import Keypoint
return [ Keypoint ( x = x , y = y ) for ( x , y ) in self . coords ]


signature:
def to_bounding_box ( self ) :
    """Generate a bounding box encapsulating the line string .
 Returns
 None or imgaug . augmentables . bbs . BoundingBox
 Bounding box encapsulating the line string .
 ` ` None ` ` if the line string contained no points ."""

implementation:
from . bbs import BoundingBox
# we don ' t have to mind the case of len ( . ) = = 1 here , because
# zero - sized BBs are considered valid
if len ( self . coords ) == 0 :
    return None
return BoundingBox ( x1 = np . min ( self . xx ) , y1 = np . min ( self . yy ) , x2 = np . max ( self . xx ) , y2 = np . max ( self . yy ) , label = self . label )


signature:
def to_polygon ( self ) :
    """Generate a polygon from the line string points .
 Returns
 imgaug . augmentables . polys . Polygon
 Polygon with the same corner points as the line string .
 Note that the polygon might be invalid , e . g . contain less than 3
 points or have self - intersections ."""

implementation:
from . polys import Polygon
return Polygon ( self . coords , label = self . label )


signature:
def to_heatmap ( self , image_shape , size_lines = 1 , size_points = 0 , antialiased = True , raise_if_out_of_image = False ) :
    """Generate a heatmap object from the line string .
 This is similar to
 : func : ` imgaug . augmentables . lines . LineString . draw _ lines _ heatmap _ array `
 executed with ` ` alpha = 1.0 ` ` . The result is wrapped in a
 ` ` HeatmapsOnImage ` ` object instead of just an array .
 No points are drawn .
 Parameters
 image _ shape : tuple of int
 The shape of the image onto which to draw the line mask .
 size _ lines : int , optional
 Thickness of the line .
 size _ points : int , optional
 Size of the points in pixels .
 antialiased : bool , optional
 Whether to draw the line with anti - aliasing activated .
 raise _ if _ out _ of _ image : bool , optional
 Whether to raise an error if the line string is fully
 outside of the image . If set to False , no error will be raised and
 only the parts inside the image will be drawn .
 Returns
 imgaug . augmentables . heatmaps . HeatmapOnImage
 Heatmap object containing drawn line string ."""

implementation:
from . heatmaps import HeatmapsOnImage
return HeatmapsOnImage ( self . draw_heatmap_array ( image_shape , size_lines = size_lines , size_points = size_points , antialiased = antialiased , raise_if_out_of_image = raise_if_out_of_image ) , shape = image_shape )


signature:
def to_segmentation_map ( self , image_shape , size_lines = 1 , size_points = 0 , raise_if_out_of_image = False ) :
    """Generate a segmentation map object from the line string .
 This is similar to
 : func : ` imgaug . augmentables . lines . LineString . draw _ mask ` .
 The result is wrapped in a ` ` SegmentationMapOnImage ` ` object
 instead of just an array .
 Parameters
 image _ shape : tuple of int
 The shape of the image onto which to draw the line mask .
 size _ lines : int , optional
 Thickness of the line .
 size _ points : int , optional
 Size of the points in pixels .
 raise _ if _ out _ of _ image : bool , optional
 Whether to raise an error if the line string is fully
 outside of the image . If set to False , no error will be raised and
 only the parts inside the image will be drawn .
 Returns
 imgaug . augmentables . segmaps . SegmentationMapOnImage
 Segmentation map object containing drawn line string ."""

implementation:
from . segmaps import SegmentationMapOnImage
return SegmentationMapOnImage ( self . draw_mask ( image_shape , size_lines = size_lines , size_points = size_points , raise_if_out_of_image = raise_if_out_of_image ) , shape = image_shape )


signature:
def coords_almost_equals ( self , other , max_distance = 1e-6 , points_per_edge = 8 ) :
    """Compare this and another LineString ' s coordinates .
 This is an approximate method based on pointwise distances and can
 in rare corner cases produce wrong outputs .
 Parameters
 other : imgaug . augmentables . lines . LineString or tuple of number or ndarray or list of ndarray or list of tuple of number
 The other line string or its coordinates .
 max _ distance : float
 Max distance of any point from the other line string before
 the two line strings are evaluated to be unequal .
 points _ per _ edge : int , optional
 How many points to interpolate on each edge .
 Returns
 bool
 Whether the two LineString ' s coordinates are almost identical ,
 i . e . the max distance is below the threshold .
 If both have no coordinates , ` ` True ` ` is returned .
 If only one has no coordinates , ` ` False ` ` is returned .
 Beyond that , the number of points is not evaluated ."""

implementation:
if isinstance ( other , LineString ) :
    pass
elif isinstance ( other , tuple ) :
    other = LineString ( [ other ] )
else :
    other = LineString ( other )
if len ( self . coords ) == 0 and len ( other . coords ) == 0 :
    return True
elif 0 in [ len ( self . coords ) , len ( other . coords ) ] : # only one of the two line strings has no coords
    return False
self_subd = self . subdivide ( points_per_edge )
other_subd = other . subdivide ( points_per_edge )
dist_self2other = self_subd . compute_pointwise_distances ( other_subd )
dist_other2self = other_subd . compute_pointwise_distances ( self_subd )
dist = max ( np . max ( dist_self2other ) , np . max ( dist_other2self ) )
return dist < max_distance


signature:
def almost_equals ( self , other , max_distance = 1e-4 , points_per_edge = 8 ) :
    """Compare this and another LineString .
 Parameters
 other : imgaug . augmentables . lines . LineString
 The other line string . Must be a LineString instance , not just
 its coordinates .
 max _ distance : float , optional
 See : func : ` imgaug . augmentables . lines . LineString . coords _ almost _ equals ` .
 points _ per _ edge : int , optional
 See : func : ` imgaug . augmentables . lines . LineString . coords _ almost _ equals ` .
 Returns
 bool
 ` ` True ` ` if the coordinates are almost equal according to
 : func : ` imgaug . augmentables . lines . LineString . coords _ almost _ equals `
 and additionally the labels are identical . Otherwise ` ` False ` ` ."""

implementation:
if self . label != other . label :
    return False
return self . coords_almost_equals ( other , max_distance = max_distance , points_per_edge = points_per_edge )


signature:
def copy ( self , coords = None , label = None ) :
    """Create a shallow copy of the LineString object .
 Parameters
 coords : None or iterable of tuple of number or ndarray
 If not ` ` None ` ` , then the coords of the copied object will be set
 to this value .
 label : None or str
 If not ` ` None ` ` , then the label of the copied object will be set to
 this value .
 Returns
 imgaug . augmentables . lines . LineString
 Shallow copy ."""

implementation: return LineString ( coords = self . coords if coords is None else coords , label = self . label if label is None else label )


signature:
def deepcopy ( self , coords = None , label = None ) :
    """Create a deep copy of the BoundingBox object .
 Parameters
 coords : None or iterable of tuple of number or ndarray
 If not ` ` None ` ` , then the coords of the copied object will be set
 to this value .
 label : None or str
 If not ` ` None ` ` , then the label of the copied object will be set to
 this value .
 Returns
 imgaug . augmentables . lines . LineString
 Deep copy ."""

implementation: return LineString ( coords = np . copy ( self . coords ) if coords is None else coords , label = copylib . deepcopy ( self . label ) if label is None else label )


signature:
def on ( self , image ) :
    """Project bounding boxes from one image to a new one .
 Parameters
 image : ndarray or tuple of int
 The new image onto which to project .
 Either an image with shape ` ` ( H , W , [ C ] ) ` ` or a tuple denoting
 such an image shape .
 Returns
 line _ strings : imgaug . augmentables . lines . LineStrings
 Object containing all projected line strings ."""

implementation:
shape = normalize_shape ( image )
if shape [ 0 : 2 ] == self . shape [ 0 : 2 ] :
    return self . deepcopy ( )
line_strings = [ ls . project ( self . shape , shape ) for ls in self . line_strings ]
return self . deepcopy ( line_strings = line_strings , shape = shape )


signature:
def from_xy_arrays ( cls , xy , shape ) :
    """Convert an ` ( N , M , 2 ) ` ndarray to a LineStringsOnImage object .
 This is the inverse of
 : func : ` imgaug . augmentables . lines . LineStringsOnImage . to _ xy _ array ` .
 Parameters
 xy : ( N , M , 2 ) ndarray or iterable of ( M , 2 ) ndarray
 Array containing the point coordinates ` ` N ` ` line strings
 with each ` ` M ` ` points given as ` ` ( x , y ) ` ` coordinates .
 ` ` M ` ` may differ if an iterable of arrays is used .
 Each array should usually be of dtype ` ` float32 ` ` .
 shape : tuple of int
 ` ` ( H , W , [ C ] ) ` ` shape of the image on which the line strings are
 placed .
 Returns
 imgaug . augmentables . lines . LineStringsOnImage
 Object containing a list of ` ` LineString ` ` objects following the
 provided point coordinates ."""

implementation:
lss = [ ]
for xy_ls in xy :
    lss . append ( LineString ( xy_ls ) )
return cls ( lss , shape )


signature:
def to_xy_arrays ( self , dtype = np . float32 ) :
    """Convert this object to an iterable of ` ` ( M , 2 ) ` ` arrays of points .
 This is the inverse of
 : func : ` imgaug . augmentables . lines . LineStringsOnImage . from _ xy _ array ` .
 Parameters
 dtype : numpy . dtype , optional
 Desired output datatype of the ndarray .
 Returns
 list of ndarray
 The arrays of point coordinates , each given as ` ` ( M , 2 ) ` ` ."""

implementation:
from . . import dtypes as iadt
return [ iadt . restore_dtypes_ ( np . copy ( ls . coords ) , dtype ) for ls in self . line_strings ]


signature:
def draw_on_image ( self , image , color = ( 0 , 255 , 0 ) , color_lines = None , color_points = None , alpha = 1.0 , alpha_lines = None , alpha_points = None , size = 1 , size_lines = None , size_points = None , antialiased = True , raise_if_out_of_image = False ) :
    """Draw all line strings onto a given image .
 Parameters
 image : ndarray
 The ` ( H , W , C ) ` ` uint8 ` image onto which to draw the line strings .
 color : iterable of int , optional
 Color to use as RGB , i . e . three values .
 The color of the lines and points are derived from this value ,
 unless they are set .
 color _ lines : None or iterable of int
 Color to use for the line segments as RGB , i . e . three values .
 If ` ` None ` ` , this value is derived from ` color ` .
 color _ points : None or iterable of int
 Color to use for the points as RGB , i . e . three values .
 If ` ` None ` ` , this value is derived from ` ` 0.5 * color ` ` .
 alpha : float , optional
 Opacity of the line strings . Higher values denote more visible
 points .
 The alphas of the line and points are derived from this value ,
 unless they are set .
 alpha _ lines : None or float , optional
 Opacity of the line strings . Higher values denote more visible
 line string .
 If ` ` None ` ` , this value is derived from ` alpha ` .
 alpha _ points : None or float , optional
 Opacity of the line string points . Higher values denote more
 visible points .
 If ` ` None ` ` , this value is derived from ` alpha ` .
 size : int , optional
 Size of the line strings .
 The sizes of the line and points are derived from this value ,
 unless they are set .
 size _ lines : None or int , optional
 Thickness of the line segments .
 If ` ` None ` ` , this value is derived from ` size ` .
 size _ points : None or int , optional
 Size of the points in pixels .
 If ` ` None ` ` , this value is derived from ` ` 3 * size ` ` .
 antialiased : bool , optional
 Whether to draw the lines with anti - aliasing activated .
 This does currently not affect the point drawing .
 raise _ if _ out _ of _ image : bool , optional
 Whether to raise an error if a line string is fully
 outside of the image . If set to False , no error will be raised and
 only the parts inside the image will be drawn .
 Returns
 ndarray
 Image with line strings drawn on it ."""

implementation:
# TODO improve efficiency here by copying only once
for ls in self . line_strings :
    image = ls . draw_on_image ( image , color = color , color_lines = color_lines , color_points = color_points , alpha = alpha , alpha_lines = alpha_lines , alpha_points = alpha_points , size = size , size_lines = size_lines , size_points = size_points , antialiased = antialiased , raise_if_out_of_image = raise_if_out_of_image )
return image


signature:
def remove_out_of_image ( self , fully = True , partly = False ) :
    """Remove all line strings that are fully / partially outside of the image .
 Parameters
 fully : bool , optional
 Whether to remove line strings that are fully outside of the image .
 partly : bool , optional
 Whether to remove line strings that are partially outside of the
 image .
 Returns
 imgaug . augmentables . lines . LineStringsOnImage
 Reduced set of line strings , with those that were fully / partially
 outside of the image removed ."""

implementation:
lss_clean = [ ls for ls in self . line_strings if not ls . is_out_of_image ( self . shape , fully = fully , partly = partly ) ]
return LineStringsOnImage ( lss_clean , shape = self . shape )


signature:
def clip_out_of_image ( self ) :
    """Clip off all parts of the line strings that are outside of the image .
 Returns
 imgaug . augmentables . lines . LineStringsOnImage
 Line strings , clipped to fall within the image dimensions ."""

implementation:
lss_cut = [ ls_clipped for ls in self . line_strings for ls_clipped in ls . clip_out_of_image ( self . shape ) ]
return LineStringsOnImage ( lss_cut , shape = self . shape )


signature:
def shift ( self , top = None , right = None , bottom = None , left = None ) :
    """Shift / move the line strings from one or more image sides .
 Parameters
 top : None or int , optional
 Amount of pixels by which to shift all bounding boxes from the
 top .
 right : None or int , optional
 Amount of pixels by which to shift all bounding boxes from the
 right .
 bottom : None or int , optional
 Amount of pixels by which to shift all bounding boxes from the
 bottom .
 left : None or int , optional
 Amount of pixels by which to shift all bounding boxes from the
 left .
 Returns
 imgaug . augmentables . lines . LineStringsOnImage
 Shifted line strings ."""

implementation:
lss_new = [ ls . shift ( top = top , right = right , bottom = bottom , left = left ) for ls in self . line_strings ]
return LineStringsOnImage ( lss_new , shape = self . shape )


signature:
def copy ( self , line_strings = None , shape = None ) :
    """Create a shallow copy of the LineStringsOnImage object .
 Parameters
 line _ strings : None or list of imgaug . augmentables . lines . LineString , optional
 List of line strings on the image .
 If not ` ` None ` ` , then the ` ` line _ strings ` ` attribute of the copied
 object will be set to this value .
 shape : None or tuple of int or ndarray , optional
 The shape of the image on which the objects are placed .
 Either an image with shape ` ` ( H , W , [ C ] ) ` ` or a tuple denoting
 such an image shape .
 If not ` ` None ` ` , then the ` ` shape ` ` attribute of the copied object
 will be set to this value .
 Returns
 imgaug . augmentables . lines . LineStringsOnImage
 Shallow copy ."""

implementation:
lss = self . line_strings if line_strings is None else line_strings
shape = self . shape if shape is None else shape
return LineStringsOnImage ( line_strings = lss , shape = shape )


signature:
def deepcopy ( self , line_strings = None , shape = None ) :
    """Create a deep copy of the LineStringsOnImage object .
 Parameters
 line _ strings : None or list of imgaug . augmentables . lines . LineString , optional
 List of line strings on the image .
 If not ` ` None ` ` , then the ` ` line _ strings ` ` attribute of the copied
 object will be set to this value .
 shape : None or tuple of int or ndarray , optional
 The shape of the image on which the objects are placed .
 Either an image with shape ` ` ( H , W , [ C ] ) ` ` or a tuple denoting
 such an image shape .
 If not ` ` None ` ` , then the ` ` shape ` ` attribute of the copied object
 will be set to this value .
 Returns
 imgaug . augmentables . lines . LineStringsOnImage
 Deep copy ."""

implementation:
lss = self . line_strings if line_strings is None else line_strings
shape = self . shape if shape is None else shape
return LineStringsOnImage ( line_strings = [ ls . deepcopy ( ) for ls in lss ] , shape = tuple ( shape ) )


signature:
def blend_alpha ( image_fg , image_bg , alpha , eps = 1e-2 ) :
    """Blend two images using an alpha blending .
 In an alpha blending , the two images are naively mixed . Let ` ` A ` ` be the foreground image
 and ` ` B ` ` the background image and ` ` a ` ` is the alpha value . Each pixel intensity is then
 computed as ` ` a * A _ ij + ( 1 - a ) * B _ ij ` ` .
 dtype support : :
 * ` ` uint8 ` ` : yes ; fully tested
 * ` ` uint16 ` ` : yes ; fully tested
 * ` ` uint32 ` ` : yes ; fully tested
 * ` ` uint64 ` ` : yes ; fully tested ( 1)
 * ` ` int8 ` ` : yes ; fully tested
 * ` ` int16 ` ` : yes ; fully tested
 * ` ` int32 ` ` : yes ; fully tested
 * ` ` int64 ` ` : yes ; fully tested ( 1)
 * ` ` float16 ` ` : yes ; fully tested
 * ` ` float32 ` ` : yes ; fully tested
 * ` ` float64 ` ` : yes ; fully tested ( 1)
 * ` ` float128 ` ` : no ( 2)
 * ` ` bool ` ` : yes ; fully tested ( 2)
 - ( 1 ) Tests show that these dtypes work , but a conversion to float128 happens , which only
 has 96 bits of size instead of true 128 bits and hence not twice as much resolution .
 It is possible that these dtypes result in inaccuracies , though the tests did not
 indicate that .
 - ( 2 ) Not available due to the input dtype having to be increased to an equivalent float
 dtype with two times the input resolution .
 - ( 3 ) Mapped internally to ` ` float16 ` ` .
 Parameters
 image _ fg : ( H , W , [ C ] ) ndarray
 Foreground image . Shape and dtype kind must match the one of the
 background image .
 image _ bg : ( H , W , [ C ] ) ndarray
 Background image . Shape and dtype kind must match the one of the
 foreground image .
 alpha : number or iterable of number or ndarray
 The blending factor , between 0.0 and 1.0 . Can be interpreted as the opacity of the
 foreground image . Values around 1.0 result in only the foreground image being visible .
 Values around 0.0 result in only the background image being visible .
 Multiple alphas may be provided . In these cases , there must be exactly one alpha per
 channel in the foreground / background image . Alternatively , for ` ` ( H , W , C ) ` ` images ,
 either one ` ` ( H , W ) ` ` array or an ` ` ( H , W , C ) ` ` array of alphas may be provided ,
 denoting the elementwise alpha value .
 eps : number , optional
 Controls when an alpha is to be interpreted as exactly 1.0 or exactly 0.0 , resulting
 in only the foreground / background being visible and skipping the actual computation .
 Returns
 image _ blend : ( H , W , C ) ndarray
 Blend of foreground and background image ."""

implementation:
assert image_fg . shape == image_bg . shape
assert image_fg . dtype . kind == image_bg . dtype . kind
# TODO switch to gate _ dtypes ( )
assert image_fg . dtype . name not in [ "float128" ]
assert image_bg . dtype . name not in [ "float128" ]
# TODO add test for this
input_was_2d = ( len ( image_fg . shape ) == 2 )
if input_was_2d :
    image_fg = np . atleast_3d ( image_fg )
    image_bg = np . atleast_3d ( image_bg )
input_was_bool = False
if image_fg . dtype . kind == "b" :
    input_was_bool = True
    # use float32 instead of float16 here because it seems to be faster
    image_fg = image_fg . astype ( np . float32 )
    image_bg = image_bg . astype ( np . float32 )
alpha = np . array ( alpha , dtype = np . float64 )
if alpha . size == 1 :
    pass
else :
    if alpha . ndim == 2 :
        assert alpha . shape == image_fg . shape [ 0 : 2 ]
        alpha = alpha . reshape ( ( alpha . shape [ 0 ] , alpha . shape [ 1 ] , 1 ) )
    elif alpha . ndim == 3 :
        assert alpha . shape == image_fg . shape or alpha . shape == image_fg . shape [ 0 : 2 ] + ( 1 , )
    else :
        alpha = alpha . reshape ( ( 1 , 1 , - 1 ) )
    if alpha . shape [ 2 ] != image_fg . shape [ 2 ] :
        alpha = np . tile ( alpha , ( 1 , 1 , image_fg . shape [ 2 ] ) )
if not input_was_bool :
    if np . all ( alpha >= 1.0 - eps ) :
        return np . copy ( image_fg )
    elif np . all ( alpha <= eps ) :
        return np . copy ( image_bg )
# for efficiency reaons , only test one value of alpha here , even if alpha is much larger
assert 0 <= alpha . item ( 0 ) <= 1.0
dt_images = iadt . get_minimal_dtype ( [ image_fg , image_bg ] )
# doing this only for non - float images led to inaccuracies for large floats values
isize = dt_images . itemsize * 2
isize = max ( isize , 4 )
# at least 4 bytes ( = float32 ) , tends to be faster than float16
dt_blend = np . dtype ( "f%d" % ( isize , ) )
if alpha . dtype != dt_blend :
    alpha = alpha . astype ( dt_blend )
if image_fg . dtype != dt_blend :
    image_fg = image_fg . astype ( dt_blend )
if image_bg . dtype != dt_blend :
    image_bg = image_bg . astype ( dt_blend )
# the following is equivalent to
# image _ blend = alpha * image _ fg + ( 1 - alpha ) * image _ bg
# but supposedly faster
image_blend = image_bg + alpha * ( image_fg - image_bg )
if input_was_bool :
    image_blend = image_blend > 0.5
else : # skip clip , because alpha is expected to be in range [ 0.0 , 1.0 ] and both images must have same dtype
# dont skip round , because otherwise it is very unlikely to hit the image ' s max possible value
    image_blend = iadt . restore_dtypes_ ( image_blend , dt_images , clip = False , round = True )
if input_was_2d :
    return image_blend [ : , : , 0 ]
return image_blend


signature:
def SimplexNoiseAlpha ( first = None , second = None , per_channel = False , size_px_max = ( 2 , 16 ) , upscale_method = None , iterations = ( 1 , 3 ) , aggregation_method = "max" , sigmoid = True , sigmoid_thresh = None , name = None , deterministic = False , random_state = None ) :
    """Augmenter to alpha - blend two image sources using simplex noise alpha masks .
 The alpha masks are sampled using a simplex noise method , roughly creating
 connected blobs of 1s surrounded by 0s . If nearest neighbour upsampling
 is used , these blobs can be rectangular with sharp edges .
 dtype support : :
 See ` ` imgaug . augmenters . blend . AlphaElementwise ` ` .
 Parameters
 first : None or imgaug . augmenters . meta . Augmenter or iterable of imgaug . augmenters . meta . Augmenter , optional
 Augmenter ( s ) that make up the first of the two branches .
 * If None , then the input images will be reused as the output
 of the first branch .
 * If Augmenter , then that augmenter will be used as the branch .
 * If iterable of Augmenter , then that iterable will be converted
 into a Sequential and used as the augmenter .
 second : None or imgaug . augmenters . meta . Augmenter or iterable of imgaug . augmenters . meta . Augmenter , optional
 Augmenter ( s ) that make up the second of the two branches .
 * If None , then the input images will be reused as the output
 of the second branch .
 * If Augmenter , then that augmenter will be used as the branch .
 * If iterable of Augmenter , then that iterable will be converted
 into a Sequential and used as the augmenter .
 per _ channel : bool or float , optional
 Whether to use the same factor for all channels ( False )
 or to sample a new value for each channel ( True ) .
 If this value is a float ` ` p ` ` , then for ` ` p ` ` percent of all images
 ` per _ channel ` will be treated as True , otherwise as False .
 size _ px _ max : int or tuple of int or list of int or imgaug . parameters . StochasticParameter , optional
 The simplex noise is always generated in a low resolution environment .
 This parameter defines the maximum size of that environment ( in
 pixels ) . The environment is initialized at the same size as the input
 image and then downscaled , so that no side exceeds ` size _ px _ max `
 ( aspect ratio is kept ) .
 * If int , then that number will be used as the size for all
 iterations .
 * If tuple of two ints ` ` ( a , b ) ` ` , then a value will be sampled
 per iteration from the discrete range ` ` [ a . . b ] ` ` .
 * If a list of ints , then a value will be picked per iteration at
 random from that list .
 * If a StochasticParameter , then a value will be sampled from
 that parameter per iteration .
 upscale _ method : None or imgaug . ALL or str or list of str or imgaug . parameters . StochasticParameter , optional
 After generating the noise maps in low resolution environments , they
 have to be upscaled to the input image size . This parameter controls
 the upscaling method .
 * If None , then either ` ` nearest ` ` or ` ` linear ` ` or ` ` cubic ` ` is picked .
 Most weight is put on linear , followed by cubic .
 * If ia . ALL , then either ` ` nearest ` ` or ` ` linear ` ` or ` ` area ` ` or ` ` cubic ` `
 is picked per iteration ( all same probability ) .
 * If string , then that value will be used as the method ( must be
 ' nearest ' or ` ` linear ` ` or ` ` area ` ` or ` ` cubic ` ` ) .
 * If list of string , then a random value will be picked from that
 list per iteration .
 * If StochasticParameter , then a random value will be sampled
 from that parameter per iteration .
 iterations : int or tuple of int or list of int or imgaug . parameters . StochasticParameter , optional
 How often to repeat the simplex noise generation process per image .
 * If int , then that number will be used as the iterations for all
 images .
 * If tuple of two ints ` ` ( a , b ) ` ` , then a value will be sampled
 per image from the discrete range ` ` [ a . . b ] ` ` .
 * If a list of ints , then a value will be picked per image at
 random from that list .
 * If a StochasticParameter , then a value will be sampled from
 that parameter per image .
 aggregation _ method : imgaug . ALL or str or list of str or imgaug . parameters . StochasticParameter , optional
 The noise maps ( from each iteration ) are combined to one noise map
 using an aggregation process . This parameter defines the method used
 for that process . Valid methods are ` ` min ` ` , ` ` max ` ` or ` ` avg ` ` ,
 where ` ` min ` ` combines the noise maps by taking the ( elementwise ) minimum
 over all iteration ' s results , ` ` max ` ` the ( elementwise ) maximum and
 ` ` avg ` ` the ( elementwise ) average .
 * If imgaug . ALL , then a random value will be picked per image from the
 valid ones .
 * If a string , then that value will always be used as the method .
 * If a list of string , then a random value will be picked from
 that list per image .
 * If a StochasticParameter , then a random value will be sampled
 from that paramter per image .
 sigmoid : bool or number , optional
 Whether to apply a sigmoid function to the final noise maps , resulting
 in maps that have more extreme values ( close to 0.0 or 1.0 ) .
 * If bool , then a sigmoid will always ( True ) or never ( False ) be
 applied .
 * If a number ` ` p ` ` with ` ` 0 < = p < = 1 ` ` , then a sigmoid will be applied to
 ` ` p ` ` percent of all final noise maps .
 sigmoid _ thresh : None or number or tuple of number or imgaug . parameters . StochasticParameter , optional
 Threshold of the sigmoid , when applied . Thresholds above zero
 ( e . g . 5.0 ) will move the saddle point towards the right , leading to
 more values close to 0.0.
 * If None , then ` ` Normal ( 0 , 5.0 ) ` ` will be used .
 * If number , then that threshold will be used for all images .
 * If tuple of two numbers ` ` ( a , b ) ` ` , then a random value will
 be sampled per image from the range ` ` [ a , b ] ` ` .
 * If StochasticParameter , then a random value will be sampled from
 that parameter per image .
 name : None or str , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 deterministic : bool , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 random _ state : None or int or numpy . random . RandomState , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 Examples
 > > > aug = iaa . SimplexNoiseAlpha ( iaa . EdgeDetect ( 1.0 ) )
 Detects per image all edges , marks them in a black and white image and
 then alpha - blends the result with the original image using simplex noise
 masks .
 > > > aug = iaa . SimplexNoiseAlpha ( iaa . EdgeDetect ( 1.0 ) , upscale _ method = " linear " )
 Same as the first example , but uses only ( smooth ) linear upscaling to
 scale the simplex noise masks to the final image sizes , i . e . no nearest
 neighbour upsampling is used , which would result in rectangles with hard
 edges .
 > > > aug = iaa . SimplexNoiseAlpha ( iaa . EdgeDetect ( 1.0 ) , sigmoid _ thresh = iap . Normal ( 10.0 , 5.0 ) )
 Same as the first example , but uses a threshold for the sigmoid function
 that is further to the right . This is more conservative , i . e . the generated
 noise masks will be mostly black ( values around 0.0 ) , which means that
 most of the original images ( parameter / branch ` second ` ) will be kept ,
 rather than using the results of the augmentation ( parameter / branch
 ` first ` ) ."""

implementation:
upscale_method_default = iap . Choice ( [ "nearest" , "linear" , "cubic" ] , p = [ 0.05 , 0.6 , 0.35 ] )
sigmoid_thresh_default = iap . Normal ( 0.0 , 5.0 )
noise = iap . SimplexNoise ( size_px_max = size_px_max , upscale_method = upscale_method if upscale_method is not None else upscale_method_default )
if iterations != 1 :
    noise = iap . IterativeNoiseAggregator ( noise , iterations = iterations , aggregation_method = aggregation_method )
if sigmoid is False or ( ia . is_single_number ( sigmoid ) and sigmoid <= 0.01 ) :
    noise = iap . Sigmoid . create_for_noise ( noise , threshold = sigmoid_thresh if sigmoid_thresh is not None else sigmoid_thresh_default , activated = sigmoid )
if name is None :
    name = "Unnamed%s" % ( ia . caller_name ( ) , )
return AlphaElementwise ( factor = noise , first = first , second = second , per_channel = per_channel , name = name , deterministic = deterministic , random_state = random_state )


signature:
def OneOf ( children , name = None , deterministic = False , random_state = None ) :
    """Augmenter that always executes exactly one of its children .
 dtype support : :
 See ` ` imgaug . augmenters . meta . SomeOf ` ` .
 Parameters
 children : list of imgaug . augmenters . meta . Augmenter
 The choices of augmenters to apply .
 name : None or str , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 deterministic : bool , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 random _ state : None or int or numpy . random . RandomState , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 Examples
 > > > imgs = [ np . ones ( ( 10 , 10 ) ) ]
 > > > seq = iaa . OneOf ( [
 > > > iaa . Fliplr ( 1.0 ) ,
 > > > iaa . Flipud ( 1.0)
 > > > imgs _ aug = seq . augment _ images ( imgs )
 flips each image either horizontally or vertically .
 > > > seq = iaa . OneOf ( [
 > > > iaa . Fliplr ( 1.0 ) ,
 > > > iaa . Sequential ( [
 > > > iaa . GaussianBlur ( 1.0 ) ,
 > > > iaa . Dropout ( 0.05 ) ,
 > > > iaa . AdditiveGaussianNoise ( 0.1*255)
 > > > iaa . Noop ( )
 > > > imgs _ aug = seq . augment _ images ( imgs )
 either flips each image horizontally , or adds blur + dropout + noise or does
 nothing ."""

implementation: return SomeOf ( n = 1 , children = children , random_order = False , name = name , deterministic = deterministic , random_state = random_state )


signature:
def AssertLambda ( func_images = None , func_heatmaps = None , func_keypoints = None , func_polygons = None , name = None , deterministic = False , random_state = None ) :
    """Augmenter that runs an assert on each batch of input images
 using a lambda function as condition .
 This is useful to make generic assumption about the input images and error
 out early if they aren ' t met .
 dtype support : :
 * ` ` uint8 ` ` : yes ; fully tested
 * ` ` uint16 ` ` : yes ; tested
 * ` ` uint32 ` ` : yes ; tested
 * ` ` uint64 ` ` : yes ; tested
 * ` ` int8 ` ` : yes ; tested
 * ` ` int16 ` ` : yes ; tested
 * ` ` int32 ` ` : yes ; tested
 * ` ` int64 ` ` : yes ; tested
 * ` ` float16 ` ` : yes ; tested
 * ` ` float32 ` ` : yes ; tested
 * ` ` float64 ` ` : yes ; tested
 * ` ` float128 ` ` : yes ; tested
 * ` ` bool ` ` : yes ; tested
 Parameters
 func _ images : None or callable , optional
 The function to call for each batch of images .
 It must follow the form ` ` function ( images , random _ state , parents , hooks ) ` `
 and return either True ( valid input ) or False ( invalid input ) .
 It essentially reuses the interface of
 : func : ` imgaug . augmenters . meta . Augmenter . _ augment _ images ` .
 func _ heatmaps : None or callable , optional
 The function to call for each batch of heatmaps .
 It must follow the form ` ` function ( heatmaps , random _ state , parents , hooks ) ` `
 and return either True ( valid input ) or False ( invalid input ) .
 It essentially reuses the interface of
 : func : ` imgaug . augmenters . meta . Augmenter . _ augment _ heatmaps ` .
 func _ keypoints : None or callable , optional
 The function to call for each batch of keypoints .
 It must follow the form ` ` function ( keypoints _ on _ images , random _ state , parents , hooks ) ` `
 and return either True ( valid input ) or False ( invalid input ) .
 It essentially reuses the interface of
 : func : ` imgaug . augmenters . meta . Augmenter . _ augment _ keypoints ` .
 func _ polygons : None or callable , optional
 The function to call for each batch of polygons .
 It must follow the form ` ` function ( polygons _ on _ images , random _ state , parents , hooks ) ` `
 and return either True ( valid input ) or False ( invalid input ) .
 It essentially reuses the interface of
 : func : ` imgaug . augmenters . meta . Augmenter . _ augment _ polygons ` .
 name : None or str , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 deterministic : bool , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 random _ state : None or int or numpy . random . RandomState , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` ."""

implementation:
def func_images_assert ( images , random_state , parents , hooks ) :
    ia . do_assert ( func_images ( images , random_state , parents , hooks ) , "Input images did not fulfill user-defined assertion in AssertLambda." )
    return images
def func_heatmaps_assert ( heatmaps , random_state , parents , hooks ) :
    ia . do_assert ( func_heatmaps ( heatmaps , random_state , parents , hooks ) , "Input heatmaps did not fulfill user-defined assertion in AssertLambda." )
    return heatmaps
def func_keypoints_assert ( keypoints_on_images , random_state , parents , hooks ) :
    ia . do_assert ( func_keypoints ( keypoints_on_images , random_state , parents , hooks ) , "Input keypoints did not fulfill user-defined assertion in AssertLambda." )
    return keypoints_on_images
def func_polygons_assert ( polygons_on_images , random_state , parents , hooks ) :
    ia . do_assert ( func_polygons ( polygons_on_images , random_state , parents , hooks ) , "Input polygons did not fulfill user-defined assertion in AssertLambda." )
    return polygons_on_images
if name is None :
    name = "Unnamed%s" % ( ia . caller_name ( ) , )
return Lambda ( func_images_assert if func_images is not None else None , func_heatmaps_assert if func_heatmaps is not None else None , func_keypoints_assert if func_keypoints is not None else None , func_polygons_assert if func_polygons is not None else None , name = name , deterministic = deterministic , random_state = random_state )


signature:
def AssertShape ( shape , check_images = True , check_heatmaps = True , check_keypoints = True , check_polygons = True , name = None , deterministic = False , random_state = None ) :
    """Augmenter to make assumptions about the shape of input image ( s ) , heatmaps and keypoints .
 dtype support : :
 * ` ` uint8 ` ` : yes ; fully tested
 * ` ` uint16 ` ` : yes ; tested
 * ` ` uint32 ` ` : yes ; tested
 * ` ` uint64 ` ` : yes ; tested
 * ` ` int8 ` ` : yes ; tested
 * ` ` int16 ` ` : yes ; tested
 * ` ` int32 ` ` : yes ; tested
 * ` ` int64 ` ` : yes ; tested
 * ` ` float16 ` ` : yes ; tested
 * ` ` float32 ` ` : yes ; tested
 * ` ` float64 ` ` : yes ; tested
 * ` ` float128 ` ` : yes ; tested
 * ` ` bool ` ` : yes ; tested
 Parameters
 shape : tuple
 The expected shape , given as a tuple . The number of entries in the tuple must match the
 number of dimensions , i . e . it must contain four entries for ` ` ( N , H , W , C ) ` ` . If only a
 single image is augmented via ` ` augment _ image ( ) ` ` , then ` ` N ` ` is viewed as 1 by this
 augmenter . If the input image ( s ) don ' t have a channel axis , then ` ` C ` ` is viewed as 1
 by this augmenter .
 Each of the four entries may be None or a tuple of two ints or a list of ints .
 * If an entry is None , any value for that dimensions is accepted .
 * If an entry is int , exactly that integer value will be accepted
 or no other value .
 * If an entry is a tuple of two ints with values ` ` a ` ` and ` ` b ` ` , only a
 value ` ` x ` ` with ` ` a < = x < b ` ` will be accepted for the dimension .
 * If an entry is a list of ints , only a value for the dimension
 will be accepted which is contained in the list .
 check _ images : bool , optional
 Whether to validate input images via the given shape .
 check _ heatmaps : bool , optional
 Whether to validate input heatmaps via the given shape .
 The number of heatmaps will be checked and for each Heatmaps
 instance its array ' s height and width , but not the channel
 count as the channel number denotes the expected number of channels
 in images .
 check _ keypoints : bool , optional
 Whether to validate input keypoints via the given shape .
 This will check ( a ) the number of keypoints and ( b ) for each
 KeypointsOnImage instance the ` ` . shape ` ` , i . e . the shape of the
 corresponding image .
 check _ polygons : bool , optional
 Whether to validate input keypoints via the given shape .
 This will check ( a ) the number of polygons and ( b ) for each
 PolygonsOnImage instance the ` ` . shape ` ` , i . e . the shape of the
 corresponding image .
 name : None or str , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 deterministic : bool , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 random _ state : None or int or numpy . random . RandomState , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 Examples
 > > > seq = iaa . Sequential ( [
 > > > iaa . AssertShape ( ( None , 32 , 32 , 3 ) ) ,
 > > > iaa . Fliplr ( 0.5)
 will first check for each image batch , if it contains a variable number of
 ` ` 32x32 ` ` images with 3 channels each . Only if that check succeeds , the
 horizontal flip will be executed ( otherwise an assertion error will be
 thrown ) .
 > > > seq = iaa . Sequential ( [
 > > > iaa . AssertShape ( ( None , ( 32 , 64 ) , 32 , [ 1 , 3 ] ) ) ,
 > > > iaa . Fliplr ( 0.5)
 like above , but now the height may be in the range ` ` 32 < = H < 64 ` ` and
 the number of channels may be either 1 or 3."""

implementation:
ia . do_assert ( len ( shape ) == 4 , "Expected shape to have length 4, got %d with shape: %s." % ( len ( shape ) , str ( shape ) ) )
def compare ( observed , expected , dimension , image_index ) :
    if expected is not None :
        if ia . is_single_integer ( expected ) :
            ia . do_assert ( observed == expected , "Expected dim %d (entry index: %s) to have value %d, got %d." % ( dimension , image_index , expected , observed ) )
        elif isinstance ( expected , tuple ) :
            ia . do_assert ( len ( expected ) == 2 )
            ia . do_assert ( expected [ 0 ] <= observed < expected [ 1 ] , "Expected dim %d (entry index: %s) to have value in range [%d, %d), got %d." % ( dimension , image_index , expected [ 0 ] , expected [ 1 ] , observed ) )
        elif isinstance ( expected , list ) :
            ia . do_assert ( any ( [ observed == val for val in expected ] ) , "Expected dim %d (entry index: %s) to have any value of %s, got %d." % ( dimension , image_index , str ( expected ) , observed ) )
        else :
            raise Exception ( ( "Invalid datatype for shape entry %d, expected each entry to be an integer, " + "a tuple (with two entries) or a list, got %s." ) % ( dimension , type ( expected ) , ) )
def func_images ( images , _random_state , _parents , _hooks ) :
    if check_images :
        if isinstance ( images , list ) :
            if shape [ 0 ] is not None :
                compare ( len ( images ) , shape [ 0 ] , 0 , "ALL" )
            for i in sm . xrange ( len ( images ) ) :
                image = images [ i ]
                ia . do_assert ( len ( image . shape ) == 3 , "Expected image number %d to have a shape of length 3, got %d (shape: %s)." % ( i , len ( image . shape ) , str ( image . shape ) ) )
                for j in sm . xrange ( len ( shape ) - 1 ) :
                    expected = shape [ j + 1 ]
                    observed = image . shape [ j ]
                    compare ( observed , expected , j , i )
        else :
            ia . do_assert ( len ( images . shape ) == 4 , "Expected image's shape to have length 4, got %d (shape: %s)." % ( len ( images . shape ) , str ( images . shape ) ) )
            for i in range ( 4 ) :
                expected = shape [ i ]
                observed = images . shape [ i ]
                compare ( observed , expected , i , "ALL" )
    return images
def func_heatmaps ( heatmaps , _random_state , _parents , _hooks ) :
    if check_heatmaps :
        if shape [ 0 ] is not None :
            compare ( len ( heatmaps ) , shape [ 0 ] , 0 , "ALL" )
        for i in sm . xrange ( len ( heatmaps ) ) :
            heatmaps_i = heatmaps [ i ]
            for j in sm . xrange ( len ( shape [ 0 : 2 ] ) ) :
                expected = shape [ j + 1 ]
                observed = heatmaps_i . arr_0to1 . shape [ j ]
                compare ( observed , expected , j , i )
    return heatmaps
def func_keypoints ( keypoints_on_images , _random_state , _parents , _hooks ) :
    if check_keypoints :
        if shape [ 0 ] is not None :
            compare ( len ( keypoints_on_images ) , shape [ 0 ] , 0 , "ALL" )
        for i in sm . xrange ( len ( keypoints_on_images ) ) :
            keypoints_on_image = keypoints_on_images [ i ]
            for j in sm . xrange ( len ( shape [ 0 : 2 ] ) ) :
                expected = shape [ j + 1 ]
                observed = keypoints_on_image . shape [ j ]
                compare ( observed , expected , j , i )
    return keypoints_on_images
def func_polygons ( polygons_on_images , _random_state , _parents , _hooks ) :
    if check_polygons :
        if shape [ 0 ] is not None :
            compare ( len ( polygons_on_images ) , shape [ 0 ] , 0 , "ALL" )
        for i in sm . xrange ( len ( polygons_on_images ) ) :
            polygons_on_image = polygons_on_images [ i ]
            for j in sm . xrange ( len ( shape [ 0 : 2 ] ) ) :
                expected = shape [ j + 1 ]
                observed = polygons_on_image . shape [ j ]
                compare ( observed , expected , j , i )
    return polygons_on_images
if name is None :
    name = "Unnamed%s" % ( ia . caller_name ( ) , )
return Lambda ( func_images , func_heatmaps , func_keypoints , func_polygons , name = name , deterministic = deterministic , random_state = random_state )


signature:
def shuffle_channels ( image , random_state , channels = None ) :
    """Randomize the order of ( color ) channels in an image .
 dtype support : :
 * ` ` uint8 ` ` : yes ; fully tested
 * ` ` uint16 ` ` : yes ; indirectly tested ( 1)
 * ` ` uint32 ` ` : yes ; indirectly tested ( 1)
 * ` ` uint64 ` ` : yes ; indirectly tested ( 1)
 * ` ` int8 ` ` : yes ; indirectly tested ( 1)
 * ` ` int16 ` ` : yes ; indirectly tested ( 1)
 * ` ` int32 ` ` : yes ; indirectly tested ( 1)
 * ` ` int64 ` ` : yes ; indirectly tested ( 1)
 * ` ` float16 ` ` : yes ; indirectly tested ( 1)
 * ` ` float32 ` ` : yes ; indirectly tested ( 1)
 * ` ` float64 ` ` : yes ; indirectly tested ( 1)
 * ` ` float128 ` ` : yes ; indirectly tested ( 1)
 * ` ` bool ` ` : yes ; indirectly tested ( 1)
 - ( 1 ) Indirectly tested via ` ` ChannelShuffle ` ` .
 Parameters
 image : ( H , W , [ C ] ) ndarray
 Image of any dtype for which to shuffle the channels .
 random _ state : numpy . random . RandomState
 The random state to use for this shuffling operation .
 channels : None or imgaug . ALL or list of int , optional
 Which channels are allowed to be shuffled with each other .
 If this is ` ` None ` ` or ` ` imgaug . ALL ` ` , then all channels may be shuffled . If it is a list of integers ,
 then only the channels with indices in that list may be shuffled . ( Values start at 0 . All channel indices in
 the list must exist in each image . )
 Returns
 ndarray
 The input image with shuffled channels ."""

implementation:
if image . ndim < 3 or image . shape [ 2 ] == 1 :
    return image
nb_channels = image . shape [ 2 ]
all_channels = np . arange ( nb_channels )
is_all_channels = ( channels is None or channels == ia . ALL or len ( set ( all_channels ) . difference ( set ( channels ) ) ) == 0 )
if is_all_channels : # note that if this is the case , then ' channels ' may be None or imgaug . ALL , so don ' t simply move the
# assignment outside of the if / else
    channels_perm = random_state . permutation ( all_channels )
    return image [ ... , channels_perm ]
else :
    channels_perm = random_state . permutation ( channels )
    channels_perm_full = all_channels
    for channel_source , channel_target in zip ( channels , channels_perm ) :
        channels_perm_full [ channel_source ] = channel_target
    return image [ ... , channels_perm_full ]


signature:
def blur_gaussian_ ( image , sigma , ksize = None , backend = "auto" , eps = 1e-3 ) :
    """Blur an image using gaussian blurring .
 This operation might change the input image in - place .
 dtype support : :
 if ( backend = " auto " ) : :
 * ` ` uint8 ` ` : yes ; fully tested ( 1)
 * ` ` uint16 ` ` : yes ; tested ( 1)
 * ` ` uint32 ` ` : yes ; tested ( 2)
 * ` ` uint64 ` ` : yes ; tested ( 2)
 * ` ` int8 ` ` : yes ; tested ( 1)
 * ` ` int16 ` ` : yes ; tested ( 1)
 * ` ` int32 ` ` : yes ; tested ( 1)
 * ` ` int64 ` ` : yes ; tested ( 2)
 * ` ` float16 ` ` : yes ; tested ( 1)
 * ` ` float32 ` ` : yes ; tested ( 1)
 * ` ` float64 ` ` : yes ; tested ( 1)
 * ` ` float128 ` ` : no
 * ` ` bool ` ` : yes ; tested ( 1)
 - ( 1 ) Handled by ` ` cv2 ` ` . See ` ` backend = " cv2 " ` ` .
 - ( 2 ) Handled by ` ` scipy ` ` . See ` ` backend = " scipy " ` ` .
 if ( backend = " cv2 " ) : :
 * ` ` uint8 ` ` : yes ; fully tested
 * ` ` uint16 ` ` : yes ; tested
 * ` ` uint32 ` ` : no ( 2)
 * ` ` uint64 ` ` : no ( 3)
 * ` ` int8 ` ` : yes ; tested ( 4)
 * ` ` int16 ` ` : yes ; tested
 * ` ` int32 ` ` : yes ; tested ( 5)
 * ` ` int64 ` ` : no ( 6)
 * ` ` float16 ` ` : yes ; tested ( 7)
 * ` ` float32 ` ` : yes ; tested
 * ` ` float64 ` ` : yes ; tested
 * ` ` float128 ` ` : no ( 8)
 * ` ` bool ` ` : yes ; tested ( 1)
 - ( 1 ) Mapped internally to ` ` float32 ` ` . Otherwise causes ` ` TypeError : src data type = 0 is not supported ` ` .
 - ( 2 ) Causes ` ` TypeError : src data type = 6 is not supported ` ` .
 - ( 3 ) Causes ` ` cv2 . error : OpenCV ( 3.4.5 ) ( . . . ) / filter . cpp : 2957 : error : ( - 213 : The function / feature is not
 implemented ) Unsupported combination of source format ( = 4 ) , and buffer format ( = 5 ) in function
 ' getLinearRowFilter ' ` ` .
 - ( 4 ) Mapped internally to ` ` int16 ` ` . Otherwise causes ` ` cv2 . error : OpenCV ( 3.4.5 ) ( . . . ) / filter . cpp : 2957:
 error : ( - 213 : The function / feature is not implemented ) Unsupported combination of source format ( = 1 ) ,
 and buffer format ( = 5 ) in function ' getLinearRowFilter ' ` ` .
 - ( 5 ) Mapped internally to ` ` float64 ` ` . Otherwise causes ` ` cv2 . error : OpenCV ( 3.4.5 ) ( . . . ) / filter . cpp : 2957:
 error : ( - 213 : The function / feature is not implemented ) Unsupported combination of source format ( = 4 ) ,
 and buffer format ( = 5 ) in function ' getLinearRowFilter ' ` ` .
 - ( 6 ) Causes ` ` cv2 . error : OpenCV ( 3.4.5 ) ( . . . ) / filter . cpp : 2957 : error : ( - 213 : The function / feature is not
 implemented ) Unsupported combination of source format ( = 4 ) , and buffer format ( = 5 ) in function
 ' getLinearRowFilter ' ` ` .
 - ( 7 ) Mapped internally to ` ` float32 ` ` . Otherwise causes ` ` TypeError : src data type = 23 is not supported ` ` .
 - ( 8 ) Causes ` ` TypeError : src data type = 13 is not supported ` ` .
 if ( backend = " scipy " ) : :
 * ` ` uint8 ` ` : yes ; fully tested
 * ` ` uint16 ` ` : yes ; tested
 * ` ` uint32 ` ` : yes ; tested
 * ` ` uint64 ` ` : yes ; tested
 * ` ` int8 ` ` : yes ; tested
 * ` ` int16 ` ` : yes ; tested
 * ` ` int32 ` ` : yes ; tested
 * ` ` int64 ` ` : yes ; tested
 * ` ` float16 ` ` : yes ; tested ( 1)
 * ` ` float32 ` ` : yes ; tested
 * ` ` float64 ` ` : yes ; tested
 * ` ` float128 ` ` : no ( 2)
 * ` ` bool ` ` : yes ; tested ( 3)
 - ( 1 ) Mapped internally to ` ` float32 ` ` . Otherwise causes ` ` RuntimeError : array type dtype ( ' float16 ' )
 not supported ` ` .
 - ( 2 ) Causes ` ` RuntimeError : array type dtype ( ' float128 ' ) not supported ` ` .
 - ( 3 ) Mapped internally to ` ` float32 ` ` . Otherwise too inaccurate .
 Parameters
 image : numpy . ndarray
 The image to blur . Expected to be of shape ` ` ( H , W ) ` ` or ` ` ( H , W , C ) ` ` .
 sigma : number
 Standard deviation of the gaussian blur . Larger numbers result in more large - scale blurring , which is overall
 slower than small - scale blurring .
 ksize : None or int , optional
 Size in height / width of the gaussian kernel . This argument is only understood by the ` ` cv2 ` ` backend .
 If it is set to None , an appropriate value for ` ksize ` will automatically be derived from ` sigma ` .
 The value is chosen tighter for larger sigmas to avoid as much as possible very large kernel sizes
 and therey improve performance .
 backend : { ' auto ' , ' cv2 ' , ' scipy ' } , optional
 Backend library to use . If ` ` auto ` ` , then the likely best library will be automatically picked per image . That
 is usually equivalent to ` ` cv2 ` ` ( OpenCV ) and it will fall back to ` ` scipy ` ` for datatypes not supported by
 OpenCV .
 eps : number , optional
 A threshold used to decide whether ` sigma ` can be considered zero .
 Returns
 image : numpy . ndarray
 The blurred image . Same shape and dtype as the input ."""

implementation:
if sigma > 0 + eps :
    dtype = image . dtype
    iadt . gate_dtypes ( image , allowed = [ "bool" , "uint8" , "uint16" , "uint32" , "int8" , "int16" , "int32" , "int64" , "uint64" , "float16" , "float32" , "float64" ] , disallowed = [ "uint128" , "uint256" , "int128" , "int256" , "float96" , "float128" , "float256" ] , augmenter = None )
    dts_not_supported_by_cv2 = [ "uint32" , "uint64" , "int64" , "float128" ]
    backend_to_use = backend
    if backend == "auto" :
        backend_to_use = "cv2" if image . dtype . name not in dts_not_supported_by_cv2 else "scipy"
    elif backend == "cv2" :
        assert image . dtype . name not in dts_not_supported_by_cv2 , ( "Requested 'cv2' backend, but provided %s input image, which " + "cannot be handled by that backend. Choose a different backend or " + "set backend to 'auto' or use a different datatype." ) % ( image . dtype . name , )
    elif backend == "scipy" : # can handle all dtypes that were allowed in gate _ dtypes ( )
        pass
    if backend_to_use == "scipy" :
        if dtype . name == "bool" : # We convert bool to float32 here , because gaussian _ filter ( ) seems to only return True when
        # the underlying value is approximately 1.0 , not when it is above 0.5 . So we do that here manually .
        # cv2 does not support bool for gaussian blur
            image = image . astype ( np . float32 , copy = False )
        elif dtype . name == "float16" :
            image = image . astype ( np . float32 , copy = False )
        # gaussian _ filter ( ) has no ksize argument
        # TODO it does have a truncate argument that truncates at x standard deviations - - maybe can be used
        # similarly to ksize
        if ksize is not None :
            warnings . warn ( "Requested 'scipy' backend or picked it automatically by backend='auto' " "in blur_gaussian_(), but also provided 'ksize' argument, which is not understood by " "that backend and will be ignored." )
        # Note that while gaussian _ filter can be applied to all channels at the same time , that should not
        # be done here , because then the blurring would also happen across channels ( e . g . red values might
        # be mixed with blue values in RGB )
        if image . ndim == 2 :
            image [ : , : ] = ndimage . gaussian_filter ( image [ : , : ] , sigma , mode = "mirror" )
        else :
            nb_channels = image . shape [ 2 ]
            for channel in sm . xrange ( nb_channels ) :
                image [ : , : , channel ] = ndimage . gaussian_filter ( image [ : , : , channel ] , sigma , mode = "mirror" )
    else :
        if dtype . name == "bool" :
            image = image . astype ( np . float32 , copy = False )
        elif dtype . name == "float16" :
            image = image . astype ( np . float32 , copy = False )
        elif dtype . name == "int8" :
            image = image . astype ( np . int16 , copy = False )
        elif dtype . name == "int32" :
            image = image . astype ( np . float64 , copy = False )
        # ksize here is derived from the equation to compute sigma based on ksize ,
        # see https : / / docs . opencv . org / 3.1.0 / d4 / d86 / group _ _ imgproc _ _ filter . html - > cv : : getGaussianKernel ( )
        # example values :
        # sig = 0.1 - > ksize = - 1.666
        # sig = 0.5 - > ksize = 0.9999
        # sig = 1.0 - > ksize = 1.0
        # sig = 2.0 - > ksize = 11.0
        # sig = 3.0 - > ksize = 17.666
        # ksize = ( ( sig - 0.8 ) / 0.3 + 1 ) / 0.5 + 1
        if ksize is None :
            if sigma < 3.0 :
                ksize = 3.3 * sigma
                # 99 % of weight
            elif sigma < 5.0 :
                ksize = 2.9 * sigma
                # 97 % of weight
            else :
                ksize = 2.6 * sigma
            # 95 % of weight
            # we use 5x5 here as the minimum size as that simplifies comparisons with gaussian _ filter ( ) in the tests
            # TODO reduce this to 3x3
            ksize = int ( max ( ksize , 5 ) )
        else :
            assert ia . is_single_integer ( ksize ) , "Expected 'ksize' argument to be a number, got %s." % ( type ( ksize ) , )
        ksize = ksize + 1 if ksize % 2 == 0 else ksize
        if ksize > 0 :
            image_warped = cv2 . GaussianBlur ( image , ( ksize , ksize ) , sigmaX = sigma , sigmaY = sigma , borderType = cv2 . BORDER_REFLECT_101 )
            # re - add channel axis removed by cv2 if input was ( H , W , 1)
            image = image_warped [ ... , np . newaxis ] if image . ndim == 3 and image_warped . ndim == 2 else image_warped
    if dtype . name == "bool" :
        image = image > 0.5
    elif dtype . name != image . dtype . name :
        image = iadt . restore_dtypes_ ( image , dtype )
return image


signature:
def MotionBlur ( k = 5 , angle = ( 0 , 360 ) , direction = ( - 1.0 , 1.0 ) , order = 1 , name = None , deterministic = False , random_state = None ) :
    """Augmenter that sharpens images and overlays the result with the original image .
 dtype support : :
 See ` ` imgaug . augmenters . convolutional . Convolve ` ` .
 Parameters
 k : int or tuple of int or list of int or imgaug . parameters . StochasticParameter , optional
 Kernel size to use .
 * If a single int , then that value will be used for the height
 and width of the kernel .
 * If a tuple of two ints ` ` ( a , b ) ` ` , then the kernel size will be
 sampled from the interval ` ` [ a . . b ] ` ` .
 * If a list , then a random value will be sampled from that list per image .
 * If a StochasticParameter , then ` ` N ` ` samples will be drawn from
 that parameter per ` ` N ` ` input images , each representing the kernel
 size for the nth image .
 angle : number or tuple of number or list of number or imgaug . parameters . StochasticParameter , optional
 Angle of the motion blur in degrees ( clockwise , relative to top center direction ) .
 * If a number , exactly that value will be used .
 * If a tuple ` ` ( a , b ) ` ` , a random value from the range ` ` a < = x < = b ` ` will
 be sampled per image .
 * If a list , then a random value will be sampled from that list per image .
 * If a StochasticParameter , a value will be sampled from the
 parameter per image .
 direction : number or tuple of number or list of number or imgaug . parameters . StochasticParameter , optional
 Forward / backward direction of the motion blur . Lower values towards - 1.0 will point the motion blur towards
 the back ( with angle provided via ` angle ` ) . Higher values towards 1.0 will point the motion blur forward .
 A value of 0.0 leads to a uniformly ( but still angled ) motion blur .
 * If a number , exactly that value will be used .
 * If a tuple ` ` ( a , b ) ` ` , a random value from the range ` ` a < = x < = b ` ` will
 be sampled per image .
 * If a list , then a random value will be sampled from that list per image .
 * If a StochasticParameter , a value will be sampled from the
 parameter per image .
 order : int or iterable of int or imgaug . ALL or imgaug . parameters . StochasticParameter , optional
 Interpolation order to use when rotating the kernel according to ` angle ` .
 See : func : ` imgaug . augmenters . geometric . Affine . _ _ init _ _ ` .
 Recommended to be ` ` 0 ` ` or ` ` 1 ` ` , with ` ` 0 ` ` being faster , but less continuous / smooth as ` angle ` is changed ,
 particularly around multiple of 45 degrees .
 name : None or str , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 deterministic : bool , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 random _ state : None or int or numpy . random . RandomState , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 Examples
 > > > aug = iaa . MotionBlur ( k = 15)
 Create a motion blur augmenter with kernel size of 15x15.
 > > > aug = iaa . MotionBlur ( k = 15 , angle = [ - 45 , 45 ] )
 Create a motion blur augmenter with kernel size of 15x15 and a blur angle of either - 45 or 45 degrees ( randomly
 picked per image ) ."""

implementation:
# TODO allow ( 1 , None ) and set to identity matrix if k = = 1
k_param = iap . handle_discrete_param ( k , "k" , value_range = ( 3 , None ) , tuple_to_uniform = True , list_to_choice = True , allow_floats = False )
angle_param = iap . handle_continuous_param ( angle , "angle" , value_range = None , tuple_to_uniform = True , list_to_choice = True )
direction_param = iap . handle_continuous_param ( direction , "direction" , value_range = ( - 1.0 - 1e-6 , 1.0 + 1e-6 ) , tuple_to_uniform = True , list_to_choice = True )
def create_matrices ( image , nb_channels , random_state_func ) : # avoid cyclic import between blur and geometric
    from . import geometric as iaa_geometric
    # force discrete for k _ sample via int ( ) in case of stochastic parameter
    k_sample = int ( k_param . draw_sample ( random_state = random_state_func ) )
    angle_sample = angle_param . draw_sample ( random_state = random_state_func )
    direction_sample = direction_param . draw_sample ( random_state = random_state_func )
    k_sample = k_sample if k_sample % 2 != 0 else k_sample + 1
    direction_sample = np . clip ( direction_sample , - 1.0 , 1.0 )
    direction_sample = ( direction_sample + 1.0 ) / 2.0
    matrix = np . zeros ( ( k_sample , k_sample ) , dtype = np . float32 )
    matrix [ : , k_sample // 2 ] = np . linspace ( float ( direction_sample ) , 1.0 - float ( direction_sample ) , num = k_sample )
    rot = iaa_geometric . Affine ( rotate = angle_sample , order = order )
    matrix = ( rot . augment_image ( ( matrix * 255 ) . astype ( np . uint8 ) ) / 255.0 ) . astype ( np . float32 )
    return [ matrix / np . sum ( matrix ) ] * nb_channels
if name is None :
    name = "Unnamed%s" % ( ia . caller_name ( ) , )
return iaa_convolutional . Convolve ( create_matrices , name = name , deterministic = deterministic , random_state = random_state )


signature:
def Clouds ( name = None , deterministic = False , random_state = None ) :
    """Augmenter to draw clouds in images .
 This is a wrapper around ` ` CloudLayer ` ` . It executes 1 to 2 layers per image , leading to varying densities
 and frequency patterns of clouds .
 This augmenter seems to be fairly robust w . r . t . the image size . Tested with ` ` 96x128 ` ` , ` ` 192x256 ` `
 and ` ` 960x1280 ` ` .
 dtype support : :
 * ` ` uint8 ` ` : yes ; tested
 * ` ` uint16 ` ` : no ( 1)
 * ` ` uint32 ` ` : no ( 1)
 * ` ` uint64 ` ` : no ( 1)
 * ` ` int8 ` ` : no ( 1)
 * ` ` int16 ` ` : no ( 1)
 * ` ` int32 ` ` : no ( 1)
 * ` ` int64 ` ` : no ( 1)
 * ` ` float16 ` ` : no ( 1)
 * ` ` float32 ` ` : no ( 1)
 * ` ` float64 ` ` : no ( 1)
 * ` ` float128 ` ` : no ( 1)
 * ` ` bool ` ` : no ( 1)
 - ( 1 ) Parameters of this augmenter are optimized for the value range of uint8.
 While other dtypes may be accepted , they will lead to images augmented in
 ways inappropriate for the respective dtype .
 Parameters
 name : None or str , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 deterministic : bool , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 random _ state : None or int or numpy . random . RandomState , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 Examples
 > > > aug = iaa . Clouds ( )
 Creates an augmenter that adds clouds to images ."""

implementation:
if name is None :
    name = "Unnamed%s" % ( ia . caller_name ( ) , )
return meta . SomeOf ( ( 1 , 2 ) , children = [ CloudLayer ( intensity_mean = ( 196 , 255 ) , intensity_freq_exponent = ( - 2.5 , - 2.0 ) , intensity_coarse_scale = 10 , alpha_min = 0 , alpha_multiplier = ( 0.25 , 0.75 ) , alpha_size_px_max = ( 2 , 8 ) , alpha_freq_exponent = ( - 2.5 , - 2.0 ) , sparsity = ( 0.8 , 1.0 ) , density_multiplier = ( 0.5 , 1.0 ) ) , CloudLayer ( intensity_mean = ( 196 , 255 ) , intensity_freq_exponent = ( - 2.0 , - 1.0 ) , intensity_coarse_scale = 10 , alpha_min = 0 , alpha_multiplier = ( 0.5 , 1.0 ) , alpha_size_px_max = ( 64 , 128 ) , alpha_freq_exponent = ( - 2.0 , - 1.0 ) , sparsity = ( 1.0 , 1.4 ) , density_multiplier = ( 0.8 , 1.5 ) ) ] , random_order = False , name = name , deterministic = deterministic , random_state = random_state )


signature:
def Fog ( name = None , deterministic = False , random_state = None ) :
    """Augmenter to draw fog in images .
 This is a wrapper around ` ` CloudLayer ` ` . It executes a single layer per image with a configuration leading
 to fairly dense clouds with low - frequency patterns .
 This augmenter seems to be fairly robust w . r . t . the image size . Tested with ` ` 96x128 ` ` , ` ` 192x256 ` `
 and ` ` 960x1280 ` ` .
 dtype support : :
 * ` ` uint8 ` ` : yes ; tested
 * ` ` uint16 ` ` : no ( 1)
 * ` ` uint32 ` ` : no ( 1)
 * ` ` uint64 ` ` : no ( 1)
 * ` ` int8 ` ` : no ( 1)
 * ` ` int16 ` ` : no ( 1)
 * ` ` int32 ` ` : no ( 1)
 * ` ` int64 ` ` : no ( 1)
 * ` ` float16 ` ` : no ( 1)
 * ` ` float32 ` ` : no ( 1)
 * ` ` float64 ` ` : no ( 1)
 * ` ` float128 ` ` : no ( 1)
 * ` ` bool ` ` : no ( 1)
 - ( 1 ) Parameters of this augmenter are optimized for the value range of uint8.
 While other dtypes may be accepted , they will lead to images augmented in
 ways inappropriate for the respective dtype .
 Parameters
 name : None or str , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 deterministic : bool , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 random _ state : None or int or numpy . random . RandomState , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 Examples
 > > > aug = iaa . Fog ( )
 Creates an augmenter that adds fog to images ."""

implementation:
if name is None :
    name = "Unnamed%s" % ( ia . caller_name ( ) , )
return CloudLayer ( intensity_mean = ( 220 , 255 ) , intensity_freq_exponent = ( - 2.0 , - 1.5 ) , intensity_coarse_scale = 2 , alpha_min = ( 0.7 , 0.9 ) , alpha_multiplier = 0.3 , alpha_size_px_max = ( 2 , 8 ) , alpha_freq_exponent = ( - 4.0 , - 2.0 ) , sparsity = 0.9 , density_multiplier = ( 0.4 , 0.9 ) , name = name , deterministic = deterministic , random_state = random_state )


signature:
def Snowflakes ( density = ( 0.005 , 0.075 ) , density_uniformity = ( 0.3 , 0.9 ) , flake_size = ( 0.2 , 0.7 ) , flake_size_uniformity = ( 0.4 , 0.8 ) , angle = ( - 30 , 30 ) , speed = ( 0.007 , 0.03 ) , name = None , deterministic = False , random_state = None ) :
    """Augmenter to add falling snowflakes to images .
 This is a wrapper around ` ` SnowflakesLayer ` ` . It executes 1 to 3 layers per image .
 dtype support : :
 * ` ` uint8 ` ` : yes ; tested
 * ` ` uint16 ` ` : no ( 1)
 * ` ` uint32 ` ` : no ( 1)
 * ` ` uint64 ` ` : no ( 1)
 * ` ` int8 ` ` : no ( 1)
 * ` ` int16 ` ` : no ( 1)
 * ` ` int32 ` ` : no ( 1)
 * ` ` int64 ` ` : no ( 1)
 * ` ` float16 ` ` : no ( 1)
 * ` ` float32 ` ` : no ( 1)
 * ` ` float64 ` ` : no ( 1)
 * ` ` float128 ` ` : no ( 1)
 * ` ` bool ` ` : no ( 1)
 - ( 1 ) Parameters of this augmenter are optimized for the value range of uint8.
 While other dtypes may be accepted , they will lead to images augmented in
 ways inappropriate for the respective dtype .
 Parameters
 density : number or tuple of number or list of number or imgaug . parameters . StochasticParameter
 Density of the snowflake layer , as a probability of each pixel in low resolution space to be a snowflake .
 Valid value range is ` ` ( 0.0 , 1.0 ) ` ` . Recommended to be around ` ` ( 0.01 , 0.075 ) ` ` .
 * If a number , then that value will be used for all images .
 * If a tuple ` ` ( a , b ) ` ` , then a value from the continuous range ` ` [ a , b ] ` ` will be used .
 * If a list , then a random value will be sampled from that list per image .
 * If a StochasticParameter , then a value will be sampled per image from that parameter .
 density _ uniformity : number or tuple of number or list of number or imgaug . parameters . StochasticParameter
 Size uniformity of the snowflakes . Higher values denote more similarly sized snowflakes .
 Valid value range is ` ` ( 0.0 , 1.0 ) ` ` . Recommended to be around ` ` 0.5 ` ` .
 * If a number , then that value will be used for all images .
 * If a tuple ` ` ( a , b ) ` ` , then a value from the continuous range ` ` [ a , b ] ` ` will be used .
 * If a list , then a random value will be sampled from that list per image .
 * If a StochasticParameter , then a value will be sampled per image from that parameter .
 flake _ size : number or tuple of number or list of number or imgaug . parameters . StochasticParameter
 Size of the snowflakes . This parameter controls the resolution at which snowflakes are sampled .
 Higher values mean that the resolution is closer to the input image ' s resolution and hence each sampled
 snowflake will be smaller ( because of the smaller pixel size ) .
 Valid value range is ` ` [ 0.0 , 1.0 ) ` ` . Recommended values :
 * On ` ` 96x128 ` ` a value of ` ` ( 0.1 , 0.4 ) ` ` worked well .
 * On ` ` 192x256 ` ` a value of ` ` ( 0.2 , 0.7 ) ` ` worked well .
 * On ` ` 960x1280 ` ` a value of ` ` ( 0.7 , 0.95 ) ` ` worked well .
 Allowed datatypes :
 * If a number , then that value will be used for all images .
 * If a tuple ` ` ( a , b ) ` ` , then a value from the continuous range ` ` [ a , b ] ` ` will be used .
 * If a list , then a random value will be sampled from that list per image .
 * If a StochasticParameter , then a value will be sampled per image from that parameter .
 flake _ size _ uniformity : number or tuple of number or list of number or imgaug . parameters . StochasticParameter
 Controls the size uniformity of the snowflakes . Higher values mean that the snowflakes are more similarly
 sized . Valid value range is ` ` ( 0.0 , 1.0 ) ` ` . Recommended to be around ` ` 0.5 ` ` .
 * If a number , then that value will be used for all images .
 * If a tuple ` ` ( a , b ) ` ` , then a value from the continuous range ` ` [ a , b ] ` ` will be used .
 * If a list , then a random value will be sampled from that list per image .
 * If a StochasticParameter , then a value will be sampled per image from that parameter .
 angle : number or tuple of number or list of number or imgaug . parameters . StochasticParameter
 Angle in degrees of motion blur applied to the snowflakes , where ` ` 0.0 ` ` is motion blur that points straight
 upwards . Recommended to be around ` ` ( - 30 , 30 ) ` ` .
 See also : func : ` imgaug . augmenters . blur . MotionBlur . _ _ init _ _ ` .
 * If a number , then that value will be used for all images .
 * If a tuple ` ` ( a , b ) ` ` , then a value from the continuous range ` ` [ a , b ] ` ` will be used .
 * If a list , then a random value will be sampled from that list per image .
 * If a StochasticParameter , then a value will be sampled per image from that parameter .
 speed : number or tuple of number or list of number or imgaug . parameters . StochasticParameter
 Perceived falling speed of the snowflakes . This parameter controls the motion blur ' s kernel size .
 It follows roughly the form ` ` kernel _ size = image _ size * speed ` ` . Hence ,
 Values around ` ` 1.0 ` ` denote that the motion blur should " stretch " each snowflake over the whole image .
 Valid value range is ` ` ( 0.0 , 1.0 ) ` ` . Recommended values :
 * On ` ` 96x128 ` ` a value of ` ` ( 0.01 , 0.05 ) ` ` worked well .
 * On ` ` 192x256 ` ` a value of ` ` ( 0.007 , 0.03 ) ` ` worked well .
 * On ` ` 960x1280 ` ` a value of ` ` ( 0.001 , 0.03 ) ` ` worked well .
 Allowed datatypes :
 * If a number , then that value will be used for all images .
 * If a tuple ` ` ( a , b ) ` ` , then a value from the continuous range ` ` [ a , b ] ` ` will be used .
 * If a list , then a random value will be sampled from that list per image .
 * If a StochasticParameter , then a value will be sampled per image from that parameter .
 name : None or str , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 deterministic : bool , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 random _ state : None or int or numpy . random . RandomState , optional
 See : func : ` imgaug . augmenters . meta . Augmenter . _ _ init _ _ ` .
 Examples
 > > > aug = iaa . Snowflakes ( flake _ size = ( 0.1 , 0.4 ) , speed = ( 0.01 , 0.05 ) )
 Adds snowflakes to small images ( around ` ` 96x128 ` ` ) .
 > > > aug = iaa . Snowflakes ( flake _ size = ( 0.2 , 0.7 ) , speed = ( 0.007 , 0.03 ) )
 Adds snowflakes to medium - sized images ( around ` ` 192x256 ` ` ) .
 > > > aug = iaa . Snowflakes ( flake _ size = ( 0.7 , 0.95 ) , speed = ( 0.001 , 0.03 ) )
 Adds snowflakes to large images ( around ` ` 960x1280 ` ` ) ."""

implementation:
if name is None :
    name = "Unnamed%s" % ( ia . caller_name ( ) , )
layer = SnowflakesLayer ( density = density , density_uniformity = density_uniformity , flake_size = flake_size , flake_size_uniformity = flake_size_uniformity , angle = angle , speed = speed , blur_sigma_fraction = ( 0.0001 , 0.001 ) )
return meta . SomeOf ( ( 1 , 3 ) , children = [ layer . deepcopy ( ) for _ in range ( 3 ) ] , random_order = False , name = name , deterministic = deterministic , random_state = random_state )


signature:
def get_arr_int ( self , background_threshold = 0.01 , background_class_id = None ) :
    """Get the segmentation map array as an integer array of shape ( H , W ) .
 Each pixel in that array contains an integer value representing the pixel ' s class .
 If multiple classes overlap , the one with the highest local float value is picked .
 If that highest local value is below ` background _ threshold ` , the method instead uses
 the background class id as the pixel ' s class value .
 By default , class id 0 is the background class . This may only be changed if the original
 input to the segmentation map object was an integer map .
 Parameters
 background _ threshold : float , optional
 At each pixel , each class - heatmap has a value between 0.0 and 1.0 . If none of the
 class - heatmaps has a value above this threshold , the method uses the background class
 id instead .
 background _ class _ id : None or int , optional
 Class id to fall back to if no class - heatmap passes the threshold at a spatial
 location . May only be provided if the original input was an integer mask and in these
 cases defaults to 0 . If the input were float or boolean masks , the background class id
 may not be set as it is assumed that the background is implicitly defined
 as ' any spatial location that has zero - like values in all masks ' .
 Returns
 result : ( H , W ) ndarray
 Segmentation map array ( int32 ) .
 If the original input consisted of boolean or float masks , then the highest possible
 class id is ` ` 1 + C ` ` , where ` ` C ` ` is the number of provided float / boolean masks . The value
 ` ` 0 ` ` in the integer mask then denotes the background class ."""

implementation:
if self . input_was [ 0 ] in [ "bool" , "float" ] :
    ia . do_assert ( background_class_id is None , "The background class id may only be changed if the original input to SegmentationMapOnImage " + "was an *integer* based segmentation map." )
if background_class_id is None :
    background_class_id = 0
channelwise_max_idx = np . argmax ( self . arr , axis = 2 )
# for bool and float input masks , we assume that the background is implicitly given ,
# i . e . anything where all masks / channels have zero - like values
# for int , we assume that the background class is explicitly given and has the index 0
if self . input_was [ 0 ] in [ "bool" , "float" ] :
    result = 1 + channelwise_max_idx
else : # integer mask was provided
    result = channelwise_max_idx
if background_threshold is not None and background_threshold > 0 :
    probs = np . amax ( self . arr , axis = 2 )
    result [ probs < background_threshold ] = background_class_id
return result . astype ( np . int32 )


signature:
def draw ( self , size = None , background_threshold = 0.01 , background_class_id = None , colors = None , return_foreground_mask = False ) :
    """Render the segmentation map as an RGB image .
 Parameters
 size : None or float or iterable of int or iterable of float , optional
 Size of the rendered RGB image as ` ` ( height , width ) ` ` .
 See : func : ` imgaug . imgaug . imresize _ single _ image ` for details .
 If set to None , no resizing is performed and the size of the segmentation map array is used .
 background _ threshold : float , optional
 See : func : ` imgaug . SegmentationMapOnImage . get _ arr _ int ` .
 background _ class _ id : None or int , optional
 See : func : ` imgaug . SegmentationMapOnImage . get _ arr _ int ` .
 colors : None or list of tuple of int , optional
 Colors to use . One for each class to draw . If None , then default colors will be used .
 return _ foreground _ mask : bool , optional
 Whether to return a mask of the same size as the drawn segmentation map , containing
 True at any spatial location that is not the background class and False everywhere else .
 Returns
 segmap _ drawn : ( H , W , 3 ) ndarray
 Rendered segmentation map ( dtype is uint8 ) .
 foreground _ mask : ( H , W ) ndarray
 Mask indicating the locations of foreground classes ( dtype is bool ) .
 This value is only returned if ` return _ foreground _ mask ` is True ."""

implementation:
arr = self . get_arr_int ( background_threshold = background_threshold , background_class_id = background_class_id )
nb_classes = 1 + np . max ( arr )
segmap_drawn = np . zeros ( ( arr . shape [ 0 ] , arr . shape [ 1 ] , 3 ) , dtype = np . uint8 )
if colors is None :
    colors = SegmentationMapOnImage . DEFAULT_SEGMENT_COLORS
ia . do_assert ( nb_classes <= len ( colors ) , "Can't draw all %d classes as it would exceed the maximum number of %d available colors." % ( nb_classes , len ( colors ) , ) )
ids_in_map = np . unique ( arr )
for c , color in zip ( sm . xrange ( nb_classes ) , colors ) :
    if c in ids_in_map :
        class_mask = ( arr == c )
        segmap_drawn [ class_mask ] = color
if return_foreground_mask :
    background_class_id = 0 if background_class_id is None else background_class_id
    foreground_mask = ( arr != background_class_id )
else :
    foreground_mask = None
if size is not None :
    segmap_drawn = ia . imresize_single_image ( segmap_drawn , size , interpolation = "nearest" )
    if foreground_mask is not None :
        foreground_mask = ia . imresize_single_image ( foreground_mask . astype ( np . uint8 ) , size , interpolation = "nearest" ) > 0
if foreground_mask is not None :
    return segmap_drawn , foreground_mask
return segmap_drawn


signature:
def draw_on_image ( self , image , alpha = 0.75 , resize = "segmentation_map" , background_threshold = 0.01 , background_class_id = None , colors = None , draw_background = False ) :
    """Draw the segmentation map as an overlay over an image .
 Parameters
 image : ( H , W , 3 ) ndarray
 Image onto which to draw the segmentation map . Dtype is expected to be uint8.
 alpha : float , optional
 Alpha / opacity value to use for the mixing of image and segmentation map .
 Higher values mean that the segmentation map will be more visible and the image less visible .
 resize : { ' segmentation _ map ' , ' image ' } , optional
 In case of size differences between the image and segmentation map , either the image or
 the segmentation map can be resized . This parameter controls which of the two will be
 resized to the other ' s size .
 background _ threshold : float , optional
 See : func : ` imgaug . SegmentationMapOnImage . get _ arr _ int ` .
 background _ class _ id : None or int , optional
 See : func : ` imgaug . SegmentationMapOnImage . get _ arr _ int ` .
 colors : None or list of tuple of int , optional
 Colors to use . One for each class to draw . If None , then default colors will be used .
 draw _ background : bool , optional
 If True , the background will be drawn like any other class .
 If False , the background will not be drawn , i . e . the respective background pixels
 will be identical with the image ' s RGB color at the corresponding spatial location
 and no color overlay will be applied .
 Returns
 mix : ( H , W , 3 ) ndarray
 Rendered overlays ( dtype is uint8 ) ."""

implementation:
# assert RGB image
ia . do_assert ( image . ndim == 3 )
ia . do_assert ( image . shape [ 2 ] == 3 )
ia . do_assert ( image . dtype . type == np . uint8 )
ia . do_assert ( 0 - 1e-8 <= alpha <= 1.0 + 1e-8 )
ia . do_assert ( resize in [ "segmentation_map" , "image" ] )
if resize == "image" :
    image = ia . imresize_single_image ( image , self . arr . shape [ 0 : 2 ] , interpolation = "cubic" )
segmap_drawn , foreground_mask = self . draw ( background_threshold = background_threshold , background_class_id = background_class_id , size = image . shape [ 0 : 2 ] if resize == "segmentation_map" else None , colors = colors , return_foreground_mask = True )
if draw_background :
    mix = np . clip ( ( 1 - alpha ) * image + alpha * segmap_drawn , 0 , 255 ) . astype ( np . uint8 )
else :
    foreground_mask = foreground_mask [ ... , np . newaxis ]
    mix = np . zeros_like ( image )
    mix += ( ~ foreground_mask ) . astype ( np . uint8 ) * image
    mix += foreground_mask . astype ( np . uint8 ) * np . clip ( ( 1 - alpha ) * image + alpha * segmap_drawn , 0 , 255 ) . astype ( np . uint8 )
return mix


signature:
def pad ( self , top = 0 , right = 0 , bottom = 0 , left = 0 , mode = "constant" , cval = 0.0 ) :
    """Pad the segmentation map on its top / right / bottom / left side .
 Parameters
 top : int , optional
 Amount of pixels to add at the top side of the segmentation map . Must be 0 or greater .
 right : int , optional
 Amount of pixels to add at the right side of the segmentation map . Must be 0 or greater .
 bottom : int , optional
 Amount of pixels to add at the bottom side of the segmentation map . Must be 0 or greater .
 left : int , optional
 Amount of pixels to add at the left side of the segmentation map . Must be 0 or greater .
 mode : str , optional
 Padding mode to use . See : func : ` numpy . pad ` for details .
 cval : number , optional
 Value to use for padding if ` mode ` is ` ` constant ` ` . See : func : ` numpy . pad ` for details .
 Returns
 segmap : imgaug . SegmentationMapOnImage
 Padded segmentation map of height ` ` H ' = H + top + bottom ` ` and width ` ` W ' = W + left + right ` ` ."""

implementation:
arr_padded = ia . pad ( self . arr , top = top , right = right , bottom = bottom , left = left , mode = mode , cval = cval )
segmap = SegmentationMapOnImage ( arr_padded , shape = self . shape )
segmap . input_was = self . input_was
return segmap


signature:
def pad_to_aspect_ratio ( self , aspect_ratio , mode = "constant" , cval = 0.0 , return_pad_amounts = False ) :
    """Pad the segmentation map on its sides so that its matches a target aspect ratio .
 Depending on which dimension is smaller ( height or width ) , only the corresponding
 sides ( left / right or top / bottom ) will be padded . In each case , both of the sides will
 be padded equally .
 Parameters
 aspect _ ratio : float
 Target aspect ratio , given as width / height . E . g . 2.0 denotes the image having twice
 as much width as height .
 mode : str , optional
 Padding mode to use . See : func : ` numpy . pad ` for details .
 cval : number , optional
 Value to use for padding if ` mode ` is ` ` constant ` ` . See : func : ` numpy . pad ` for details .
 return _ pad _ amounts : bool , optional
 If False , then only the padded image will be returned . If True , a tuple with two
 entries will be returned , where the first entry is the padded image and the second
 entry are the amounts by which each image side was padded . These amounts are again a
 tuple of the form ( top , right , bottom , left ) , with each value being an integer .
 Returns
 segmap : imgaug . SegmentationMapOnImage
 Padded segmentation map as SegmentationMapOnImage object .
 pad _ amounts : tuple of int
 Amounts by which the segmentation map was padded on each side , given as a
 tuple ` ` ( top , right , bottom , left ) ` ` .
 This tuple is only returned if ` return _ pad _ amounts ` was set to True ."""

implementation:
arr_padded , pad_amounts = ia . pad_to_aspect_ratio ( self . arr , aspect_ratio = aspect_ratio , mode = mode , cval = cval , return_pad_amounts = True )
segmap = SegmentationMapOnImage ( arr_padded , shape = self . shape )
segmap . input_was = self . input_was
if return_pad_amounts :
    return segmap , pad_amounts
else :
    return segmap


signature:
def resize ( self , sizes , interpolation = "cubic" ) :
    """Resize the segmentation map array to the provided size given the provided interpolation .
 Parameters
 sizes : float or iterable of int or iterable of float
 New size of the array in ` ` ( height , width ) ` ` .
 See : func : ` imgaug . imgaug . imresize _ single _ image ` for details .
 interpolation : None or str or int , optional
 The interpolation to use during resize .
 See : func : ` imgaug . imgaug . imresize _ single _ image ` for details .
 Note : The segmentation map is internally stored as multiple float - based heatmaps ,
 making smooth interpolations potentially more reasonable than nearest neighbour
 interpolation .
 Returns
 segmap : imgaug . SegmentationMapOnImage
 Resized segmentation map object ."""

implementation:
arr_resized = ia . imresize_single_image ( self . arr , sizes , interpolation = interpolation )
# cubic interpolation can lead to values outside of [ 0.0 , 1.0 ] ,
# see https : / / github . com / opencv / opencv / issues / 7195
# TODO area interpolation too ?
arr_resized = np . clip ( arr_resized , 0.0 , 1.0 )
segmap = SegmentationMapOnImage ( arr_resized , shape = self . shape )
segmap . input_was = self . input_was
return segmap


signature:
def to_heatmaps ( self , only_nonempty = False , not_none_if_no_nonempty = False ) :
    """Convert segmentation map to heatmaps object .
 Each segmentation map class will be represented as a single heatmap channel .
 Parameters
 only _ nonempty : bool , optional
 If True , then only heatmaps for classes that appear in the segmentation map will be
 generated . Additionally , a list of these class ids will be returned .
 not _ none _ if _ no _ nonempty : bool , optional
 If ` only _ nonempty ` is True and for a segmentation map no channel was non - empty ,
 this function usually returns None as the heatmaps object . If however this parameter
 is set to True , a heatmaps object with one channel ( representing class 0)
 will be returned as a fallback in these cases .
 Returns
 imgaug . HeatmapsOnImage or None
 Segmentation map as a heatmaps object .
 If ` only _ nonempty ` was set to True and no class appeared in the segmentation map ,
 then this is None .
 class _ indices : list of int
 Class ids ( 0 to C - 1 ) of the classes that were actually added to the heatmaps .
 Only returned if ` only _ nonempty ` was set to True ."""

implementation:
# TODO get rid of this deferred import
from imgaug . augmentables . heatmaps import HeatmapsOnImage
if not only_nonempty :
    return HeatmapsOnImage . from_0to1 ( self . arr , self . shape , min_value = 0.0 , max_value = 1.0 )
else :
    nonempty_mask = np . sum ( self . arr , axis = ( 0 , 1 ) ) > 0 + 1e-4
    if np . sum ( nonempty_mask ) == 0 :
        if not_none_if_no_nonempty :
            nonempty_mask [ 0 ] = True
        else :
            return None , [ ]
    class_indices = np . arange ( self . arr . shape [ 2 ] ) [ nonempty_mask ]
    channels = self . arr [ ... , class_indices ]
    return HeatmapsOnImage ( channels , self . shape , min_value = 0.0 , max_value = 1.0 ) , class_indices


signature:
def from_heatmaps ( heatmaps , class_indices = None , nb_classes = None ) :
    """Convert heatmaps to segmentation map .
 Assumes that each class is represented as a single heatmap channel .
 Parameters
 heatmaps : imgaug . HeatmapsOnImage
 Heatmaps to convert .
 class _ indices : None or list of int , optional
 List of class indices represented by each heatmap channel . See also the
 secondary output of : func : ` imgaug . SegmentationMapOnImage . to _ heatmap ` .
 If this is provided , it must have the same length as the number of heatmap channels .
 nb _ classes : None or int , optional
 Number of classes . Must be provided if class _ indices is set .
 Returns
 imgaug . SegmentationMapOnImage
 Segmentation map derived from heatmaps ."""

implementation:
if class_indices is None :
    return SegmentationMapOnImage ( heatmaps . arr_0to1 , shape = heatmaps . shape )
else :
    ia . do_assert ( nb_classes is not None )
    ia . do_assert ( min ( class_indices ) >= 0 )
    ia . do_assert ( max ( class_indices ) < nb_classes )
    ia . do_assert ( len ( class_indices ) == heatmaps . arr_0to1 . shape [ 2 ] )
    arr_0to1 = heatmaps . arr_0to1
    arr_0to1_full = np . zeros ( ( arr_0to1 . shape [ 0 ] , arr_0to1 . shape [ 1 ] , nb_classes ) , dtype = np . float32 )
    for heatmap_channel , mapped_channel in enumerate ( class_indices ) :
        arr_0to1_full [ : , : , mapped_channel ] = arr_0to1 [ : , : , heatmap_channel ]
    return SegmentationMapOnImage ( arr_0to1_full , shape = heatmaps . shape )


signature:
def deepcopy ( self ) :
    """Create a deep copy of the segmentation map object .
 Returns
 imgaug . SegmentationMapOnImage
 Deep copy ."""

implementation:
segmap = SegmentationMapOnImage ( self . arr , shape = self . shape , nb_classes = self . nb_classes )
segmap . input_was = self . input_was
return segmap


signature:
def get_arr ( self ) :
    """Get the heatmap ' s array within the value range originally provided in ` ` _ _ init _ _ ( ) ` ` .
 The HeatmapsOnImage object saves heatmaps internally in the value range ` ` ( min = 0.0 , max = 1.0 ) ` ` .
 This function converts the internal representation to ` ` ( min = min _ value , max = max _ value ) ` ` ,
 where ` ` min _ value ` ` and ` ` max _ value ` ` are provided upon instantiation of the object .
 Returns
 result : ( H , W ) ndarray or ( H , W , C ) ndarray
 Heatmap array . Dtype is float32."""

implementation:
if self . arr_was_2d and self . arr_0to1 . shape [ 2 ] == 1 :
    arr = self . arr_0to1 [ : , : , 0 ]
else :
    arr = self . arr_0to1
eps = np . finfo ( np . float32 ) . eps
min_is_zero = 0.0 - eps < self . min_value < 0.0 + eps
max_is_one = 1.0 - eps < self . max_value < 1.0 + eps
if min_is_zero and max_is_one :
    return np . copy ( arr )
else :
    diff = self . max_value - self . min_value
    return self . min_value + diff * arr


signature:
def draw ( self , size = None , cmap = "jet" ) :
    """Render the heatmaps as RGB images .
 Parameters
 size : None or float or iterable of int or iterable of float , optional
 Size of the rendered RGB image as ` ` ( height , width ) ` ` .
 See : func : ` imgaug . imgaug . imresize _ single _ image ` for details .
 If set to None , no resizing is performed and the size of the heatmaps array is used .
 cmap : str or None , optional
 Color map of ` ` matplotlib ` ` to use in order to convert the heatmaps to RGB images .
 If set to None , no color map will be used and the heatmaps will be converted
 to simple intensity maps .
 Returns
 heatmaps _ drawn : list of ( H , W , 3 ) ndarray
 Rendered heatmaps . One per heatmap array channel . Dtype is uint8."""

implementation:
heatmaps_uint8 = self . to_uint8 ( )
heatmaps_drawn = [ ]
for c in sm . xrange ( heatmaps_uint8 . shape [ 2 ] ) : # c : c + 1 here , because the additional axis is needed by imresize _ single _ image
    heatmap_c = heatmaps_uint8 [ ... , c : c + 1 ]
    if size is not None :
        heatmap_c_rs = ia . imresize_single_image ( heatmap_c , size , interpolation = "nearest" )
    else :
        heatmap_c_rs = heatmap_c
    heatmap_c_rs = np . squeeze ( heatmap_c_rs ) . astype ( np . float32 ) / 255.0
    if cmap is not None : # import only when necessary ( faster startup ; optional dependency ; less fragile - - see issue # 225)
        import matplotlib . pyplot as plt
        cmap_func = plt . get_cmap ( cmap )
        heatmap_cmapped = cmap_func ( heatmap_c_rs )
        heatmap_cmapped = np . delete ( heatmap_cmapped , 3 , 2 )
    else :
        heatmap_cmapped = np . tile ( heatmap_c_rs [ ... , np . newaxis ] , ( 1 , 1 , 3 ) )
    heatmap_cmapped = np . clip ( heatmap_cmapped * 255 , 0 , 255 ) . astype ( np . uint8 )
    heatmaps_drawn . append ( heatmap_cmapped )
return heatmaps_drawn


signature:
def draw_on_image ( self , image , alpha = 0.75 , cmap = "jet" , resize = "heatmaps" ) :
    """Draw the heatmaps as overlays over an image .
 Parameters
 image : ( H , W , 3 ) ndarray
 Image onto which to draw the heatmaps . Expected to be of dtype uint8.
 alpha : float , optional
 Alpha / opacity value to use for the mixing of image and heatmaps .
 Higher values mean that the heatmaps will be more visible and the image less visible .
 cmap : str or None , optional
 Color map to use . See : func : ` imgaug . HeatmapsOnImage . draw ` for details .
 resize : { ' heatmaps ' , ' image ' } , optional
 In case of size differences between the image and heatmaps , either the image or
 the heatmaps can be resized . This parameter controls which of the two will be resized
 to the other ' s size .
 Returns
 mix : list of ( H , W , 3 ) ndarray
 Rendered overlays . One per heatmap array channel . Dtype is uint8."""

implementation:
# assert RGB image
ia . do_assert ( image . ndim == 3 )
ia . do_assert ( image . shape [ 2 ] == 3 )
ia . do_assert ( image . dtype . type == np . uint8 )
ia . do_assert ( 0 - 1e-8 <= alpha <= 1.0 + 1e-8 )
ia . do_assert ( resize in [ "heatmaps" , "image" ] )
if resize == "image" :
    image = ia . imresize_single_image ( image , self . arr_0to1 . shape [ 0 : 2 ] , interpolation = "cubic" )
heatmaps_drawn = self . draw ( size = image . shape [ 0 : 2 ] if resize == "heatmaps" else None , cmap = cmap )
mix = [ np . clip ( ( 1 - alpha ) * image + alpha * heatmap_i , 0 , 255 ) . astype ( np . uint8 ) for heatmap_i in heatmaps_drawn ]
return mix