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 ````` gQQQQQØÊÊÊÑÊQQ¸ ¸»gÊÃ@Q©ÑmM `````` _ØÊÊÊÊÊÊÊÊÊþ°ÑÊÊQ©Ñ ÊÊÊÊÊQ____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 ÑÑÑÑÑÑÑÑÑÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÑÑÑÑÊQÑÊÑ_ÎÑQQQQjÊþþÊÑþQQÊÊÊÊg¿_ _g©ÑÑÑÊÊÑÑ Ñ»©QQÿ©©QÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊʰ``¨qÊfQÊýÑQþ`©ÑÜÑÑÊþÊÑQÊÑÑÑÑÑÊÑÑ©©ÑÑÑÑÑÊÊÊÊÊ Ñ©©ÑÑÑ©QÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÜλ¯ÊÑÑÿ.Ê ÎÎÑ»¯ÜÜÎÑÊþÎÎβ²²¨²¨²²»»»»ÎÎÎÎÎÎÎÑ ©`²Î¨ÎÎÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÑ»»»qÊQÿ »Ê ©Q©©Ñ»²©©ÑÊþQQQQQQQQQQQQ©©©©©©©©QQ ©©Q©©ÑÑÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ©©©©ÊÊʰQQÊ Q©Q©QQQ¿ÜÑÊþÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ ©Ü©©^»²©ÑÑÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊѸ¨¸QÊMÿQQÑ Ñ»©»©Î»»Q¸ÜÊþQÑÑ©©ÑÑ©©©©ÜÑÑÑÑÑÑÑÑÑ ©»»»QQѩλÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊ»»»ÎØÑ³;Ñ»©©»¸¨²²²©©Ñ©Ñh¯Ê_©»QQÑ©ÑÑQÑQÑÑÑÑÑÑÑÑQ ©QQîQ©»Q;»ÊÊÑÊÊÊÊÊÊÊÊÊÊÊÊÑQQ¿_ÊÃÊÜ©QQÑQQQ©Î^QÎÑQQQ©ÑÊþ©©ÑѩѩѩÑÑÑÑQQQQQQ Ñ©ÜÑÎÎÜÎÎÜÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊQQÑÑQʽÑÑÑÑQQQQ©Q»Î뽩¯Ñ¨²ÑÊQÎÎÜÑÑÑÑÑÑÑÑQÑÑÑÑÑÑ ÑÑÜÑÑÑÑÑÎQÊÊÊÊÊÊÑÊÊÊÊÊÊÊÑÑÑÑÑÑÊ#Ñ©ÑÑQQÑÑ©©©Ñ»½©©©©©QQÊѽÑÑÑÑÑÑQÑÑÜÑQÑÑÑÑÑ ÑQQÑQ©Ñ©©ÑÊÊÊÊÊÊÑÊÑÊÊÊÊѽ»ÑÑÑÎ ¯©QQ©Ñ©©ÿ©©ÑÑ©ÿѽ½ÑѽÑÑq ýÿ©QѩѩÑÑ©©ÑÑÑ©Q ÑÜj©Q©QÎQQÊÊÊÊÊÊ¿ÊÊÊÊÊÊÑ©©©©Q° »Q©©Î©Q©QQQ©ÑÑÑQΩÑѩѩÑÀ`ÑÑÑÑÑÑ©ÑÑÑÑÑÑÜQQ QQÑ3ÑQQÑÑQÊÊÊÊÊÑ2QÊÊÊÊÊþQQ©©Ê ¸ÑÑ©©©Q©ÑQÑQ©ÑQÑÑ©QÑÑÑQQÑÑ¿³ÑÑÑÑ©ÑÑÑÑÑÑQÑQÑ ©ÑÑÑQÑQ©ÑQÊÊÊÊÊQÿÑÊÊÑÑÊÊÑÑQÑÊ ÎQ©ÑÑQÑÜÑÑQÑÑÜÑÑQQQÿQQÑ©ÑQÑ¿ÎQQÿQQÑQÊÑÑQÑQÑ
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
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers10
Suggested Problems
-
5985 Solvers
-
Given two arrays, find the maximum overlap
1607 Solvers
-
1029 Solvers
-
Create a cell array out of a struct
2110 Solvers
-
Are all the three given point in the same line?
584 Solvers
More from this Author38
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!