12 ms·
Jpeg2png: Silky smooth JPEG decoding – no more artifacts (2016)
- webmaven 6y ago"jpeg2png gives best results for pictures that should never be saved as JPEG. Examples are charts, logo's, and cartoon-style digital drawings." Interesting value proposition. There may be equivalents for other misused file types/formats. The obvious one is the inverse case of photos saved as GIFs, but I imagine audio and text (eg. PDF malapropisms?) are possible too.
- makapuf 6y agoI d say the issue is the prpgram here, a compressor program might have heuristic to detect png-favored images vs photos. I cannot imagine we couldn't detect the easy cases reliably (because I'd say often images are more in a category or another). Crop the image to 64x64, try png and if the result is sufficiently small continue, else convert to jpg ?
- dmitriid 6y agoAnd then someone uploads this image to twitter/facebook, and it gets triply re-encoded and resized with the worst algorithms known to man :(
- BlackLotus89 6y agohttps://mobile.twitter.com/NolanOBrien/status/1204557498990002176 https://mobile.twitter.com/NolanOBrien/status/12045574989900... twitter now doesn't cripple uploaded images, but tries to preserve all information except exiv data.
- dmitriid 6y agoKudos to Twitter! Now if only they stopped cropping images to rand()xrand() in timelines pretending they employ advanced ML algorithms to do so :)
- fireattack 6y agoIt's not random though. They likely show most contrasted area (with maybe some face detection).
- dmitriid 6y agoThat's what they claim. The result seems to be no better than rand() :)
- deleted 6y ago[deleted]
- jandrese 6y agoI just tried it with a text heavy screenshot, a common scenario where the JPEG encoding produces a poor result with lots of speckle around each letter. The result is very good. The speckling is effectively eliminated without smearing the letters. JPEG Encoded, 25% quality: http://jubei.ceyah.org/overcompressed/crop-jpg.png http://jubei.ceyah.org/overcompressed/crop-jpg.png JPEG2PNG: http://jubei.ceyah.org/overcompressed/crop-converted.png http://jubei.ceyah.org/overcompressed/crop-converted.png
- indigo945 6y agoI find the text on the reference decoded image easier to read, despite the colorful speckles surrounding the words. JPEG2PNG doesn't smear the letters a lot, but does appear to slightly deform them. Consider the leading "a" in "add license, readme", whose upper half seems to be closer together after the JPEG2PNG run. However, now I'm wondering whether my impression that the reference decoded text is easier to read is a form of overfitting. I have spent the past 20 years reading low-quality JPEG screenshots on the internet, maybe the perceptual centers of my brain have developed an unblocking algorithm?
- stordoff 6y agoThat's a really interesting suggestion. I'm seeing something similar - the jpeg2png output looks cleaner and at first glance more pleasant to look at, but the reference seems both sharper and easier to read. It feels somehow more easier to ignore the more obvious flaws in the reference, and being used to them sounds like a plausible explanation to my layman ear.
- fireattack 6y agoWhy the whole picture shifted? This can't be good
- jandrese 6y agoThey're both cropped out of a full screen grab.
- 0-_-0 6y agoNow we just need an adversarially trained neural network to fill in detail [1] and we have a 21st century JPEG decoder! [1] Implemented for a custom compressor: https://hific.github.io/ https://hific.github.io/
- leeoniya 6y agohere's one that upscales extremely well: https://github.com/TianZerL/Anime4KCPP https://github.com/TianZerL/Anime4KCPP
- lazyjones 6y agoAnd one day, a law enforcement officer will use it on a bad quality JPEG image and one of the innocent persons whose photos were used to train the NN will be arrested.
- kevin_thibedeau 6y agoNexus-6 just needs to get better at hiding from the law.
- IgorPartola 6y agoThis looks like it would be super useful in making phone photography look better. I can’t seem to find, is there a way to run this yourself?
- ajb 6y agoThis is a poor-mans version of the deblocking filter which you find in recent video standards, but jpeg was to early to get it. The advantage of those over this is that the encoder knows that the decoder is going to run the filter, and it can use that in its perceptual model to choose an encoding which looks most like the original after deblocking. Video codecs also use the deblocked version as reference frames. So you see these artifacts in mpeg-2 video and jpeg, but not more recent ones.
- pornel 6y agoI'd call newer formats to have poor-man's deblocking, because they literally apply blur to blocky images, instead of reconstructing an optimal gradient. In newer codecs you can notice that sometimes blocks of 8 or 16 pixels get blurred with a 4px-wide blur, which is barely enough to cover up the edges, but not enough to mask square-ish shapes underneath.
- etaioinshrdlu 6y agoThe interesting thing is that advanced encoders might create JPEGs that produce odd results with this decoder.
- a_e_k 6y agoYes, this is definitely an interesting question. Earlier this year I implemented a version of trellis quantization for some compression experiments that I've been tinkering with in my spare time. My code considers more possibilities than just rounding to the nearest quantization step when it deems that the bit rate savings in after entropy encoding may be worth the additional image loss (e.g., it might even completely zero a coefficient). That would violate this decoder's assumption that the original DCT coefficient must have been within a limited range around the quantization step. I know that mozjpeg [1] features trellis quantization for JPEG encoding. I wonder how this decoder would do with that? [1] https://github.com/mozilla/mozjpeg https://github.com/mozilla/mozjpeg
- ache7 6y agoIt goes fine with mozjpeg. I tested a little, didn't find any problems.
- wtallis 6y agoThis strikes me as conceptually similar to the problem of printing floating point numbers. A naive algorithm will convert the binary floating point to decimal and print that out, with potentially many trailing digits that are more or less garbage. The more human-friendly algorithms figure out the shortest/simplest decimal that would be rounded to the same binary floating point quantity, and prints that instead.
- jandrese 6y agoYes, I've long wanted a floating point print function that understands that 3.999999999999 should be printed as "4".
- colejohnson66 6y agoMy $.02: I’d prefer it say 3.9999999... than 4 so students learn of the inaccuracy of floating point. If one wants a rounded output, one should round before printing.
- jandrese 6y agoStudents can be taught using the standard library printf() or whatever. It's not as easy as "just round" though, because you don't know where the digits start to repeat. A smart function would also print 4.1249999999999 as 4.125. A fancy unicode version could even include the mathematical notation to print 3.333333333333 as 3.3 with a line over the trailing 3. Or 4.2525252525 as 4.25 with the bar over the 25. Might be asking too much of a simple print function though, this might end up being an extension of the halting problem.
- ris 6y agoInteresting project, but its name sells it incredibly short.
- locofocos 6y ago"For pictures that have been reencoded to JPEG multiple times I recommend shred." (https://www.gnu.org/software/coreutils/manual/html_node/shred-invocation.html https://www.gnu.org/software/coreutils/manual/html_node/shre...) That's the funniest thing I've read in a while.
- Lanrei 6y agoThat reminds me of a quote about chlorine trifluoride: "...It can be kept in some of the ordinary structural metals—steel, copper, aluminum, etc.—because of the formation of a thin film of insoluble metal fluoride that protects the bulk of the metal ... If, however, this coat is melted or scrubbed off, and has no chance to reform, the operator is confronted with the problem of coping with a metal-fluorine fire. For dealing with this situation, I have always recommended a good pair of running shoes."
- derefr 6y agoI've always wondered if there was something you really could do to neutralize a reaction that "really wants to happen" like that. Presuming you're in a well-equipped chem lab and have access to all sorts of non-mundane substances... maybe you could pour liquid helium on the fire? (It'd splatter from the Leidenfrost effect, but the flying Helium droplets wouldn't harm anything in any chemical sense, "merely" a physical "being very cold" sense. So, suit up against frostburn, and move away any glassware to ensure it isn't shattered by the opposite of unequal heating.)
- slavik81 6y agoI don't know about chlorine trifloride, but that is one of the strategies used for reactive substances, like molten sodium: https://youtu.be/rAYW9n8i-C4?t=2m https://youtu.be/rAYW9n8i-C4?t=2m
- kortex 6y agoClF3 will react until there is nothing left to fluorinate. In practice, this means it'll react with most neutral elements, oxides, and chlorides. Certain oxides might act to poison the reaction, slowing it down by absorbing free radicals. Mainly, you wouldn't even want to be close enough to such a reaction to be able to douse it.
- pents90 6y agoIt's long past time to retire Lena as the canonical test image in CG.
- pkulak 6y agoLena and Big Buck Bunny for life!
- pkulak 6y agoWelp... I had no idea this was a centerfold photo and never gave it a second thought until now. I appreciate the heads up, op.
- enriquto 6y agoWhy? It's like "lorem ipsum" at this point.
- NoSorryCannot 6y agoIf lorem ipsum were softcore erotica...
- enriquto 6y agoWhat if I told you it actually is? > Quis autem vel eum iure reprehenderit, qui inea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? Translation: Who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? This text could very well be the first page of a softcore erotica (or even hardcore!). The rest of the text is not usually visible. But then again, neither is the rest of lena!
- NoSorryCannot 6y agoThis is a really big stretch in interpretation but also in plausibility, since Latin is a dead language. But if it were true, then you'd have it your way: it'd also be inappropriate in professional settings that don't naturally necessitate it.
- deleted 6y ago[deleted]
- karmakaze 6y agoFor the first image I much prefer the jpeg decoded image to the de-noised one. The de-noised one just looks like it was sent through a low-pass/median filter and loses contrast, detail, and texture. If you flip between the full-sized images the jpeg2png looks like vaseline on the lens. The naming is also odd. I don't imagine it would do well with text (which are the sorts of images I associate with png) that was jpeg encoded then decoded with it.
- KarlKemp 6y agoIt says it is specifically targeted at images that should have been png in the first place.
- Scaevolus 6y agoKnusperli is similar: https://github.com/google/knusperli https://github.com/google/knusperli Instead of trying to smooth the entire image, it reduces blocking artifacts by finding plausible coefficients that reduce discontinuities at block boundaries (jpegs are encoded as a series of 8x8 blocks). "jpeg2png gives best results for pictures that should never be saved as JPEG", but knusperli works well on normal photographic content, since it only tries to remove blocking artifacts. > A JPEG encoder quantizes DCT coefficients by rounding coefficients to the nearest multiple of the elements of the quantization matrix. For every coefficient, there is an interval of values that would round to the same multiple. A traditional decoder uses the center of this interval to reconstruct the image. Knusperli instead chooses the value in the interval that reduces discontinuities at block boundaries. The coefficients that Knusperli uses, would have rounded to the same values that are stored in the JPEG image.
- enriquto 6y ago> Instead of trying to smooth the entire image, it reduces blocking artifacts by finding plausible coefficients that reduce discontinuities at block boundaries This is essentially the same thing, but using slightly different regularizers. In both cases, an image is found that whose jpeg compression is identical to the given one, by selecting the "most regular" image among the large family of such images. Jpeg2png minimizes the total variation over the whole image, and knusperly only along the boundaries of the blocks. The effect is quite similar at the end.
- Scaevolus 6y agoThe effects are quite different, since reducing total variation also reduces texture, which is important to perceived quality. Here's a direct comparison-- note how knusperli retains slightly more detail instead of oversmoothing: https://mod.ifies.com/f/200710_lena_decode_comparison.png https://mod.ifies.com/f/200710_lena_decode_comparison.png
- enriquto 6y agoGood point. Unfortunately, the lena image is quite bad for comparison, there's almost no texture (except for the blue kerchief). I wonder what would happen for a heavily textured image; say, white noise. Would knusperly smooth it only along the block boundaries and leave it alone elsewhere?
- crazygringo 6y agoThis is really cool, but in other comments I'm reading that good JPEG encoders and decoders depend on knowing the other. That you can design a better JPEG encoder for a known reference decoder (which decoded version best matches the original), and you can likewise design a better JPEG decoder for a known reference encoder. But now that there are both encoders and decoders trying to be more efficient and non-blocky respectively... it feels like a mess. Even more so because a decoder never knows which encoder was used, and an encoder never knows which decoder. Is there any solution to this mess? Is there a best practice here? Since most JPEG's are probably viewed on the web, do all browsers share the same decoder, and so effort is best spent on the encoder? Or even while encoder improvements are made specifically for the algorithms browsers use, can improvements to decoders still be made that remain improvements, instead of e.g. "overfitting" and actually making things worse? This just feels like a bit of an "improvements race" on both sides which leaves me a little dizzy in trying to understand it...
- IgorPartola 6y agoThe obvious improvement is to use a better format than JPEG. Maybe something that can include information about the encoding process so the decoder can use that instead of guessing. Or maybe even a non-lossy format so we can focus more on data compression and less on visual compression.
- FriendlyNormie 6y agoShut up you dumb fucking faggot.
- ur-whale 6y agoSurprised no one has tried to build a GANN to do this (remove JPEG artifacts). Denoiser in ray tracing are quite a success, and this strikes me as quite similar. In fact, now that I think of it, you probably don't even need a GANN, since you can create an infinite training set for quasi-free.
- ache7 6y agoI've seen these projects on github. I don't remember the names, only that waifu2x upscaler has an NN filter for JPEG artifacts.