Word Portraits visualization [closed]

2019-02-19 11:36发布

问题:

I stopped by this visualization and it's called Word Portrait:

My question is: how to do something like this? Is there a tutorial or a paper that describes this?

回答1:

I newer saw this but I did bitmap to ASCII art converter in the past which is similar. so from my point of view I see it like this:

  1. take gray-scale image and segmentate it (by rectangle areas with fixed aspect ratio)

    Aspect ratio is given by input text phrase and Font used. This will give you list of rectangles with similar colors so compute average color for them. Also a good idea is to limit min and max size of segments

    • too small rectangles are unreadable
    • too big rectangles are ugly (see the biggest GENIUS)
  2. replace rectangle segments by text

    Font size is limited by filled area (rectangle size) so text will fit into it. Average color of text should be the same as average color of rectangle segment

    text_color=rectangle_avg_color*(ink_pixels+paper_pixels)/ink_pixels
    

    ink_pixels and paper_pixels are the count of pixels in rendered text phrase. If you want to implement colored images then just compute R,G,B values separately and blend it together or segmentate by colors and intensities at once

See Image to ASCII Art conversion it may help you got some new ideas ...



回答2:

Check my Github repository: ArtWork.

We implemented this algorithm for an university project.

How this algorithm is working.

  1. Compute the Bounding Box of the font you are using.
  2. Take this BBox and move it over your image.
  3. (will be explained in step 7. check the used image with the current BBox. Is there a free spot within the BBox to print (all pixels must be white)? If yes go to Step 4. else move the BBox further.)
  4. Compute the mean of this BBox
  5. Compute the variance of this BBox
  6. Use a threshold which defines if we print or not (variance low -> we print otherwise we move the BBox)
  7. If we print the text, print it with Color(result mean) on your result image and on a second completely white image, called used image, which will help us to check if we already printed into this area. On this used image we print with black color.
  8. Update your parameters, this means shrink the font size step by step till you reached your final end condition (ex. currentFontSize > minFontSize).
  9. Repeat (go to Step 1.) till your final condition is reached.