Message Boards Message Boards


Create ASCII art 3: generate a mosaic version of an image

Posted 1 year ago
1 Reply
3 Total Likes


Another post described how to perform ASCII art by using convolution. Interestingly, the same technique is suitable for reconstructing an image as a mosaic art representation from sample images.


If in the case of ImageASCII, we use a convolution-based approach, we use rasterized characters; we use a dataset of sample images to do the same thing. ImageMosaic is available in Wolfram Function Repository and can be accessed as ResourceObject[ImageMosaic].


Below are a few example results to demonstrate the function behavior:

Reference Outcomes

Tile size has {12,12} dimensions. The input image was resized to match 800 in one dimension, sample images constant images of random colors.

Since the dataset can be anything, we can highlight the similarity of the approach to the ASCII art generation by using a dataset of images that are rasters of 95 ASCII characters:

To rasterize ASCII characters, we use the same method as in the previous approach. Here is a result of an image mosaic with 95 ASCII characters.

ResourceObject[ImageMosaic][image, samples, "BlendingFraction"-> 0]


Let us compare with the ImageASCII function result:

ResourceObject[ImageASCII][image, "Image"]


We can see that the results are the same:

In[-]: MinMax@ImageDifference[imageMosaic, imageASCII]
Out[-]: {0., 0.}

We can try to mimic colored ASCII art via expanding our dataset with character rasters of various colors. Colored ASCII characters were rasterized like this:

colorPallete = 
		Table[RGBColor[i, j, k],
			{i, 0, 1, 0.25}, 
			{j, 0, 1, 0.25}, 
			{k, 0, 1, 0.25}
samples = Prepend[Join @@ Map[Function[
	Rasterize[Style[#, 12, Bold, color], RasterSize -> {8, 12}] & /@ CharacterRange["!", "~"]
], Rasterize[" ", RasterSize -> {8, 12}]];

Moreover, here is the visual outcome:

ResourceObject[ImageMosaic][image, samples, "BlendingFraction" -> 0, RasterSize -> 1920, "ProcessingFunction" -> (ImageAdjust@HistogramTransform[#]&)]]

Colored ASCII art


As seen, the image feature recovery is quite precise. It is essential to choose the right dataset when trying to perform mosaic art on an image. The bigger the dataset can help to achieve a better reconstruction.

References & Credits

Thanks to Wolfram Team and Mikayel Egibyan in particular for mentoring the internship.

POSTED BY: Karen Danielyan

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract