ImageGrids
ClassSource
ImageGrids(
n_cols: int,
*,
width: int = 1024,
margins: tuple[int, int] = (0, 0),
gaps: tuple[int, int] = (0, 0),
bg_color: str | tuple[float, ...] | None = None,
fmt: str | ImageFormat = "png"
)
ImageGrids(
n_rows: int,
*,
height: int = 1024,
margins: tuple[int, int] = (0, 0),
gaps: tuple[int, int] = (0, 0),
bg_color: str | tuple[float, ...] | None = None,
fmt: str | ImageFormat = "png"
)
ImageGrids(
n_rows: int,
n_cols: int,
*,
width: int = 1024,
height: int = 1024,
margins: tuple[int, int] = (0, 0),
gaps: tuple[int, int] = (0, 0),
bg_color: str | tuple[float, ...] | None = None,
fmt: str | ImageFormat = "png"
)
The tool used for creating grided images.
Its design is similar to matplotlib's subplots.
Arguments
Initialization.
ver. 1
| Name | Type | Required | |
|---|---|---|---|
n_cols | int | The number of rows in the grid. | |
width | int | The width of the image. This width will be uniformly divided according to n_cols. | |
margins | tuple[int, int] | The (horizontal_margin, vertical_margin) padded to the image. | |
gaps | tuple[int, int] | The (x_gap, y_gap) defining the separations among images. | |
bg_color | str | tuple[float, ...] | None | The background color of the whole image. If this value is None, will use transparent background. | |
fmt | str | ImageFormat | The format of the image. It is used only when saving this image. |
ver. 2
| Name | Type | Required | |
|---|---|---|---|
n_rows | int | The number of rows in the grid. | |
height | int | The height of the image. This height will be uniformly divided according to n_rows. | |
margins | tuple[int, int] | The (horizontal_margin, vertical_margin) padded to the image. | |
gaps | tuple[int, int] | The (x_gap, y_gap) defining the separations among images. | |
bg_color | str | tuple[float, ...] | None | The background color of the whole image. If this value is None, will use transparent background. | |
fmt | str | ImageFormat | The format of the image. It is used only when saving this image. |
ver. 3
| Name | Type | Required | |
|---|---|---|---|
n_rows | int | When both rows and cols are specified, this container will has a number limit of specified figures. | |
n_cols | int | When both rows and cols are specified, this container will has a number limit of specified figures. | |
width | int | The size of the image. The width and height will be uniformly divided. | |
height | int | The size of the image. The width and height will be uniformly divided. | |
margins | tuple[int, int] | The (horizontal_margin, vertical_margin) padded to the image. | |
gaps | tuple[int, int] | The (x_gap, y_gap) defining the separations among images. | |
bg_color | str | tuple[float, ...] | None | The background color of the whole image. If this value is None, will use transparent background. | |
fmt | str | ImageFormat | The format of the image. It is used only when saving this image. |
Methods
append
self.append(img: Image | ImageProtocol)
Add an image to this grid.
The image added by this method will be placed after previously registered images.
Requires
| Name | Type | Required | |
|---|---|---|---|
img | Image | ImageProtocol | The image instance to be registered. |
clear
self.clear()
Remove all images registered to this storage.
items
(v_1: tuple[int, int], v_2: ImageProtocol) in self.items()
Iterate all indicies and corresponding images.
Yields
| Name | Type | |
|---|---|---|
v_1 | tuple[int, int] | The (row, col) index. |
v_2 | ImageProtocol | The image corresponding to the index. |
pop
v_1: ImageProtocol = self.pop(row: int, col: int)
Remove the image in the storage, and return it.
Requires
| Name | Type | Required | |
|---|---|---|---|
row | int | ||
col | int | The indicies along the row and column axes. |
Returns
| Name | Type | |
|---|---|---|
v_1 | ImageProtocol | The image removed from the storage. Will raise |
Properties
img
img: ImageMultiLayer = self.img
Render the multi-layer image.
n_cols
n_cols: int = self.n_cols
Get the number of columns based on the currently registered images.
n_rows
n_rows: int = self.n_rows
Get the number of rows based on the currently registered images.
Operators
__contains__
flag: bool = idx in self
Test whether the index exists in the grid.
Requires
| Name | Type | Required | |
|---|---|---|---|
idx | tuple[int, int] | The (row, col) index. |
Returns
| Name | Type | |
|---|---|---|
v_1 | bool | Whether the given index is in the grid. |
__delitem__
del self[idx]
Remove the image in this grid.
Requires
| Name | Type | Required | |
|---|---|---|---|
idx | tuple[int, int] | The (row, col) index. |
__getitem__
idx: tuple[int, int]
v_1: ImageProtocol = self[idx]
Get the image stored in this grid.
Requires
| Name | Type | Required | |
|---|---|---|---|
idx | tuple[int, int] | The (row, col) index. |
Returns
| Name | Type | |
|---|---|---|
v_1 | ImageProtocol | The image in the storage. Will raise |
__iter__
for (v_1, v_2) in self:
v_1: int
v_2: int
Iterate all (row, col) indicies in the order of row-col.
Yields
| Name | Type | |
|---|---|---|
v_1 | int | The row index. |
v_2 | int | The col index. |
__setitem__
val: Image | ImageProtocol
self[idx] = val
Add the image to this grid.
Requires
| Name | Type | Required | |
|---|---|---|---|
idx | tuple[int, int] | The (row, col) index. | |
val | Image | ImageProtocol | The image in the to be configured in the storage. Will raise |