#NEWLINE# def rasterize_landmarks_2d( image , group = None , render_lines = True , line_style = '-' , line_colour = 'b' , line_width = 1 , render_markers = True , marker_style = 'o' , marker_size = 1 , marker_face_colour = 'b' , marker_edge_colour = 'b' , marker_edge_width = 1 , backend = 'matplotlib' ) : #NEWLINE# #INDENT# "\n    This method provides the ability to rasterize 2D landmarks onto an image.\n    The returned image has the specified landmark groups rasterized onto\n    the image - which is useful for things like creating result examples\n    or rendering videos with annotations.\n\n    Since multiple landmark groups can be specified, all arguments can\n    take lists of parameters that map to the provided groups list. Therefore,\n    the parameters must be lists of the correct length or a single parameter\n    to apply to every landmark group.\n\n    Multiple backends are provided, all with different strengths. The 'pillow'\n    backend is very fast, but not very flexible. The `matplotlib` backend\n    should be feature compatible with other Menpo rendering methods, but\n    is much slower due to the overhead of creating a figure to render\n    into.\n\n    Parameters\n    ----------\n    image : :map:`Image` or subclass\n        The image to render onto.\n    group : `str` or `list` of `str`, optional\n        The landmark group key, or a list of keys.\n    render_lines : `bool`, optional\n        If ``True``, and the provided landmark group is a :map:`PointGraph`,\n        the edges are rendered.\n    line_style : `str`, optional\n        The style of the edge line. Not all backends support this argument.\n    line_colour : `str` or `tuple`, optional\n        A Matplotlib style colour or a backend dependant colour.\n    line_width : `int`, optional\n        The width of the line to rasterize.\n    render_markers : `bool`, optional\n        If ``True``, render markers at the coordinates of each landmark.\n    marker_style : `str`, optional\n        A Matplotlib marker style. Not all backends support all marker styles.\n    marker_size : `int`, optional\n        The size of the marker - different backends use different scale\n        spaces so consistent output may by difficult.\n    marker_face_colour : `str`, optional\n        A Matplotlib style colour or a backend dependant colour.\n    marker_edge_colour : `str`, optional\n        A Matplotlib style colour or a backend dependant colour.\n    marker_edge_width : `int`, optional\n        The width of the marker edge. Not all backends support this.\n    backend : {'matplotlib', 'pillow'}, optional\n        The backend to use.\n\n    Returns\n    -------\n    rasterized_image : :map:`Image`\n        The image with the landmarks rasterized directly into the pixels.\n\n    Raises\n    ------\n    ValueError\n        Only 2D images are supported.\n    ValueError\n        Only RGB (3-channel) or Greyscale (1-channel) images are supported.\n    " #NEWLINE# if ( ( image . n_channels != 1 ) and ( image . n_channels != 3 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Only RGB or Greyscale images can be rasterized' ) #NEWLINE# #UNINDENT# if ( image . n_dims != 2 ) : #NEWLINE# #INDENT# raise ValueError ( 'Only 2D images can be rasterized.' ) #NEWLINE# #UNINDENT# if ( backend in _RASTERIZE_BACKENDS ) : #NEWLINE# #INDENT# if isinstance ( group , list ) : #NEWLINE# #INDENT# landmarks = [ image . landmarks [ g ] . lms for g in group ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# landmarks = [ image . landmarks [ group ] . lms ] #NEWLINE# #UNINDENT# n_pclouds = len ( landmarks ) #NEWLINE# render_lines = check_param ( n_pclouds , bool , 'render_lines' , render_lines ) #NEWLINE# line_style = check_param ( n_pclouds , basestring , 'line_style' , line_style ) #NEWLINE# line_colour = check_param ( n_pclouds , ( basestring , tuple ) , 'line_colour' , line_colour ) #NEWLINE# line_width = check_param ( n_pclouds , int , 'line_width' , line_width ) #NEWLINE# render_markers = check_param ( n_pclouds , bool , 'render_markers' , render_markers ) #NEWLINE# marker_style = check_param ( n_pclouds , basestring , 'marker_style' , marker_style ) #NEWLINE# marker_size = check_param ( n_pclouds , int , 'marker_size' , marker_size ) #NEWLINE# marker_face_colour = check_param ( n_pclouds , ( basestring , tuple ) , 'marker_face_colour' , marker_face_colour ) #NEWLINE# marker_edge_colour = check_param ( n_pclouds , ( basestring , tuple ) , 'marker_edge_colour' , marker_edge_colour ) #NEWLINE# marker_edge_width = check_param ( n_pclouds , int , 'marker_edge_width' , marker_edge_width ) #NEWLINE# return _RASTERIZE_BACKENDS [ backend ] ( image , landmarks , render_lines = render_lines , line_style = line_style , line_colour = line_colour , line_width = line_width , render_markers = render_markers , marker_style = marker_style , marker_size = marker_size , marker_face_colour = marker_face_colour , marker_edge_colour = marker_edge_colour , marker_edge_width = marker_edge_width ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'Unsupported backend: {}' . format ( backend ) )