An ACO algorithm for image compression

This paper is an application of Ant Colony Metaheuristic (ACO) to the problem of image fractal compression using IFS. An ACO hybrid algorithm is proposed for image fractal compression and the results obtained are shown. According to the tests carried out, the proposed algorithm offers images with similar quality to that obtained with a deterministic method, in about 34% less time.


Introduction
For over 15 years, data compression has had relevance due to the increasing volume of personal and professional information (documents, videos, audio, images) that we use everyday.Data compression software is constantly used to store or transmit information with methods that try to reduce redundant information in data file content and thus, to minimize their physical space.Image fractal compression is among data compression methods.Defines in [11] as an image that can be completely determined by a mathematical algorithm in its thinnest texture and detail, it can then be inferred that fractal compression consists in obtaining an approximation of a real image by means of a set of mathematical transformations applied to certain blocks in the image.A restriction on these methods is the high computational cost of image compression.An analogy with the real ants' behavior was presented as a new paradigm called Ant Colony Optimization (ACO).The main features of ACO are the fast search of good solutions, parallel work and use of heuristic information, among others.Several problems have been solved using ACO: TSP, Knapsack, Cutting Stock, Graph Coloring, Job Shop, etc.This paper proposes an ACO hybrid algorithm for image fractal compression, a problem still unsolved with ACO.In section 2, we describe some theoretical aspects of both fractal compression and ACO.In section 3, the proposed algorithm and its variations with regard to ACO algorithms is detailed.In section 4, we show results from different tests, using varying parameter values in the proposed algorithm and comparing them to those in a deterministic one.Finally, in section 5, we suggest some aspects to bear in mind in ACO algorithm implementation based on our experience as well as possible improvements to the proposed one.

