📜 ⬆️ ⬇️

Neural network as a predictor for PNG image coding

I bring to your attention the translation of the article Neural Network As Predictor For Image Coding (PNG) . The author's blog is here .

Research topic


The main reason for this work was the improvement of existing pre-filters . Create a new filter that, using an artificial neural network, would make the best prediction, leading to better file compression.

Compression


Classically PNG compression is divided into two steps:
')
  1. Pre-filtering (using predictors);
  2. Compression (using DEFLATE).

In this article, only the first step is important. In the image below, you can see the pre-existing filters currently in use, and how they maintain the difference between the real and predicted pixel.

Predictor job
Current filters + new solution:
Type ofNameFilter functionRecovery function
0NoneFilt (x) = Orig (x)Recon (x) = Filt (x)
oneSubFilt (x) = Orig (x) - Orig (a)Recon (x) = Filt (x) + Recon (a)
2UpFilt (x) = Orig (x) - Orig (b)Recon (x) = Filt (x) + Recon (b)
3AverageFilt (x) = Orig (x) - floor ((Orig (a) - Orig (b) / 2))Recon (x) = Filt (x) + floor ((Recon (a) - Recon (b) / 2))
fourPaethFilt (x) = Orig (x) - PaethPredictor (Orig (a), Orig (b), Orig (d))Recon (x) = Filt (x) + PaethPredictor (Recon (a), Recon (b), Recon (d))
fiveNeural NetworkFilt (x) = Orig (x) - NN (ArrayOfInputPixels)Recon (x) = Filt (x) + NN (ArrayOfInputPixels)

Neural network as a predictor


The last filter is a new implementation of the author of this article. It internally uses a neural network with an array of input pixels. As a result, returns the predicted pixel variable. As in other filters, the difference between the original and the predicted value is maintained. But what are these input values ​​you ask? In the figure below, the author tried to describe the process of transferring the neural network of input values ​​more clearly and clearly. First, there are three different parts of the image:

  1. Copied (indicated by RED);
  2. Input pixels for the neural network (indicated by GREEN);
  3. Predicted pixel (denoted BLUE).

Image areas

Copied pixels

The entire red area will be copied 1: 1, since the initial data is required to start the work of the neural filter. This is the reason for copying such an image frame. The network configuration was as follows:


So all pixels from 1st to 28th will be copied.

Input pixels

The first pixel processed by the filter is in position (5.4) . This pixel can be predicted using the remaining 28 pixels and the neural network. This is evident from the illustration above.

Projected pixel

All green pixels are input pixels that the neural network processes, resulting in the predicted value for the BLUE pixel.

Components


In this section, the author describes the components developed and used. All code is written in JAVA.
At the first stage it is necessary to train the neural network. To accomplish this step a little faster, the author developed the Pattern Exporter, which creates a training sequence for the JavaNNS Tool. For clarity, this step describes the figure below.

image

After completing the training of the neural network, it must be used in the encoder / encoder. A detailed explanation of the described stage is shown in the figure below.

image

  1. Input Image: A simple image that will compress the neural network.
  2. PNG Encoder / Decoder: Encoding and decoding an image using a predictor on a neural network.
  3. Neural Netwrok: a neural network developed in the JAVA programming language.
  4. JNNSParser
  5. Output image: as output, the image should be smaller than what was compressed.

For encoding and decoding, the author used the pngj library. You can find it here .

results


There are many ways to select a neural network configuration.

image

Possible ways to select a neural network configuration:


Below are some of the best options estimated by the author for designing a neural network. He mainly evaluated them by simply checking with several samples of images, and then he calculated the BPP (bit per pixel) of the neural network and determined the best parameters. This led to the following results:

image

Neural network estimated configuration:


Comparison with other PNG predictors

At the next stage, the author compared his neural filter with other PNG filters that are currently in use. Testing took place on several images.

image

It can be seen that the neural network copes with image compression somewhat worse than Paeth and Average filters, but it is much better than Sub and Up. After this check, another one was carried out, and much more images (111) participated in which nature was captured. It was necessary to find out which image the filter copes with best, and which worse. It shows the images that the neural network coped with much better than all the other filters:

image

I wasnt sure what these pictures have in common. Well there are many flowers. So maybe my Neural Network really likes Flowers. But I wasn't very comfortable with that explanation.

So, we can conclude that the neural network is good to use if it is present in the image:


In the next step, the author rummaged in his photos taken during the holidays to find the one that would satisfy the conditions described above and found one:

image

As a result, the following BPP values ​​were calculated for 6 filters:
Type ofNameBPP
0None7.289
oneSub6.681
2Up6.667
3Average6.433
fourPaeth6.486
fiveNn6.368

Thus, the theory of image features for better compression using a neurofilter was confirmed.

Comparison of images of nature with the image that man created


The author conducted one more test to find out how the origin of an object in an image affects compression. The following results were obtained:

image

Conclusion



The project is on GIT Hub. Who is interested, you can see .

Source: https://habr.com/ru/post/303842/


All Articles