Introduction
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.
Approach
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]
.
Results
Below are a few example results to demonstrate the function behavior:
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 =
Flatten[
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[
color,
Rasterize[Style[#, 12, Bold, color], RasterSize -> {8, 12}] & /@ CharacterRange["!", "~"]
],
colorPallete
], Rasterize[" ", RasterSize -> {8, 12}]];
Moreover, here is the visual outcome:
ResourceObject[ImageMosaic][image, samples, "BlendingFraction" -> 0, RasterSize -> 1920, "ProcessingFunction" -> (ImageAdjust@HistogramTransform[#]&)]]
Conclusion
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.