# Problem 1199. ASCII art

Convert a grayscale image to ASCII

Inputs:

• img: Grayscale image (a matrix of values between 0 and 1)
• chars: Char array of valid ascii characters
• bitmap: Grayscale images of each valid ascii character (3d matrix with size Height x Width x N, and with values between 0 and 1)

Output:

Bin the original image img into segments of size Height x Width, and find the best matching ascii character for each bin (minimizing the euclidean distance between each bin grayscale values and the matching character grayscale values).

Return the fitted ascii image: a matrix of characters in chars that, when displayed, approximates the image img.

```                              _____
QQÊÊÊÊþ¿_
gÊÊÊÊÊÊÊÊÊþ
qÊÊÊÊÊÊÊÑÑÊÊg_                              ``
_ÊÊÊþÎÊÊ ¾ºÜÑÑÑ®½g                        `````
_gÊÊÊÊÊÊÊÊÊÊÊÊQQQÊÊÊ  ÎÊÊÊQÊþ¯¯¯¯                     ````
gØÊÊÊÊÊÊÊÊÊÊÊÊÊÊþÊÊÊÊÑ×,_ÎÊÎ¯ÊÊÊ                         ```
_ØÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊQQÊQgÊÊ`¯°  ¸QÊ                       `````;
gÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊgÊÊÊÊþ_¿__gÊ¯                       ` `;»»
ÆÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊQQÊÊÊÊÊÊÊÊÊÊÊÊ_                       ````»»
ÑÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊØÊÊÊÊÊÊÊÊ_ÿ_ÑÊÊÃ           ³³^            `»»
¯ÑÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÑÊÊÑþ           ·              ```»
ÆÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÑÊ ÊÑÊþ           ·              ```»
ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ¯ÑÊÊÊÊ    Êþ                          `;»
gÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ  qÊÃÊ `  QÊþ         ·         :`    ```
QgQ¿¸      gÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ   ÊÑ Ê ` qÑÑÊÿ        ·        ;``    `:`
ÑÑÑÑ©¸  ¸ qÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ¯  qÊÎ Î ¨ ÑÑîÑÊ¸       ·      »»¨² ` ¸¸¸¸¸
QQQ¿ggQQÊQÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÃ »»qþþ Î » . ,¡Êþ_¿¿q»¿ jQ_`         _QQÿgQ

note: for an appropriate display the display font needs to be monospace. If a char image does not fit within the command window, you may try the following to display it on a figure:

``` fontsize=6;
figure;
uicontrol('style','text','units','norm','position',[0,0,1,1],'string',str,...
'fontweight','bold','horizontalalignment','left','fontname','monospaced',...
'foregroundcolor','k','backgroundcolor','w','fontsize',fontsize);```

and edit the value fontsize so that the image fits within the figure.

### Solution Stats

66.67% Correct | 33.33% Incorrect
Last Solution submitted on Oct 07, 2023

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!