100KB image compression

2

Your task is to, given an image, compress it to 100000 bytes or less, while following all of the below rules:

  • No cheating/loopholes.

  • Your code must not be optimized to work best only on the test set of images, but rather produce a good output in general.

  • Colours that do not exist in the original input image must also not exist in the output image. You do not necessarily have to use all of the colours in the input image, so you may use a subset of them if you want to, but, there must not be any extra colours in the output image that were not present in the input image.

  • The input will be at minimum of image types/file extensions JPG, PNG, GIF (including animated GIFs), and BMP. Your code may support any additional formats for input and output beyond the minimum described above, if you want to.

  • The output image must remain in the same file format/extension as the original image, unless your code doesn't support a format and you'd need to convert it. Conversion processing must be done losslessly and outputted to a lossless file format. Therefore, there must not be anything added or removed at all from the image during the format conversion process.

  • The maximum filesize of the output image after compression is exactly 100000 bytes.

  • You must not losslessly compress images. Theoretically speaking, "any lossless compression algorithm that makes some files shorter must necessarily make some files longer."

  • The output image must have the exact same dimensions/size as the input image.

  • Theoretically speaking, every possible input your algorithm/code gets must produce an output of 1000000 bytes or less.

Your code must produce good output on most images in general, but, for this challenge, you must test your code on this test set of images and upload your output.

You must also show the code that you used, and not just the output images.

Your score is determined by the sum the squared difference between the input and output images.

As an example:

If the first pixel in the uncompressed image is RGB (2,3,4) and the first pixel in the compressed image is RGB (5,6,7), then the squared distance for that pixel is (2-5)^2+(3-6)^2+(4-7)^2, and then you sum that up for all the pixels.

Thank you, and good luck!

CodingGolfHockey

Posted 2016-08-14T02:01:47.757

Reputation: 21

Question was closed 2016-08-14T02:29:47.237

3

Unfortunately, "best image quality" is way too broad as a winning criterion. I'd recommend posting challenges in the Sandbox to refine them before posting them here

– Nathan Merrill – 2016-08-14T02:06:14.733

2

That said, while this challenge is well written and easy to read (nice job!), it's really similar to another image compression challenge, and I'm not sure how you would score "best image quality" without making it a duplicate.

– Nathan Merrill – 2016-08-14T02:11:27.377

Better, but a bit unclear. What does "amount of colors" mean? The number of pixels with the same RGB value? The number of R values that are the same (and G/B values)? What if the pixels are in a different spot? – Nathan Merrill – 2016-08-14T02:36:30.263

I really like the spirit of the challenge, but if the 'compressor' returns an exact copy of the original image, but is one off with every color, in this grading scheme, it would get 0, as it has none of the original colors. One way is to sum the squared difference between the input and output images. – Magenta – 2016-08-14T02:59:59.020

If, for the first pixel, the uncompressed image is (2,3,4) and the compressed is (5,6,7), then the squared distance for that pixel is (2-5)^2+(3-6)^2+(4-7)^2, and then sum that up for all the pixels. Conversely, you could steal the python code in 'Compress an image to a 4 KiB preview' which is structure-based instead. – Magenta – 2016-08-14T03:08:57.037

Please do not vandalise your question. If you register your account, you can delete it. – Wrzlprmft – 2016-08-14T10:32:19.000

How do I make the question no-longer on hold?

I've updated it and made it more clear. – CodingGolfHockey – 2016-08-14T10:58:49.473

@CodingGolfHockey What should we do if it is impossible to create an image of a given size under 100kB? – LegionMammal978 – 2016-08-14T11:06:21.027

If by impossible you mean that your algorithm may produce an output that doesn't follow the rules, then do not post it.

I've edited the challenge to make this more clear. – CodingGolfHockey – 2016-08-14T11:11:11.037

Looks like I need 5 re-open votes for this to be no longer on hold. I guess I'll have to wait.. – CodingGolfHockey – 2016-08-14T11:34:17.737

No answers