Layout-Parser / layout-parser

A Unified Toolkit for Deep Learning Based Document Image Analysis
https://layout-parser.github.io/
Apache License 2.0
4.67k stars 449 forks source link

Better Visualization Functions #129

Closed lolipopshock closed 2 years ago

lolipopshock commented 2 years ago
  1. Not drawing the box outlines when setting box_width=0. For example,

    from PIL import Image
    import layoutparser as lp
    
    image = Image.new('RGB', (50,50), color='white')
    lp.draw_box(image, [lp.Rectangle(10, 10, 40, 40)], box_width=0)

    Previously, it will draw a box image.

  2. Allowing setting box_color in draw_box:

    1. directly setting box_color:

      from PIL import Image
      import layoutparser as lp
      
      image = Image.new('RGB', (50,50), color='white')
      
      lp.draw_box(image, 
                  [lp.TextBlock(lp.Rectangle(10, 10, 20, 20), type='a'), 
                  lp.TextBlock(lp.Rectangle(30, 30, 45, 45), type='b'),] ,
                  box_color=['black', 'red'])

      image

    2. overriding color_map:

      lp.draw_box(image, 
                  [lp.TextBlock(lp.Rectangle(10, 10, 20, 20), type='a'), 
                  lp.TextBlock(lp.Rectangle(30, 30, 45, 45), type='b'),] ,
                  color_map={'a':'black', 'b':'blue'}, box_color=['black', 'red'])

      image

  3. Setting box_color, box_alpha, and box_width for each objects:

    from PIL import Image
    import layoutparser as lp
    
    image = Image.new('RGB', (50,50), color='white')
    lp.draw_box(image, 
                [lp.TextBlock(lp.Rectangle(10, 10, 20, 20), type='a'), 
                lp.TextBlock(lp.Rectangle(30, 30, 45, 45), type='b'),] ,
                box_color=['black', 'red'], 
                box_alpha=[0.1, 0.5], 
                box_width=[2,4])

    image