When you move away from ImageMagick and libpng, there are other possibilities.Ģ) While it would be possible to train a neural network to decide whether JPG or PNG would compress better, it would probably take longer and be less exact than just trying both and looking at the output. JPGs will fare better with photos which tend to have more jitter, which is hard to compress. In short: PNGs will work well with computer-generated images, because those tend to be quite regular and thus easy to deflate. Note also that there are programs that are able to do lossy compression in PNG (which could well beat JPG compression in some cases). With a higher compression ratio, JPG files will be much smaller, but the artifacts will be more pronounced. Note that PNG is usually used to losslessly compress images, while JPG is inherently lossy. For photos, this is usually not a problem also for high-resolution textual images the problem will be much less pronounced (because the blur radius is smaller relative to image size). Maybe you could run the script against the type of images you normally use and see what you get.ġ) JPG is usually not as good for text because the artifacts tend to "smear" or blur the image. not very scientific, but something at least. Set terminal postscript color landscape dashed enhanced 'Times-Roman'Īnd I got the following plot which shows that as ImageMagick's entropy number increases, the ratio of JPEG size to PNG size improves in favour of JPEG. Then I created the following gnuplot command file plot.cmd: set title 'Plotted with Gnuplot' Then I ran each of the files through the first script, like this: for f in xx*.jpg do. That gives me files called xx1.jpg with 1% noise, xx2.jpg with 2% noise and so on, up to xx99.jpg with 99% noise. # Make greyscale version for entropy calculationĮntropy=$(identify -verbose -features 1 temp.jpg | grep -A1 " Entropy:" | tail -n 1 | awk -F, '.jpg done Jsize=$(convert "$f" -strip JPG:- | wc -c) I made a little script to calculate the following for a given input file: I do not have a pile of sample images to test my theory on, so I did it a different way. Ok, I have had a little more time to spend on this now. I think the last value is the only one you need consider. There are 5 values for each type of entropy - horizontal, vertical, left diag, right diag and overall. I suspect images with a higher entropy will compress better as JPEGs and those with a lower entropy will fare better as PNGs - but I have to dash now :-) If you use ImageMagick, you can calculate the Entropy easily like this: identify -verbose -features 1 image.jpg | grep -i -A1 entropy I have absolutely no time to develop this line of thought further but the image entropy is probably a good discriminant for selecting JPEG or PNG - see my earlier comment on your question.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |