# What pattern maximises a JPEG file's size? [duplicate]

As I understand the JPEG algorithm, it smooths (ignores) gradual variations in colour and brightness in favour of high frequencies. This loss of information is what creates the characteristic high level of compression relative to lossless algorithms.

So the grey square would result in a small JPEG file, whilst the grids should generate larger files:-

Clearly such grids /patterns could be of any pitch right up to single pixels. I'm stipulating that all the images are grey scale types. Is there some way to determine the type of pattern to maximise the size of a JPEG file, or must this be done experimentally?

• Which encoder and encoder settings? The encoders are free to tune the quantization table for each image, and may not have equivalent encoding settings. Sep 27 '17 at 11:56

Pursuing on @OlliNiemitalo, JPEG allows some loss related to frequency quantization. So any file can be compressed to any size, hence you cannot maximize a JPEG size without setting some constraints, like quality. Let us assume a standard metric, like mean-squared error.

Now, let us check some of the JPEG features for image sparsification, and let us try to go the opposite direction:

• JPEG assumes similarities in RGB color planes, correlated with a luminance/chrominance transform for instance. So you choose independent R, G, and B, you are good
• 8$\times 8$ patches are compressed almost independently, except for the average, predicted for the blocks before (raster order). If you have neighboring blocks with very different means, good
• the more the high-frequency, the less a 8$\times$8 block as natural frequency, the better. They avoid long trails of zeros encoded by an EOB symbol.

One cannot easily fulfill all these properties together, especially with RGB planes made of 8-bit integers. Forgetting about the average-thing, generating independent RGB images, with each pixel randomly $0$ or $255$ (ie high range). Quantization is likely to produced here a lot of false colors. This could give you very bad images for the JPEG in MSE. However, original and compressed ones could look as ugly.

You can find other fractal-based or fancy-patterned proposal in What is the least JPG-compressible pattern? (camera shooting piece of cloth, scale/angle/lighting may vary)

If you are looking for an explicit mathematical (analytic geometrical etc.) formula which would generate the geometrical shape (the pattern) that you define as the one which would compress least under a given JPEG encoder implementation; I haven't heard of such a formula. May be there is but as I said I haven't heard of one such.

However, the way you ask this question is not the most proper approach given the theoretical concepts behind the JPEG image compression algorithms. If you look at a generic JPEG encoder, you would see that there are a number of blocks such as the DCT, Quantizer and VLC Huffman encoder.

I won't go into the details of the theoretical analysis of those blocks and the mechanism of how the associated compression is physically achieved. However I will describe the charactheristic of the shape which would produce more bits than others under a given encoder:

The shape which would result in the largest JPEG encoded bitstream is the one, which, after its DCT is taken, produces least number of consequitive zeros and largest amplitude coefficients after the DCT coefficients are quantized by a selected weighting matrix.

So which image would do that? It depends on the weighting matrix and DCT. If you select a human visual system based weighting matrix then the image must have excess high frequency contets. This means that The image must be composed of sharp and short duration black and white passages.

Its orientation could also matter because of the zig-zag scannig pattern of eth DCT coefficients. But its hard to be sure without further analysis.

Consequently a white noise image with high dynamic range would produce quite large file size as its DCT would be ineffecitve to reduce its frequency content to low frequency coefficients.
{"ft_lang_label":"__label__en","ft_lang_prob":0.9674685,"math_prob":0.874074,"size":1772,"snap":"2021-43-2021-49","text_gpt3_token_len":349,"char_repetition_ratio":0.10690045,"word_repetition_ratio":0.0,"special_character_ratio":0.18340857,"punctuation_ratio":0.06896552,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96348095,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-16T22:10:21Z\",\"WARC-Record-ID\":\"<urn:uuid:d12ffd33-9ff2-416a-a48c-eb01d1f0410f>\",\"Content-Length\":\"160099\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2701801f-3252-4427-94cc-7a8bb57c45c9>\",\"WARC-Concurrent-To\":\"<urn:uuid:253f5b8e-a11f-4b21-9d02-c09e774b8490>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://dsp.stackexchange.com/questions/43986/what-pattern-maximises-a-jpeg-files-size\",\"WARC-Payload-Digest\":\"sha1:AJALI232TFWNJKJGVKNDMARJZUP55BM7\",\"WARC-Block-Digest\":\"sha1:PC663XXF7IENUL5PY2IHPESKABNOQ7IV\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585025.23_warc_CC-MAIN-20211016200444-20211016230444-00708.warc.gz\"}"}