Draw the layout region on the input canvas(image). Args: canvas (:obj:`~np.ndarray` or :obj:`~PIL.Image.Image`): The canvas to draw the layout boxes. layout (:obj:`Layout` or :obj:`list`): The layout of the canvas to show. box_width (:obj:`int` or
(
canvas: Image.Image,
layout: Layout,
box_width: Optional[Union[List[int], int]] = None,
box_alpha: Optional[Union[List[float], float]] = None,
box_color: Optional[Union[List[str], str]] = None,
color_map: Optional[Dict] = None,
show_element_id: bool = False,
show_element_type: bool = False,
id_font_size: Optional[int] = None,
id_font_path: Optional[str] = None,
id_text_color: Optional[str] = None,
id_text_background_color: Optional[str] = None,
id_text_background_alpha: Optional[float] = 1,
)
| 223 | |
| 224 | @image_loader |
| 225 | def draw_box( |
| 226 | canvas: Image.Image, |
| 227 | layout: Layout, |
| 228 | box_width: Optional[Union[List[int], int]] = None, |
| 229 | box_alpha: Optional[Union[List[float], float]] = None, |
| 230 | box_color: Optional[Union[List[str], str]] = None, |
| 231 | color_map: Optional[Dict] = None, |
| 232 | show_element_id: bool = False, |
| 233 | show_element_type: bool = False, |
| 234 | id_font_size: Optional[int] = None, |
| 235 | id_font_path: Optional[str] = None, |
| 236 | id_text_color: Optional[str] = None, |
| 237 | id_text_background_color: Optional[str] = None, |
| 238 | id_text_background_alpha: Optional[float] = 1, |
| 239 | ): |
| 240 | """Draw the layout region on the input canvas(image). |
| 241 | |
| 242 | Args: |
| 243 | canvas (:obj:`~np.ndarray` or :obj:`~PIL.Image.Image`): |
| 244 | The canvas to draw the layout boxes. |
| 245 | layout (:obj:`Layout` or :obj:`list`): |
| 246 | The layout of the canvas to show. |
| 247 | box_width (:obj:`int` or :obj:`List[int]`, optional): |
| 248 | Set to change the width of the drawn layout box boundary. |
| 249 | Defaults to None, when the boundary is automatically |
| 250 | calculated as the the :const:`DEFAULT_BOX_WIDTH_RATIO` |
| 251 | * the maximum of (height, width) of the canvas. |
| 252 | If box_with is a list, it will assign different widths to |
| 253 | the corresponding layout object, and should have the same |
| 254 | length as the number of blocks in `layout`. |
| 255 | box_alpha (:obj:`float` or :obj:`List[float]`, optional): |
| 256 | A float or list of floats ranging from 0 to 1. Set to change |
| 257 | the alpha of the drawn layout box. |
| 258 | Defaults to 0 - the layout box will be fully transparent. |
| 259 | If box_alpha is a list of floats, it will assign different |
| 260 | alphas to the corresponding layout object, and should have |
| 261 | the same length as the number of blocks in `layout`. |
| 262 | box_color (:obj:`str` or :obj:`List[str]`, optional): |
| 263 | A string or a list of strings for box colors, e.g., |
| 264 | `['red', 'green', 'blue']` or `'red'`. |
| 265 | If box_color is a list of strings, it will assign different |
| 266 | colors to the corresponding layout object, and should have |
| 267 | the same length as the number of blocks in `layout`. |
| 268 | Defaults to None. When `box_color` is set, it will override the |
| 269 | `color_map`. |
| 270 | color_map (dict, optional): |
| 271 | A map from `block.type` to the colors, e.g., `{1: 'red'}`. |
| 272 | You can set it to `{}` to use only the |
| 273 | :const:`DEFAULT_OUTLINE_COLOR` for the outlines. |
| 274 | Defaults to None, when a color palette is is automatically |
| 275 | created based on the input layout. |
| 276 | show_element_id (bool, optional): |
| 277 | Whether to display `block.id` on the top-left corner of |
| 278 | the block. |
| 279 | Defaults to False. |
| 280 | show_element_type (bool, optional): |
| 281 | Whether to display `block.type` on the top-left corner of |
| 282 | the block. |