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!

  • 3
    \$\begingroup\$ 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 \$\endgroup\$ – Nathan Merrill Aug 14 '16 at 2:06
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Nathan Merrill Aug 14 '16 at 2:11
  • \$\begingroup\$ 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? \$\endgroup\$ – Nathan Merrill Aug 14 '16 at 2:36
  • \$\begingroup\$ 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. \$\endgroup\$ – Magenta Aug 14 '16 at 2:59
  • \$\begingroup\$ 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. \$\endgroup\$ – Magenta Aug 14 '16 at 3:08