Fractal Compression and Ant Colony 2.1 Fractal Compression
Storing an image, for example, that of a fern in the form of pixel collection, takes up a lot of memory space -about 256 Kb. for an image of 256*256 pixels-if good resolution is required.Nevertheless, it is possible to store a collection of numbers that defines certain transformations capable of generating the fern image, but occupying 4 Kb in memory at the most.If a collection of transformations is capable of generating this for a given image, then the image can be represented in a compact way.Fractal compression describes the scheme to obtain such collection.For more details, see [7].Suppose that we have an image I that we want to compress.We are looking for a collection of transformations w 1 , w 2 , . . ., w n such that W = w i and I =| W |, i.e.
To achieve this, image I must be broken up into blocks so that the original image is obtained when applying transformations.However, there are images that are not made up of blocks that might be easily transformed to obtain I.But an approximation I =| W | where the distance d(I, I') is the smallest possible to be obtained, i.e. what is needed is to minimize the distance between original image blocks and the transformed blocks, i.e.: Thus, domain blocks D i and w i transformations have to be found in order to be as close as possible to an image block R i (also called region) after applying a transformation to a domain block Some definitions are given below: An affine transformation w : R n → R n can be written: Where A, an n-order matrix in R n×n is called deformation matrix1 of w and vector b in R n , is called the traslation vector of w.
• An affine transformation w, is contractive if A < 1.If there is 0 ≤ s ≤ 1, so that A < s, s being the contraction factor for the transformation w.
• Let R n be the vectorial space with a metric d (also called distance function), An Iterated Function System(IFS) in this space is a set of finite contractive transformations, W = {w 1 , w 2 , . . .w m }.The contraction factor s is defined as the maximum of the contraction factors in the transformations s = max{ w 1 , w 2 , . . ., w m }.An IFS defines its associated transformation on the space of compact subsets D(R n ) by W (I) = w i (I) for all • Given an IFS {w 1 , w 2 , . . .w m } there is a unique invariant set I so that I = m i=1 w i (I).I is the attractor of w.
• Given a metric d on n-dimensional space R n , two sets A, B ∈ R n , the distance between A and B can be expressed as: This distance function is called Hausdorff metric of d.
• To know how to approximate an IFS attractor to an image, we use the Collage Theorem.
Let W = {w 1 , w 2 , . . ., w m } be an IFS with contraction factor s, W : Therefore, the problem of searching an attractor A close to an image I is equivalent to minimizing the distance d(I, m i=1 w i (I)).

Fractal Compression Deterministic Algorithm
This algorithm was proposed by Barnsley [1].It divides the image into a grid of non-overlapping range blocks R = {R i } and domain blocks D = {D i } in which partial overlapping can exist.For each range block R i , the algorithm performs an exhaustive search over domain blocks, until a domain block D j is found so that the distance d = (R i , w ijk (D j )) is minimal.Then it saves the coordinates of D j and the type of transformation applied.The algorithm is shown in Figure 1.
A characteristic of fractal compression is that the decompression resolution is independent of image size, so that the chosen size for decompression can be different from the size of the original image, without changing the resolution.

ACO
Ant colonies are distributive systems that form highly structured social organizations allowing them to perform complex tasks that in certain cases, exceed the individual capacities of a single agent ( [2]), as in the case of food search.Basically, ants go out of the nest to look for food leaving a trace on the ground, called pheromone.In case the path chosen by an ant is shorter (in terms of time or some other measurement) than that of the rest of the ants, it would be able to deposit the food Figure 1: Exhaustive algorithm in the nest and return to look for more, thus increasing the pheromone on its path, causing other ants to follow the same path as a result of the high level of pheromone on the ground.ACO algorithms used for solving optimization problems were developed based on the observation of the ant behavior described above.One of the most best-known ACO algorithms, is Ant System(AS).It was created in 1992 by Marco Dorigo and used to solve the TSP, based exactly on the fact that ants find the shortest path to go from the nest to the food source.

AS-ACO
Some details of AS-ACO algorithm that adapt actual ant behavior to minimal cost graph are shown below associating a variable τ ij called the artificial pheromone trace to every edge(i,j) of graph G=(V, E).As already mentioned, ants follow the pheromone trace.The amount of pheromone deposited on each edge is proportional to the utility achieved.Every ant constructs a step-wise solution to the problem.At each node, the ant uses the stored local information to decide the node to reach next.When an ant k is in node i it uses the pheromone trace τ ij left on edges and heuristic information, to choose j as the next node, according to the random proportional rule: being N k i the ant k neighborhood, in node i.The node i neighborhood comprises all the nodes connected directly to it in the graph G=(V, E), except its predecessor to avoid returning to previously visited nodes.
Applying decision rule at each node, ant k will eventually reach the final node.Once ant k has completed its path, it deposits an amount of pheromone on the edges visited given by the following equation: Thus, when the other ants are in node i, they will be more likely to choose node j as their next one due to higher concentration of the pheromone.An important aspect is the value that ∆τ k takes.
In general, the amount of pheromone deposited is a decreasing function of path length.Pheromone evaporation can be understood as a mechanism that allows rapid convergence of the ants towards a sub-optimum path (see [4]).In fact, decreasing pheromone favors the exploration of different paths during the search process and avoids the stagnation in local-optimum.In actual ant colonies, evaporation takes place but does not play an important role in shorter path search.
The evaporation leaves behind bad decisions, and allows a continuous improvement in achieved solutions.Pheromone evaporation is applied using the following equation: for all edges (i,j) from graph G and ρ ∈ (0, 1] a parameter of the algorithm.
A general framework for the Ant Colony can be:

Algorithmic Details
This section explains how ACO metaheuristic was adapted to image compression problems, detailing aspects related specifically to compression.

Pheromone
The success of an ACO algorithm depends, among other variables, on pheromone trace definition.This depends on the problem to be solved.For example, in the TSP solved in [3], the pheromone deposited on edge (i, j) denotes the benefits of going to city j, from city i.In the Bin Packing problem solved in [10], the pheromone deposited on edge (i, j) reflects the benefit of having items i and j in the same bin.In our work, the pheromone deposited on edge (i, j) refers to associating range block i and domain block j.The pheromone matrix is rectangular (not symmetrical) where the rows indicates range blocks (image blocks) and the columns domain blocks (blocks to transform).

Heuristic Information
The possibility of using heuristic information to direct probabilistic construction of solutions by the ants is important because it allows considering problem specific knowledge.This knowledge can be available a priori (static problems) or at run time (dynamic problems).In static problems, the heuristic information is calculated in every run of the algorithm.Examples are the inverse of distance between cities i and j used in the TSP problem of [5] and the size of item j used in the Bin Packing Problem of [10].The static heuristic has the advantage of being computed at every iteration of the algorithm together with the pheromone information.In the case of dynamic problems, the heuristic information depends on building partial solutions and must be calculated at each step taken by the ants.Bear in mind that the use of heuristic information is important for an ACO algorithm and that its importance decreases if local search algorithms are used.Depending on the problem to be solved, the definition of the heuristic information will be more or less complex.In section 4, the quality of the solutions obtained by the algorithm using heuristic information and local search is analyzed.
In our work several alternatives of heuristic information were tested.Using the inverse of the error obtained when using the domain block j for approximating domain block i, was found to be the best one.This heuristics has to be obtained dynamically in contrast to other problems solved with ACO, where the heuristic information is static(TSP, Bin Packing, Snapsack, Job Shop, etc); the reason for this being that the error information to approximate domain blocks is not available before the optimization process and, therefore, the exhaustive exploration of the solution space is important.Further details about other options are given in section 5.

Problem Solving
As indicated previously, ants construct feasible solutions using heuristic information and pheromone.Every ant constructs its path choosing one domain block j for every range block i.The probability that an ant k chooses one domain block j for the range block i, is given by following equation: J otherwise (8) where: • η ij = 1 err ij and err ij is the error incurred in choosing block j as being close to block i.
• q is a uniform random variable [0,1).In contrast to [4], where Ant Colony System algorithm (ACS) described uses a fixed parameter q 0 that serves as threshold for choosing between a probability calculation or selecting a node in a deterministic way.In this paper we use one Simulated Annealing (SA) characteristic consisting in the selection of poor solutions using an exponential expression.In addition, it is necessary to mention that the ants we used perform different kinds of work.Good and bad ants were basically used for the construction of solutions.Expression 8, allows the choice of "bad" blocks at the beginning of the search process.We use this option for the exploration of new solution spaces.Our local optimum scape mechanism is based on the Simulated Annealing algorithm used to solve an Assignment Problem in ( [12]).
• J is a random variable that selects a good block from neighborhood i.
The construction of solutions thus consists in choosing a domain block j for every range block i of the image, according to the above equation.

Pheromone Update
Once all ants have constructed their paths, the pheromone level is updated by evaporation followed on the deposit of new pheromone value as indicated next: Where ∆τ super ij = 1/C super , and C super is an objective function value obtained by a "super" ant.The adopted criterion is similar to MAX-MIN ( [4]), where a selected ant is the one that deposits pheromone in every iteration.The ACO MAX-MIN algorithm is easy to implement and it yields good results.Nevertheless, a path for a "super" ant was generated at each iteration in this paper.This path is obtained from the best domain block and an associated transformation for each range block, which was found by the other ants.That is to say, the ants perform cooperative work so that only one ant deposits pheromone in a chosen path generated by the best selections of the ant colony.

Objective Function
In order for the proposed algorithm to achieve good solutions, an objective function that measures the quality of the solutions must be used.In [3], the objective function was the minimal cost of vehicle routing, in [5] the total minimal distance for visiting all cities, in [10] an average of bin usage.Here a similar expression for fitness as the one used in [13] was applied.It basically measures the distance between image blocks (range) and domain blocks.The expression to minimize is: where: • r i (x, y) is the pixel (x,y) of range block i

Local Search and ACO
When local search is used, ACO algorithms improve their performance.We can mention [3], where 2-OPT heuristic is applied for improvement of solutions in the routing problem and [10] that uses the Martello and Toth dominance Criterion, among others.The reason why ACO algorithms coupled with local search algorithms provide good solutions, is that they are complementary.An ACO algorithm generally achieves intermediate quality solutions, whereas local search algorithms search in the solution neighborhood, trying to improve the solution quality further.
As regards local search algorithms, the crossover operator proposed in the genetic algorithm of [13] and a local search algorithm used in [9] can be mentioned.Nevertheless, using the above mentioned algorithms implies a high computational cost.A better alternative can be obtained by a modification of Jacquin's algorithm [8] consisting in performing the computation prior to problem solving through the block classifications.
Here two local search algorithms are used.Algorithm 1: based on the possibility of having similar blocks in images forming a region (e.g., in an tree image, surely there are zones where a group of leaves are very similar among them), given an image block r i and a domain block d j , the algorithm compares the latter with neighboring blocks of r i .Figure 3, illustrates the operation of Algorithm 1.

Figure 3: Local Search Algorithm
Algorithm 2: in order to improve the quality of solutions and explore new domain blocks, for any image range block whose error in approximation is higher than the average known for the best solution so far, the algorithm assigns a random domain block even not used.
In Figure 4, a pseudocode appears.
The results of some tests are commented in this section.First, the parameters of the ACO algorithm proposed will be defined and then their results will be compared with the deterministic algorithm proposed in [11].Then the results obtained by the proposed algorithm both with and without local search will be analyzed.The experiments were done on several test images -landscapes, human faces, animals, etc.-with similar results in terms of quality and time to those reported here2 .

Parameters
The parameters that will be defined correspond to our ACO algorithm: • Number of ants: indicates the ants that will construct solutions for each iteration.According to( [4]), 10 is a reasonable value.Nevertheless, other values will be considered.
• β: defines the importance of using heuristic information in contrast to pheromone information.
In [4], 2 is the recommended value, in [10] 2 and 5 were used, whereas 10 and 5 were used in [5].According to our tests, this parameter is not as relevant as the others.
• α: defines the importance of the pheromone trace.The value recommended in [4] and [10] is 1, whereas in [5] 0.1 was used.Also, it presents the same characteristic as that of β in relevancy.
• ρ: is the evaporation factor used for the control of pheromone level deposited on paths.Values close to 1 are recommended ([6], [2]).
• Stop criterion: is the number of times that the ants as a whole construct new solutions.There are others alternatives to stop execution of these algorithms, e.g.difference between two consecutive solutions, cpu time, stagnation of solutions, closeness to ideal solution, among other ones.
• Factor S: is used to obtain an initial solution.It is obtained from the sum of the product between a factor s and the difference of averages between range and domain blocks used.For the performed tests, using factors between [7,15] is recommended.
• Block size (pixels): indicates domain and range blocks size.Smaller size implies a better approximation.Based on our test results, where we evaluate time and quality, the value used is 8x8.
In Figure 5, the compressor interface is shown.Using heuristic information and pheromone, the ants build their paths in parallel.Nevertheless, the quality of solution depends on the ant position in the construction of solutions.
Procedure Construct solution(pheromone matrix,error matrix,#ants,#img,α, β)    1, the best results correspond to evaporation factors between 0.5 and 0.7, i.e., good results with a computational time near to 50% of that used by the deterministic algorithm and objective function value within 24%.
Figure 6 shows the original image, deterministic compression and our best result so far.According to the results obtained in Table 3, we can say that: • Using 10 ants and 55 iterations, i.e., more iterations than the best solution obtained up to Table 2, a better solution is obtained but at the price of higher execution time (72.1 % of necessary time to obtain the deterministic value).
• Using more ants than the best solution of table 2 and fewer iterations (15 ants and 35 iterations) the results obtained do not improve over those achieved before.
• Better execution times and quality in solutions than the best solution up to Table 2 were obtained, and they correspond to results of the last row (42.3 % of deterministic time and a variation of 23.5 % respect to the deterministic algorithm).However, there is a solution with less computation time and acceptable quality (previous to last row) shown in Figure 7.
Figure 7: Deterministic image and results of Table 1 and Table 3 As observed in Figure 7, the quality obtained with 5 ants and 45 iterations are "acceptable" with a computational time equal to 34.5 % of the deterministic algorithm and a variation from the deterministic value of 25.6 %.  4, the best result without applying local search is higher than twice the best solution with local search (23.5 %).Also, the execution time is slightly shorter.Figure 8 shows the deterministic result and best solutions with and without local search.The proposal of [13] to solve the fractal compression was done using a simple objective function.
The reported results shows a variation of 65 % with respect to optimal value with a computational time of 330 minutes.
In our work and in accordance with the tests performed, it is possible to obtain good-quality images with execution times close to 34 % of the deterministic time, with a variation of objective value of 25.6%.The execution time and compressed image quality allow us to state that ACO metaheuristic can be applied successfully to the fractal image compression problem.Also, our algorithm is another possible alternative for image compression.
To achieve good results, it was necessary to consider the following factors: • Number of ants: in accordance with [4], the use of 10 (or n ants where n is in this case the number of domain blocks) is recommended.In our case, we used the first one.Bear in mind that each ant stores its path and this affects the available memory.For this reason, it is not advisable to use too many ants.
• Iterations: they depend on the problem.They are intimately related to the number of ants, and also to the number of ants that deposit pheromone.At the first stages, "acceptable" results must be allowed as the algorithm improves the initial solution proposed.That is to say, with few iterations low-quality results are obtained.
• Evaporation factor (ρ): [6] uses 0.5 to solve the TSP problem.In this work, good results were obtained with values close to 0.7.The important thing to consider with this parameter is the fact that values near to 1 force to the exploration of new spaces of solutions while values close to 0 explore the environment of the current solution.
• Initial solution: in [2], [4] and [6] the initial pheromone applied at each edge(i, j) is done using a function that relates the number of ants with an initial solution.These works do not precise the distance this gives to the desired solution.It is important that this situation be taken into account.In this paper it is shown that the initial solution must be at most between 1.7 and 2.5 times the best value.Higher values cause a slow descent towards good solutions, while lower values can cause unfeasible solutions.Ant Colony does not need initial solutions of high quality, but it does requires them not to be too far.
• Local search: in [4] mentions the importance of the heuristic information even though it does not apply local search to the TSP problem.In this work, we mostly consider the use of local search algorithms to avoid stagnation and to ensure fast convergence to reasonable solutions.When local search was not used, the solutions obtained were far from the expected results (twice the best obtained using local search).Although this difference can be reduced, the price to pay is a bigger number of iterations causing higher execution times that not necessarily ensure reasonable solutions.
• Heuristic Information: in [3] (like most ACO proposals) considers the inverse of the distance between pairs (i, j) as heuristic information.On the other hand, [10] considers the size of items j as heuristic information.In our case, the following three alternatives were considered, being the third one the one that yielded better results: -Difference of mean value: this alternative did not yield good results, because it was affected by extreme values.In our tests, reconstructed images had the same tonality in the whole image.
-Frequencies(i, j): it consists of saving the number of times that domain block j was used to compare with range block i.This option did not work, because it is possible that the ants choose bad domain blocks(major error) and cause the others to follow the same path and thus increase the frequency of use.
-Error of selection(i, j): as indicated previously, it is the error caused by choosing domain block j to compare with range block i.Thus, the frequencies are not considered.Also, the information is variable, not fixed as in the the majority of problems solved with ACO.Basically, the selection error is equivalent to the cost of selection.
Finally, there are several possible strategies that can be applied to improve results: • Categorization of blocks: in [8] this is done to solve the problem in deterministic manner.Nevertheless, the time of block categorization before solving the problem must be considered.Through the categorization of blocks it is possible to obtain compressed images that are more similar to the original ones and have better compression ratios.
• Local search: to improve paths obtained by the ants using other local search algorithms.
• Cooperative work: In our work, all ants collaborate to obtain a better path.However, several types of ants can be defined each performing different tasks and collaborating to ensure better solutions.

Figure 8 :
Figure 8: Deterministic result and solutions with and without local search Return ant listGenerating the best path for the "super" ant means selecting the best domain blocks achieved by the ants.Update pheromone consists of evaporation and deposit.Only the "super" ant performs updates.

Table 1 :
Comparison of deterministic algorithm and ACO, using different values of ρ.

Table 1 :
ACO results, using different values for evaporation factorAccording to Table

Table 2 :
ACO results, using different values for ants and iterations

Table 3 :
Comparison of deterministic algorithm (Value: 4996545, Time: 402 secs) and ACO, using different values for ants and iterations.

Table 3 :
ACO results, using different values for ants and iterations

Table 4 :
Comparison of deterministic algorithm (Value: 4996545, Time: 402 secs) and ACO, using different values of ants and iterations, without local search algorithms.

Table 4 :
ACO results, using different values for ants and iterations, without local search From Table