MikkoLipsanen commited on
Commit
b776049
·
verified ·
1 Parent(s): c99fa8d

Update plotting functions

Browse files
Files changed (1) hide show
  1. plotting_functions.py +7 -11
plotting_functions.py CHANGED
@@ -3,7 +3,7 @@ from PIL import Image, ImageDraw
3
 
4
  class PlotHTR:
5
  def __init__(self, region_alpha = 0.3, line_alpha = 0.3):
6
- self.region_colors = {'marginalia': (0,201,87), 'page-number': (0,0,255), 'paragraph': (238,18,137), 'case-start': (238,18,137)}
7
  self.region_alpha = region_alpha
8
  self.line_alpha = line_alpha
9
 
@@ -12,14 +12,10 @@ class PlotHTR:
12
  img = image.copy()
13
  draw = ImageDraw.Draw(img)
14
  for region in region_data:
15
- region_type = region['region_name']
16
  img_h, img_w = region['img_shape']
17
  region_polygon = list(map(tuple, region['region_coords']))
18
-
19
- color = self.region_colors[region_type]
20
-
21
- draw.polygon(region_polygon, fill = color, outline='black')
22
- # Lower alpha value is applied to filled polygons to make them transparent
23
  blended_img = Image.blend(image, img, self.region_alpha)
24
  return blended_img
25
 
@@ -30,10 +26,10 @@ class PlotHTR:
30
  for region in region_data:
31
  img_h, img_w = region['img_shape']
32
  line_polygons = region['lines']
33
- region_type = region['region_name']
34
- color = self.region_colors[region_type]
35
  for i, polygon in enumerate(line_polygons):
36
- draw.polygon(polygon, fill = color)
 
37
  # Lower alpha value is applied to filled polygons to make them transparent
38
  blended_img = Image.blend(image, img, self.line_alpha)
39
- return blended_img
 
3
 
4
  class PlotHTR:
5
  def __init__(self, region_alpha = 0.3, line_alpha = 0.3):
6
+ self.polygon_color = (238,18,137)
7
  self.region_alpha = region_alpha
8
  self.line_alpha = line_alpha
9
 
 
12
  img = image.copy()
13
  draw = ImageDraw.Draw(img)
14
  for region in region_data:
 
15
  img_h, img_w = region['img_shape']
16
  region_polygon = list(map(tuple, region['region_coords']))
17
+ draw.polygon(region_polygon, fill = self.polygon_color, outline='black')
18
+ # Lower alpha value is applied to filled polygons to make them transparent
 
 
 
19
  blended_img = Image.blend(image, img, self.region_alpha)
20
  return blended_img
21
 
 
26
  for region in region_data:
27
  img_h, img_w = region['img_shape']
28
  line_polygons = region['lines']
29
+ print(f'{len(line_polygons)} text lines')
 
30
  for i, polygon in enumerate(line_polygons):
31
+ line_polygon = list(map(tuple, polygon))
32
+ draw.polygon(line_polygon, fill = self.polygon_color, outline='black')
33
  # Lower alpha value is applied to filled polygons to make them transparent
34
  blended_img = Image.blend(image, img, self.line_alpha)
35
+ return blended_img