Background
PICASCII is a neat tool that converts images into ASCII art.
It achieves different degrees of brightness by using the following ten ASCII characters:
@#+';:,.`
We'll say that these charxels (character elements) have brightnesses from 1 (at-sign) to 10 (space).
Below, you can see the results of converting a little code, the Welsh flag, an overhanded fractal, a large trout and a little golf, displayed with the correct font:
Your can see the images in this fiddle and download them from Google Drive.
Task
While the end results of PICASCII are visually pleasing, all five images combined weigh 153,559 bytes. How much could these images be compressed if we are willing to sacrifice part of their quality?
Your task is to write a program that accepts an ASCII art image such as the above ones and a minimum quality as input and prints a lossy compression of the image – in form of a full program or a function returning a single string – that satisfies the quality requirement.
This means that you do not get to write a separate decompressor; it must be built-in into each of the compressed images.
The original image will consist of charxels with brightnesses between 1 and 10, separated by linefeeds into lines of the same length. The compressed image must have the same dimensions and use the same set of characters.
For an uncompressed image consisting of n charxels, the quality of a compressed version of the image is defined as
where ci is the brightness of the ith charxel of the compressed image's output and ui the brightness of the ith charxel of the uncompressed image.
Scoring
Your code will be run with the five images from above as input and minimum quality settings of 0.50, 0.60, 0.70, 0.80 and 0.90 for each of the images.
Your score is the geometric mean of the sizes of all compressed images, i.e., the twenty-fifth root of the product of the lengths of all twenty-five compressed images.
The lowest score wins!
Additional rules
Your code has to work for arbitrary images, not just the ones used for scoring.
It is expected that you optimize your code towards the test cases, but a program that does not even attempt to compress arbitrary images won't get an upvote from me.
Your compressor may use built-in byte stream compressors (e.g., gzip), but you have to implement them yourself for the compressed images.
Bulit-ins normally used in byte stream decompressors (e.g., base conversion, run-length decoding) are allowed.
Compressor and compressed images do not have to be in the same language.
However, you must pick a single language for all compressed images.
For each compressed image, standard code golf rules apply.
Verification
I've made a CJam script to easily verify all quality requirements and calculate a submission's score.
You can download the Java interpreter from here or here.
e# URLs of the uncompressed images.
e# "%s" will get replaced by 1, 2, 3, 4, 5.
"file:///home/dennis/codegolf/53199/original/image%s.txt"
e# URLs of the compressed images (source code).
e# "%s-%s" will get replaced by "1-50", "1-60", ... "5-90".
"file:///home/dennis/codegolf/53199/code/image%s-%s.php"
e# URLs of the compressed images (output).
"file:///home/dennis/codegolf/53199/output/image%s-%s.txt"
e# Code
:O;:C;:U;5,:)
{
5,5f+Af*
{
C[IQ]e%g,X*:X;
ISQS
[U[I]e%O[IQ]e%]
{g_W=N&{W<}&}%
_Nf/::,:=
{
{N-"@#+';:,.` "f#}%z
_::m2f#:+\,81d*/mq1m8#
_"%04.4f"e%S
@100*iQ<"(too low)"*
}{
;"Dimension mismatch."
}?
N]o
}fQ
}fI
N"SCORE: %04.4f"X1d25/#e%N
Example
Bash → PHP, score 30344.0474
cat
Achieves 100% quality for all inputs.
$ java -jar cjam-0.6.5.jar vrfy.cjam 1 50 1.0000 1 60 1.0000 1 70 1.0000 1 80 1.0000 1 90 1.0000 2 50 1.0000 2 60 1.0000 2 70 1.0000 2 80 1.0000 2 90 1.0000 3 50 1.0000 3 60 1.0000 3 70 1.0000 3 80 1.0000 3 90 1.0000 4 50 1.0000 4 60 1.0000 4 70 1.0000 4 80 1.0000 4 90 1.0000 5 50 1.0000 5 60 1.0000 5 70 1.0000 5 80 1.0000 5 90 1.0000 SCORE: 30344.0474