Image.strhcat#

classmethod Image.strhcat(*images: Image, widths: int | Sequence[int] = 1, arraysep: str = ' |', labels: Sequence[str] | None = None) → str[source][source]#

Format several small images concatenated horizontally

Parameters:
  • images (Image instances) – one or more images to be formatted horizontally concatenated

  • widths (int or list of ints, optional) – number of digits for the formatted array elements, defaults to 1. If scalar applies to all images, if list applies to each image.

  • arraysep (str, optional) – separator between arrays, defaults to " |"

  • labels (list of str, optional) – list of labels for each array, defaults to None

Returns:

multiline string containing formatted arrays

Return type:

str

Raises:

ValueError – if the arrays have different numbers of rows

AUTO_EDIT

For image processing this is useful for displaying small test images.

The arrays are formatted and concatenated horizontally with a vertical separator. Each array has a header row that indicates the column number. Each row has a header column that indicates the row number.

>>> from machinevisiontoolbox import Image
>>> A = Image.Random(size=(5,5), maxval=9)
>>> print(Image.strhcat(A))

      0 1 2 3 4  
      - - - - -  
  0:  1 1 3 3 0
  1:  6 0 8 2 3
  2:  4 1 2 8 4
  3:  2 7 1 1 0
  4:  2 2 5 6 6
>>> print(Image.strhcat(A, widths=2))

       0  1  2  3  4  
       -  -  -  -  -  
  0:   1  1  3  3  0
  1:   6  0  8  2  3
  2:   4  1  2  8  4
  3:   2  7  1  1  0
  4:   2  2  5  6  6
>>> B = Image.Random(size=(5,5), maxval=9)
>>> print(Image.strhcat(A, B))

      0 1 2 3 4   0 1 2 3 4  
      - - - - -   - - - - -  
  0:  1 1 3 3 0 | 7 2 8 5 4
  1:  6 0 8 2 3 | 3 1 2 8 2
  2:  4 1 2 8 4 | 0 7 7 3 8
  3:  2 7 1 1 0 | 7 3 7 7 7
  4:  2 2 5 6 6 | 4 0 1 6 6
>>> print(Image.strhcat(A, B, labels=("A:", "B:")))
     A:          B:
      0 1 2 3 4   0 1 2 3 4  
      - - - - -   - - - - -  
  0:  1 1 3 3 0 | 7 2 8 5 4
  1:  6 0 8 2 3 | 3 1 2 8 2
  2:  4 1 2 8 4 | 0 7 7 3 8
  3:  2 7 1 1 0 | 7 3 7 7 7
  4:  2 2 5 6 6 | 4 0 1 6 6

The number of rows in each image must be the same, but the number of columns can vary.

Seealso:

Image.print Image.showpixels Image