Skip to content

Braille#

This style uses the characters of the Braille writing system.

Example

Consider the following image:

Apple logo

Apple Computer [Rob Janoff, 1977]

Here's what it should look like:

Apple logo in text (Braille style)

Encoding

Traditional Braille characters are made up of 6 dots (⠿). Since each dot could be in one of 2 states (raised or lowered), there are a total of 64 unique combinations.

In Unicode, braille is represented in a block, the Braille Patterns. There are 256 unique characters each in its own 8-dot cell (⣿).

Procedure#

This style is implemented using the BrailleDrawer.

Styling

Refer to the procedure outlined in the Styles documentation for an overview of the steps common to all styles.

Initialization#

Threshold#

The threshold parameter filters out pixels of the input image whose grayscale intensities are lesser than it.

Consider the following image:

Contributions

Tiles ressembling GitHub contributions

Here's what it should look like:

Contributions in text (Braille Threshold 0)

Contributions in text (Braille Threshold 70)

Contributions in text (Braille Threshold 108)

Contributions in text (Braille Threshold 168)

Contributions in text (Braille Threshold 210)

Matrices#

The kernel attribute holds a NumPy ndarray containing the following matrix:

\[ kernel = \begin{bmatrix} 1 & 8\\ 2 & 16\\ 4 & 32\\ 64 & 128\end{bmatrix} \]

The Unicode encoding of the 8-dot cell Braille system is done by assigning each of the dots a power of 2. Each character in the Braille Patterns block has a unique Unicode value that is obtained by summing these powers.

The charset_array attribute holds another NumPy ndarray containing all 256 Braille characters.

Conversion#

Resizing#

Assuming the output text should have the dimensions text_height and text_width, the image must be resized according to the following criteria:

  • image_height = 4 * text_height.
  • image_width = 2 * text_width.
  • If either image_height or image_width is 0, it is derived from the other by preserving the aspect ratio of the original image.

Following the above algorithm, each pixel of the resized image will be assigned to one dot (Braille character dot) in the output text.

Source

Refer to the calculate_size function for more information.

Processing#

  1. The resized image is first converted to its grayscale.
  2. Each pixel is set to either 0 or 1 based on whether its grayscale intensity is below or above the threshold.
  3. A convolution operation is performed on this filtered image using the kernel matrix. The resultant matrix has the ofsetted Unicode values for the corresponding Braille character.
  4. The charset_array is indexed with the resultant "indices" matrix, giving the final text_matrix.
Processing an image into a text matrix (Braille style)
Source

Refer to the process function for more information.