7
\$\begingroup\$

Your goal is to write a program / script which "converts" real images into ascii art.

General:

Your program will get a path to a image file over stdin or as parameter (whatever you prefer). The format will be jpeg.
It should "convert" it to ascii art and save it to the harddrive.
The image will be in grayscale. You don't have to check if the input file exists or the file is a valid image.
You can use any utf-8 character in your outputfile.

Rules:

  • You must be able to recognize the output image.
  • Your program must recognize the path on stdin or parameters
  • The content of the original image must be read from the drive (you get only the path to the file)
  • No user interaction (except giving the parameters at startup) allowed
  • Must terminate without any error message
  • The output must be written to the harddrive (output name is up to you)
  • Only turing complete languages allowed.
  • If you require any special language version for your program you have to add it to your answer. Otherwise the newest stable version will be used (e.g. python = python 3.3)

Bonus points:

  • -10 Points for every additional image format your program can convert (please write down which formats can be recognized)
  • -25 Points if your program can change the output size (width / height parameters at startup in characters)
  • -100 Points if you don't use any Image Processing libraries (e.g. PIL, ImageMagic, GD...)
  • -50 Points if your program source looks like ascii art itself ;)

Formula to calculate your points:

points = floor(programSize (in Bytes) * avgRuntimeOnTestInput (in seconds) - BonusPoints)

How your program will be tested:

All programs will run on a new virtual machine running Debian x64 (current version) with 512MB memory, 2x3,4Ghz CPU.
The time will be calculated on an average of three pictures per format with different size and content (every program will be use the same files).
Please write your programcall into your answer so i can check it (and if required the needed compile parameters).
Example program call (with bonus parameters):
python ascii.py -file /home/chill0r/test/MyPicture.jpeg -width 1000 -height 750 -out /home/chill0r/test/MyPictureAscii.txt

I'll check the answers every few days and post a 'low score' (high score doesn't really fit on code golf...). (Meaning you don't have to calculate your points on your own)

\$\endgroup\$

closed as too broad by Sriotchilism O'Zaic, caird coinheringaahing, Mego Apr 2 '18 at 0:00

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    \$\begingroup\$ First, I've only been here for a week and already seen multiple ASCII challenges. This one is even more general than the last two. Second, if I have the fastest code, and someone else has the shortest code, who wins? I suggest removing the "fastest-code" tag or the "code-golf" tag - probably remove the former judging by your scoring system. Then, put a spin on your question that makes it unique from other ASCII challenges. \$\endgroup\$ – Rainbolt Mar 13 '14 at 19:49
  • \$\begingroup\$ I have removed fastest-code since it is obvious from the question that this is a code-golf challenge. \$\endgroup\$ – ace Mar 13 '14 at 20:28
  • 3
    \$\begingroup\$ "You must be able to recognize the output image." - isn't this too subjective? I thought to post this question too but couldn't come up with a way to enforce this objectively. \$\endgroup\$ – Claudiu Mar 13 '14 at 20:32
  • 2
    \$\begingroup\$ One objective approach to "able to recognize" I have been able to think of is for poster to hire people on something like Mechanical Turk to see if they recognize the image. But that creates a problem if poster wanders off distracted by something shiny and new answers are still coming in. So I thought of one better: poster writes a test harness that rasterizes the ASCII images and algorithmically evaluates them for similarity to the original image, and posts the source for the tester in the question. Then at least you have a verifiable authority. \$\endgroup\$ – Jonathan Van Matre Mar 13 '14 at 20:38
  • 2
    \$\begingroup\$ Bonus points are listed with negative values, but they are subtracted in the score formula, that makes them to penalties? \$\endgroup\$ – Heiko Oberdiek Mar 13 '14 at 20:44
11
\$\begingroup\$

Mathematica

asciiPhoto[image_,rastersize_:125,shades_:3] scans the image according to the raster size (default=125), quantizes it into up to 7 shades (3 by default), then replaces the shading with ASCII characters of varying darkness. Hints about relative darkness found here. The characters are stored in shades; for some reason, 2 of them disappeared in the cut and paste to SE.

asciiPhoto[image_,rastersize_:125,shades_:3]:=
Module[{chars,gray},
chars={{},{"M"," "},{"","/"," "},{"P","o","/"," "},{"W","o","/",""," "},
{"","b","o","/",""," "},{"","M","b","o","/",""," "},};
gray=ImageData[ColorQuantize[Rasterize[image,RasterSize->rastersize+1,
ImageSize->rastersize],shades]];
GraphicsGrid[gray/.Thread[Union@Flatten[gray,1]->chars[[shades]]],ImageSize->500]]

Examples

Render the merganser with a raster size of 35 in 4 shades; compare it to a raster size of 85 with 5 shades.

merganzer

{asciiPhoto[merganzer, 35, 4], asciiPhoto[merganzer, 85, 5]}

merg2


Raster size of 125 in 2 shades; same raster size with 7 shades.

{asciiPhoto[merganzer, 125, 2], asciiPhoto[merganzer, 125, 7]}

merganzer3


Let's not forget Greta.

greata

\$\endgroup\$
  • 1
    \$\begingroup\$ Very nice. The only observation isn't programming related: Let Greta go. :) \$\endgroup\$ – Dr. belisarius Mar 14 '14 at 1:51
  • \$\begingroup\$ @belisarius, It seems I just can't get Greta out of my mind. \$\endgroup\$ – DavidC Mar 14 '14 at 1:55
  • \$\begingroup\$ Well, it's a shared weak point \$\endgroup\$ – Dr. belisarius Mar 14 '14 at 2:01
  • \$\begingroup\$ I invite you to spend a few pennies by downvotng this one \$\endgroup\$ – Dr. belisarius Mar 14 '14 at 2:05
  • 1
    \$\begingroup\$ Happy to oblige. \$\endgroup\$ – DavidC Mar 14 '14 at 2:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.