Tag Info

Hot answers tagged compression

136

///, 2*1 + 1020874 = 1020876 Prints a space.

116

Mathematica, score 14125.71333 "a.png"~Export~ConstantImage[{28,34,41}/95,{386,320}] Saves this image: to a.png.

110

Java, 7399.80678201 This reminded me of a project I had in my numerical computations class a few semesters back, which was to draw a silhouette of Mount Everest using polynomial interpolation. That was done in MATLAB, but I'm not very fond of MATLAB, so I decided to work in Java. The basic idea behind it is that I chose "smart" points (read here as "random")...

109

Pyth (no built-in compression), score 4695.07 4656.03 4444.82 Pyth’s only image-related functionality is a builtin to write a matrix of RGB triples as an image file. So the crazy idea here is to train a small deep neural network on the (x, y) ↦ (r, g, b) function representing the image, and run it on the coordinates of each pixel. The plan Write a custom ...

97

Node.js, 2*224 + 524279 = 524727 Please refer to the change log at the end of this post for score updates. A function taking and returning a byte. a=[...l='14210100'],m={},s={},b={} f=c=>a.some((t,n)=>x=s[y=l.slice(n)]>t|/^[A-Z '"(]/.test(y)&&b[y],l+=String.fromCharCode(c),a.map((_,n)=>(m[x=l.slice(n)]=-~m[x])<s[y=l.slice(n,8)]||(s[...

91

Python3.4+, 4697.26 I used the same method as in my ImageMagick answer, but with the following parameters: convert ORIGINAL.png -filter Lanczos2 -resize x32 - | pngquant --speed 1 -f 20 > i Using these parameters I generated the following 1003 byte Python program (I didn't find any improvements over @kennytm's output method): import base64,io,PIL....

91

Perl, 2·70525 + 326508 = 467558 Predictor $m=($u=1<<32)-1;open B,B;@e=unpack"C*",join"",<B>;$e=2903392593;sub u{int($_[0]+($_[1]-$_[0])*pop)}sub o{$m&(pop()<<8)+pop}sub g{($h,%m,@b,$s,$E)=@_;if($d eq$h){($l,$u)=(u($l,$u,$L),u($l,$u,$U));$u=o(256,$u-1),$l=o($l),$e=o(shift@e,$e)until($l^($u-1))>>24}$M{"@c"}{$h}++-++$C{"@c"}-pop@c ... 88 Python 3, score 5701.31 import base64,io,PIL.Image PIL.Image.open(io.BytesIO(base64.b85decode('iBL{Q4GJ0x0000DNk~Le0000I0000D2m$~A04pr1P5=MlSxEDRCrzu%wJF2MgRctyYrpz&VS-04oPU$02O1RYA2$KKm9YcYEUcDJyh+N==-F7oxW_3ecQvNY1*VQwC-UKjIkjQ8wn&8)Ukt&?VNpg?HBmL%~#(%>G5yhoON#6r~Pv6ekHzgk~o3d4gyuJLu_K5Ca>QWmKD%@0G*T5|2ap)6YJolVN{skh#D2-J*z9sSwJGT&-...

77

Python 3, 2·267 + 510193 = 510727 Predictor def p(): d={};s=b'' while 1: p={0:1};r=range(len(s)+1) for i in r: for c,n in d.setdefault(s[:i],{}).items():p[c]=p.get(c,1)*n**b'\1\6\f\36AcWuvY_v`\270~\333~'[i] c=yield max(sorted(p),key=p.get) for i in r:e=d[s[:i]];e[c]=e.get(c,1)+1 s=b'%c'%c+s[:15] This uses a weighted Bayesian combination of ...

70

Java, 8748.95 Another approach: I created a class that computes a Voronoi Diagram from a given set of points. This set of points is used as the parameter set that serves as the input for the Apache BOBYQAOptimizer. The evaluation function of the optimizer takes the points and creates a voronoi diagram from them. The voronoi regions are colored with the ...

64

AutoIt, 9183.25 7882.53 UPDATE So it turns out that redrawing the image like a (drunk) toddler is more effective than storing any version of the image. (More effective than my old solution anyway). Every line that draws an element is crucial to decreasing the score. I suspect this program is capable of achieving scores well below 7000 with very minor ...

58

I've improved my method by adding actual compression. It now operates by iteratively doing the following: Convert the image to YUV Downsize the image preserving the aspect ratio (if the image is color, the chroma is sampled at 1/3 the width & height of the luminance) Reduce the bit depth to 4 bits per sample Apply median prediction to the image, making ...

55

Python 3, 2*279+592920=593478 2*250 + 592467 = 592967 2 * 271 + 592084 = 592626 2 * 278 + 592059 = 592615 2 * 285 + 586660 = 587230 2 * 320 + 585161 = 585801 2 * 339 + 585050 = 585728 d=m={} s=1 w,v='',0 def f(c): global w,m,v,s,d if w not in m:m[w]={} u=m[w];u[c]=c in u and 1+u[c]or 1;v+=1;q=n=' ';w=w*s+c;s=c!=n if w in m:_,n=max((m[w][k],k)for k in m[...

45

Windows BAT file, score 4458.854 echo QlBH+yAAgwKCQAADkkdARAHBcYMSAAABJgGvBVKInJKSe4D9mGo5+oRwrhSlmmqeYK22qun5kDzV+UZhRPdtXWSME8ABlNItkdoM5b0O7jO01KMnUbhSa4GAKq6U/AWBh8J4Od/O0RKwm2Bj1lAWi3yfWb9AB14B9/aml7juRU0fQTVS9LUQxE1eXTfp6f2SdBh9Ibyk3CNjdpEGdZLsuSPaQUP0vWnqtxyBsYQW1orBqzSh4zWFscTx5OMxA4FAw1/Y+/xx+TEUkogp4oykebVfCTFJYFRW6KZ+...

42

C++11, 7441.68126105 6997.65434833 5198.16107651 More Updates I liked the ellipses from Perl so much I had to try them in C++11. I used the raw string to shove bytes into there, but for a while I was getting a slight discrepancy with the score I expected and the generated code. It turns out that you actually can't put a raw 0x0d (Carriage Return), since g++...

41

ImageMagick, 4551.71 Uses the ImageMagick 'programming' language, using the following options (you might have to escape the !): convert i -resize 386x320! o.png Assuming the following 968 byte source file (given as hexdump): 00000000: 89 50 4E 47 0D 0A 1A 0A - 00 00 00 0D 49 48 44 52 | PNG IHDR| 00000010: 00 00 00 30 00 00 00 28 - 08 03 00 00 00 ...

40

Python 2, 4749.88 1018 bytes Everybody has probably forgotten about this problem by now, except me.... This problem interested me far too much, especially as it quickly became apparent that approaches using image compression algorithms were definitely in the lead, but yet somehow unsatisfying from an aesthetic standpoint. Approaches based on optimizing a ...

37

Go Works by dividing the image into regions recursively. I try to divide regions with high information content, and pick the dividing line to maximize the difference in color between the two regions. Each division is encoded using a few bits to encode the dividing line. Each leaf region is encoded as a single color. 4vN!IF$+fP0~\}:0d4a's%-~@[Q(qSd<&... 37 Matlab, score 5388.3 Without any built in compression. The colour depth is reduced such that each pixel can be represented by one printable character. And the resolution is reduced. This is then hardcoded as a string. The code itself reverses the whole process. The resizing operation is using a Lanczos 3 interpolation kernel. imwrite(imresize(reshape('@<... 36 Python Encoding requires numpy, SciPy and scikit-image. Decoding requires only PIL. This is a method based on superpixel interpolation. To begin, each image is divided into 70 similar sized regions of similar color. For example, the landscape picture is divided in the following manner: The centroid of each region is located (to the nearest raster point on ... 30 zsh+bpgdec, 4159.061760861207 Yes, another BPG solution. I think this basically serves to prove that BPG is the best image compression utility currently available. Consider it an improvement over yallie's original BPG solution. The file is 1024 bytes long, right at the limit. It consists of the line exec bpgdec =(tail -n+2$0) followed by the raw BPG ...

27

Min: 12 bitsMax: Avg: Had and thought last night that I could possibly make it even smaller. x Colour to play next (0 -> Black, 1-> White) 1 Only King left? 00000 Position of White King (0 -> A1 ... 63 -> H8) 00000 Position of Black King 01 00000 11111 WK:A1, BK:H2 (Black to play) 11 00000 11111 WK:A1, BK:H2 (White to play) The result ...

27

C, 6641 999 bytes, using only stdio.h and math.h. I made a filled-circle function d() that draws concentric RGB colored circles over radius values r..0. 21 circles are used here. I could squeeze in a few more if I stripped out more whitespace, but I like the relative readability as it stands. I figured out rough circle placement using Gimp layers in ...

27

05AB1E, 4 bytes D1ìH Explanation D Duplicate input 1ì Prepend 1 H Interpret as hexadecimal and implicitly display the value in base 10 If the input has invalid hex characters, H won't push anything so the last value on the stack will be the duplicated input, that's why the program prints its input in case of invalid input. Try it online!

26

Scala Sure, it'd be easier to encode MIDI files, but who's got a bunch of MIDI files lying around? It's not 1997! First things first: I've decided to interpret a "Unicode byte" as a "Unicode char" and use CJK characters, because: It matches the image challenge Twitter is cool with it I really need those bits There are a few tricks I use to squeeze every ...

26

Haskell, 107 points import Control.Monad import Data.List type Elem = Char type Board = [[Elem]] type Constraints = ([Elem],[Elem],[Elem]) digits :: [Elem] digits = "123456789" noCons :: Constraints noCons = ([],[],[]) disjointCons :: Constraints disjointCons = ("123","456","789") -- constraints from a single block - up to isomorphism triples :: [a] -> ...

26

Python 3, score 5390.25, 998 bytes I used a simulated annealing program to fit rectangles into the shape of Starry Night. Then it uses a Gaussian blur to smooth out the straight rectangular edges. To save some bytes, I compressed the rectangle data into base 94. from PIL import Image as I,ImageDraw as D,ImageFilter as F def V(n,f,t): z=0;s='';d='''...

26

Python 2, 5238.59 points It is probably time to post my own answer. Here's the image The code looks like this import Image,ImageDraw as D m=Image.new("RGB",(386,320),"#4b5b6e") d=D.Draw(m,"RGBA") s="[string containing unprintable characters]" for i in range(95): x,y,w,h,r,g,b,a=[ord(c)-9for c in s[i::95]] x,y=3*x,3*y d.ellipse([x-w,...

25

Starry, 11428.1894502 10904.3079277 10874.1307958 Starry might not be the best language to do this however it is certainly the most fitting. You can Try It online however it seems that the output is truncated so you will not get the full image. This program outputs an uncompressed ppm files to standard out. + +* +* +* +* . +. + ...

25

C++, score: 2*132 + 865821 = 866085 Thanks to @Quentin for saving 217 bytes! int f(int c){return c-10?"t \n 2 sS \n - 08........ huaoRooe oioaoheu thpih eEA \n neo enueee neue hteht e"[c-32]:10;} A very simple solution that, given a character, just outputs the character that most frequently appears after the input character. Verify the ...

Only top voted, non community-wiki answers of a minimum length are eligible