Cluster memory with approximation

A memory with nonlinear approximation inside data clusters is developed. Clusters are proposed to be allocated using the k-means method. The approximation should be carried out using the training of an ensemble of neural networks. Cluster memory is tested using an adaptive filter to convert image colors. According to the results of computer experiments, this type of memory showed good selective learning ability. By the example of an adaptive filter, it is possible to train the memory to change the entire color palette of the image.


A significant drawback of perceptron neural networks is their poor ability to generalize multicluster data. In particular, the XOR task for learning a logical function cannot be solved with a single perceptron, since two conflicting trends can be traced in one direction of the data points for an increase and decrease in the decisive function of a neural network. Such contradictory dependencies within the same training data array cannot be generalized by a single neural network of the form of a multidimensional perceptron. Therefore, it is proposed to divide the array of training data into clusters within which to approximate individual neural networks. A computer experiment is conducted in the article to test this type of memory for the task of an adaptive image filter for the selective conversion of a color palette.

Cluster analysis: k-means method

The k-means method is one of the most popular clustering methods. Its purpose is to obtain such data centers that would correspond to the hypothesis of compactness of data classes with their symmetric radial distribution. One way to determine the positions of such centers, for a given number of k , is the EM approach.

In this method, two procedures are performed sequentially.

  1. Definition for each data object Xithe nearest center Cj, and assigning a class label to this object Xij. Further, for all objects, their belonging to different classes becomes determined.
  2. Calculation of the new position of the centers of all classes.

Repeating iteratively these two procedures from the initial random position of the centers of k classes, one can achieve the separation of objects into classes that would correspond to the hypothesis of radial compactness of classes to the maximum.

A new author's classification algorithm will be compared with the k-means method.

Primary Image Colors

The k-means method applied to the color space of pixels in an image allows you to highlight the basic tones. To do this, it is proposed to convert the colors of RGB pixels to HSB using the Java Color.RGBtoHSB platform method and get a color hue H and brightness B. The distance between the pixels in the color space is proposed to be determined by the formula:

dist left(Xi,Xj right)= sqrtHi cdotBiHj cdotBj

The initial arrangement of cluster centers is proposed to be calculated as follows.

  1. Find min and max values Hi cdotBifor all pixels.
  2. Divide the interval [ min , max ] into k parts.
  3. Calculate pixel frequencies in each sub-interval by value Hi cdotBi.
  4. Sort the intervals by the number of pixels in descending order.
  5. Calculate pixel centers in subintervals.

Cluster Analysis: Gradient Map

The approach for conducting cluster analysis based on the k-means method has the disadvantage that there is no influence of the output image indices. To take into account the change in the indicators of the output image, depending on the change in the indicators of the input image, the following algorithm is proposed.

  1. Sort all input vectors by size Hi cdotBi
  2. When moving from one input vector to another in a sorted array, view the change in the monotonicity of the quantity Hi cdotBicorresponding output vectors.
  3. Monotonic input vectors Hi cdotBiassign the corresponding output vectors not larger than the selected threshold p to one class.
  4. The threshold p can be varied to divide the vectors into the desired number of clusters.

Adaptive filter

To implement image conversion, neural networks are possible. The main advantage of neural networks is their automatic learning ability. In this case, it is proposed to train an adaptive filter [Shovin 2018] based on a neural network to use a pair of images in which the original image is a sample, and the second is changed from a sample by any existing filter or transformation. The adaptive filter needs to restore this conversion. For this, a window of size dx by dy and 3 color channels is used. As a result, the dxdy • 3 input signals for input neurons are used in the neural network. The network can be supplemented by hidden layers of the number of neurons associated with the color factors of the filter conversion. It is proposed to use 3 neurons at the output of a neuron, the output signals of which are mapped to three colors ( rgb - red, green, blue) in the central pixel of the window from the output image. The signal of the color channel of the pixel is linearly converted into a range of values ​​[- 0.5 ; 0.5 ]. Whereas the antisymmetric sigmoid function with an interval of values ​​[- 1 ; 1 ]. For the boundary pixels of the images, when the window goes beyond the boundaries of the images, the input values ​​of the network neurons corresponding to such pixels are set to 0 . A neural network is trained on windows for all pixels of the output image by the method of back propagation of error.

Cluster memory

After the basic tones of the image are found, an adaptive filter is constructed for the pixels of each tone with a window width and height of 1 pixel. Filters are trained for each cluster separately. Thus, using neural networks of adaptive filters, the approximation of pixel colors within their cluster (tone) is carried out.

Numerical experiment

The cluster memory was trained using adaptive filters as an example for transforming a color palette.

Fig. 1. Original and modified palette.

An adaptive filter requires learning to selectively whiten skin colors without changing other colors.

As a result of applying an adaptive filter with cluster memory (9 clusters-tones and clusters according to the gradient map) to the original palette, the following images were obtained:

Fig. 2. The changed palette for the basic tones and the gradient map.


An approach is proposed for learning complex functions based on cluster memory with approximation using a family of neural networks and conducting cluster analysis of the source data. Using the adaptive filter as an example, the possibility of selective conversion of palette colors is shown. The use of cluster memory with approximation is relevant when conflicting trends in the same directions of changes in the indicators of the source data are traced in the training data set. In particular, it is possible to solve the XOR problem for learning a logical function.

  1. Shovin V.A. Adaptive image filter based on a neural network. // Mathematical and computer modeling: a collection of materials of the VI International Scientific Conference. 2018 .-- 198 p.


All Articles