Keywords

1 Introduction

Fractals are one of the most challenging and intriguing mathematical shapes ever defined. Basically, they are geometric figures created by repeating a simple process over and over so that it yields a self-similar pattern across different scales. Interestingly, in the case of fractals, the scale factor of this replicating pattern is not an integer number, but a real one. Such a number is called the fractal dimension and it is usually larger than the topological dimension of the fractal [3, 9]. Fractals have become ubiquitous objects in popular culture, particularly since the 80s of last century, owing to the technological advances in hardware and software and the widespread availability of personal computers. They are also very popular in science due to their ability to describe many growing patterns and natural structures commonly found in real-life objects: branches of trees, river networks, coastlines, mountain ranges, and so on. Furthermore, fractals have found remarkable applications in computer graphics, scientific visualization, image processing, dynamical systems, telecommunications, medicine, biology, arts, and many other fields [1, 3, 9, 11, 12].

There are several methods described in the literature to obtain fractal images. They include the Brownian motion, escape-time fractals, finite subdivision rules, L-systems, strange attractors of dynamical systems, and many others [1, 3]. One of the most popular methods is the Iterated Function Systems (IFS), originally conceived by Hutchinson [13] and popularized by Barnsley in [1]. Roughly, an IFS consists of a finite system of contractive maps on a complete metric space. It can be proved that the Hutchinson operator over the set of all compact subsets of this space has a unique non-empty compact fixed set for the induced Hausdorff metric, called the attractor of the IFS. The graphical representation of this attractor is (at least approximately) a self-similar fractal image. Conversely, each self-similar fractal image can be represented by an IFS. Obtaining the parameters of such IFS is called the IFS inverse problem. Basically, it consists of solving an image reconstruction problem: given a fractal image, compute the IFS whose attractor approximates the input image accurately.

This IFS inverse problem has shown to be extremely difficult. In fact, the general case is still unsolved and only partial solutions have been reached so far. In this paper we propose a new approach to address this problem for the case of binary fractal images. Our methodology consists of the hybridization of a bio-inspired metaheuristics based on the cuckoo search algorithm for global optimization and a local search procedure. In particular, we consider a modification of the original cuckoo search method called the improved cuckoo search (ICS), which is based on the idea of allowing the method parameters to change over the generations [16]. This method is hybridized with the Luus-Jakoola (LJ) heuristics, a search method aimed at improving the local search step to refine the quality of the solution.

The structure of this paper is as follows: Sect. 2 introduces the basic concepts and definitions about the iterated function systems and the IFS inverse problem. Then, Sect. 3 describes the original and the improved cuckoo search algorithms. Our proposed method is described in detail in Sect. 4, while the experimental results are briefly discussed in Sect. 5. The paper closes with the main conclusions and some ideas about future work in the field.

2 Basic Concepts and Definitions

2.1 Iterated Function Systems

An Iterated Function System (IFS) is a finite set \(\{\phi _i\}_{i=1,\dots ,\eta }\) of contractive maps \(\phi _i: \mathbf {\Omega } \longrightarrow \mathbf {\Omega }\) defined on a complete metric space \(\mathcal {M}=(\mathbf {\Omega },\mathbf {\Psi })\), where \(\mathbf {\Omega } \subset \mathbb {R}^n\) and \(\mathbf {\Psi }\) is a distance on \(\mathbf {\Omega }\). We refer to the IFS as \(\mathcal{W}=\{\mathbf {\Omega }; \phi _i,\dots ,\phi _\eta \}\). For visualization purposes, in this paper we consider that the metric space \((\mathbf {\Omega },\mathbf {\Psi })\) is \(\mathbb {R}^2\) along with the Euclidean distance \(d_2\), which is a complete metric space. Note, however, that our method can be applied to any other complete metric space of any dimension without further modifications. In this two-dimensional case, the affine transformations \(\phi _\kappa \) are of the form:

$$\begin{aligned} \left[ \begin{array}{c} \xi _1^* \\ \xi _2^* \\ \end{array} \right] = \phi _\kappa \left[ \begin{array}{c} \xi _1 \\ \xi _2 \\ \end{array} \right] = \left[ \begin{array}{cc} \theta _{11}^\kappa &{} \theta _{12}^\kappa \\ \theta _{21}^ \kappa &{} \theta _{11}^ \kappa \\ \end{array} \right] . \left[ \begin{array}{c} \xi _1 \\ \xi _2 \\ \end{array} \right] + \left[ \begin{array}{c} \sigma _1^ \kappa \\ \sigma _2^ \kappa \\ \end{array} \right] \end{aligned}$$
(1)

or equivalently: \(\mathbf{\Phi }_\kappa (\mathbf{\Xi }) = \mathbf{\Theta }_\kappa .\mathbf{\Xi } + \mathbf{\Sigma }_\kappa \) where \(\mathbf{\Sigma }_ \kappa \) is a translation vector and \(\mathbf{\Theta }_ \kappa \) is a \(2\times 2\) matrix with eigenvalues \(\lambda _1^ \kappa ,\lambda _2^ \kappa \) such that \(|\lambda _j^ \kappa | < 1\). In fact, \(\mu _\kappa =|det(\mathbf{\Theta }_ \kappa )|<1\) meaning that \(\phi _\kappa \) shrinks distances between points. Let us now define a transformation called the Hutchinson operator, \(\varUpsilon \), on the compact subsets of \(\mathbf {\Omega }\), \(\mathcal{H}(\mathbf {\Omega })\), by:

$$\begin{aligned} \varUpsilon (\mathcal {B})=\bigcup \limits _{\kappa =1}^{\eta } \phi _{\kappa }(\mathcal {B}) \end{aligned}$$
(2)

with \(\mathcal {B} \in \mathcal{H}(\mathbf {\Omega })\). If all the \(\phi _\kappa \) are contractions, \(\varUpsilon \) is also a contraction in \(\mathcal{H}(\mathbf {\Omega })\) with the induced Hausdorff metric [1, 13]. Then, according to the fixed point theorem, \(\varUpsilon \) has a unique fixed point, \(\varUpsilon (\mathcal {A})=\mathcal{A}\), called the attractor of the IFS.

Consider a set of probabilities \(\mathcal{P}=\{\omega _1,\dots ,\omega _\eta \}\), with \(\sum _{\kappa =1}^\eta \omega _\kappa =1\). There exists an efficient method, known as probabilistic algorithm, for the generation of the attractor of an IFS. It follows from the result provided that \(\mathbf{\Xi }_0 \in \mathbf {\Omega }\), where: \(\mathbf{\Xi } _j=\phi _\kappa (\mathbf{\Xi }_{j-1})\) with probability \(\omega _\kappa >0\), see [2]. Picking an initial point \(\mathbf{\Xi }_0\), one of the mappings in the set \(\{\phi _i,\dots ,\phi _\eta \}\) is chosen at random using the weights \(\{\omega _1,\dots ,\omega _\eta \}\). The selected map is then applied to generate a new point, and the same process is repeated again with the new point and so on. As a result of this stochastic iterative process, we obtain a sequence of points that converges to the fractal as the number of points increases [1, 10].

2.2 The Collage Theorem

The Collage Theorem basically says that any digital image \(\mathcal{I}\) can be approximated through an IFS [1, 10]. In particular, it states that given a non-empty compact subset \(\mathcal{I} \in \mathcal{H}(\mathbf {\Omega })\), the Hausdorff metric H(., .), a non-negative real threshold value \(\epsilon \ge 0\), and an IFS \(\mathcal{W}=\{\mathbf {\Omega }; \phi _i,\dots ,\phi _\eta \}\) on \(\mathbf {\Omega }\) with contractivity factor \(0<s<1\) (the maximum of the contractivity factors \(s_\kappa \) of maps \(\phi _\kappa \)), if \(H\left( \mathcal{I}, \varUpsilon (\mathcal{I})\right) = H\left( \mathcal{I},\bigcup \limits _{\kappa =1}^{\eta } \phi _{\kappa }(\mathcal{I})\right) \le \epsilon \) then \({\displaystyle H\left( \mathcal{I},\mathcal{A}\right) \le {{\epsilon } \over {1-s}}}\), where \(\mathcal{A}\) is the attractor of the IFS. That is: \({\displaystyle H\left( \mathcal{I},\mathcal{A}\right) \le {{1} \over {1-s}} H\left( \mathcal{I},\bigcup \limits _{\kappa =1}^{\eta } \phi _{\kappa }(\mathcal{I})\right) }\).

2.3 The IFS Inverse Problem

Suppose that we are given an initial fractal image . The Collage Theorem says that it is possible to obtain an IFS \(\mathcal{W}\) whose attractor has a graphical representation \(\mathcal{F}^{\blacksquare }\) that approximates accurately according to a similarity function \(\mathcal {S}\), which measures the graphical distance between and \(\mathcal{F}^{\blacksquare }\) [1]. Note that once \(\mathcal{W}\) is computed, for any (not necessarily fractal) initial image . Mathematically, this means that we have to solve the optimization problem:

(3)

The problem (3) is a continuous constrained optimization problem, because all free variables in \(\{\mathbf{\Theta }_\kappa ,\mathbf{\Sigma }_\kappa ,\omega _\kappa \}_i\) are real-valued and must satisfy the condition that the corresponding functions \(\phi _\kappa \) have to be contractive. It is also a multimodal problem, since there can be several global or local minima of the similarity function. The problem is so difficult that only partial solutions have been reported so far, but the general problem still remains unsolved to a large extent. In this paper we address this problem by using a hybrid approach based on the cuckoo search algorithm described in next paragraphs.

3 The Cuckoo Search Algorithms

3.1 Original Cuckoo Search (CS)

The Cuckoo search (CS) is a powerful metaheuristic algorithm originally proposed by Yang and Deb in 2009 [18]. Since then, it has been successfully applied to difficult optimization problems [5, 14, 17, 19]. The algorithm is inspired by the obligate interspecific brood-parasitism of some cuckoo species that lay their eggs in the nests of host birds of other species to escape from the parental investment in raising their offspring and minimize the risk of egg loss to other species, as the cuckoos can distributed their eggs amongst a number of different nests.

This interesting and surprising breeding behavioral pattern is the metaphor of the cuckoo search metaheuristic approach for solving optimization problems. In the cuckoo search algorithm, the eggs in the nest are interpreted as a pool of candidate solutions of an optimization problem while the cuckoo egg represents a new coming solution. The ultimate goal of the method is to use these new (and potentially better) solutions associated with the parasitic cuckoo eggs to replace the current solution associated with the eggs in the nest. This replacement, carried out iteratively, will eventually lead to a very good solution of the problem.

In addition to this representation scheme, the CS algorithm is also based on three idealized rules [18, 19]:

  1. 1.

    Each cuckoo lays one egg at a time, and dumps it in a randomly chosen nest;

  2. 2.

    The best nests with high quality of eggs (solutions) will be carried over to the next generations;

  3. 3.

    The number of available host nests is fixed, and a host can discover an alien egg with a probability \(p_a \in [0,1]\). In this case, the host bird can either throw the egg away or abandon the nest so as to build a completely new nest in a new location. For simplicity, this assumption can be approximated by a fraction \(p_a\) of the n nests being replaced by new nests (with new random solutions at new locations).

Table 1. Cuckoo search algorithm via Lévy flights as originally proposed in [18, 19].

The basic steps of the CS algorithm are summarized in the pseudocode shown in Table 1. Basically, the CS algorithm starts with an initial population of n host nests and it is performed iteratively. The initial values of the jth component of the ith nest are determined by the expression \(x_i^j(0)=rand.(up_i^j-low_i^j)+low_i^j\), where \(up_i^j\) and \(low_i^j\) represent the upper and lower bounds of that jth component, respectively, and rand represents a standard uniform random number on the interval (0, 1). With this choice, the initial values are within the search space domain. These boundary conditions are also controlled in each iteration step.

For each iteration t, a cuckoo egg i is selected randomly and new solutions \(\mathbf{x}_i^{t+1}\) are generated by using the Lévy flight. According to the original creators of the method, the strategy of using Lévy flights is preferred over other simple random walks because it leads to better overall performance of the CS. The general equation for the Lévy flight is given by:

$$\begin{aligned} \mathbf{x}_i^{t+1}=\mathbf{x}_i^t+\alpha \oplus levy(\lambda ) \end{aligned}$$
(4)

where t indicates the number of the current generation, and \(\alpha >0\) indicates the step size, which should be related to the scale of the particular problem under study. The symbol \(\oplus \) is used in Eq. (4) to indicate the entry-wise multiplication. Note that Eq. (4) is essentially a Markov chain, since next location at generation \(t+1\) only depends on the current location at generation t and a transition probability, given by the first and second terms of Eq. (4), respectively. This transition probability is modulated by the Lévy distribution as:

$$\begin{aligned} levy(\lambda ) \sim t^{-\lambda }, \qquad \qquad (1<\lambda \le 3) \end{aligned}$$
(5)

which has an infinite variance with an infinite mean. From the computational standpoint, the generation of random numbers with Lévy flights is comprised of two steps: firstly, a random direction according to a uniform distribution is chosen; then, the generation of steps following the chosen Lévy distribution is carried out. The authors suggested to use the Mantegna’s algorithm for symmetric distributions (see [19] for details), which computes the factor:

$$\begin{aligned} \hat{\phi }=\left( {{\varGamma (1+\hat{\beta }).sin\left( {{\pi .\hat{\beta }} \over {2}}\right) } \over {\varGamma \left( \left( {{1+\hat{\beta }} \over {2}}\right) .\hat{\beta }.2^{{\hat{\beta }-1} \over {2}}\right) }} \right) ^{{1} \over {\hat{\beta }}} \end{aligned}$$
(6)

where \(\varGamma \) denotes the Gamma function and \({\displaystyle \hat{\beta }={{3} \over {2}}}\) in the original implementation by Yang and Deb [19]. This factor is used in Mantegna’s algorithm to compute the step length \(\varsigma \) as: \(\varsigma ={{u} \over {|v|^{{1} \over {\hat{\beta }}}}}\), where u and v follow the normal distribution of zero mean and deviation \(\sigma _u^2\) and \(\sigma _v^2\), respectively, where \(\sigma _u\) obeys the Lévy distribution given by Eq. (6) and \(\sigma _v=1\). Then, the stepsize \(\zeta \) is computed as \(\zeta =0.01\, \varsigma \, (\mathbf{x}-\mathbf{x}_{best})\). Finally, \(\mathbf{x}\) is modified as: \(\mathbf{x} \leftarrow \mathbf{x}+\zeta .\mathbf {\Delta }\) where \(\mathbf {\Delta }\) is a random vector of the dimension of the solution x and that follows the normal distribution N(0, 1). The CS method then evaluates the fitness of the new solution and compares it with the current one. In case the new solution brings better fitness, it replaces the current one. On the other hand, a fraction of the worse nests (according to the fitness) are abandoned and replaced by new solutions so as to increase the exploration of the search space looking for more promising solutions. The rate of replacement is given by the probability \(p_a\), a parameter of the model that has to be tuned for better performance. Moreover, for each iteration step, all current solutions are ranked according to their fitness and the best solution reached so far is stored as the vector \(\mathbf{x}_{best}\).

3.2 Improved Cuckoo Search (ICS)

The improved cuckoo search (ICS) method was proposed in [16] to enhance the performance of the original CS. It is based on the idea of allowing its parameters \(p_a\) and \(\alpha \) to change over the generations, as opposed to their fixed values in the original CS. In ICS the parameter \(p_a\) is modified as:

$$\begin{aligned} p_a^t=p_{a_M} - {{p_{a_M}-p_{a_m}} \over {\varLambda }}\, t \end{aligned}$$
(7)

where the subscripts M and m are used to indicate the maximum and minimum values of the parameter respectively, and \(\varLambda \) indicates the total number of iterations. According to Eq. (7), the parameter \(p_a\) is now decreased linearly with the number of iterations from a maximum value \(p_{a_M}\) until a minimum one, \(p_{a_m}\). At early iterations, its value is high to enforce the diversity of solutions in the algorithm. This diversity is decreasing over the time so as to intensify the search using the best candidates of the population in final iterations for a better fine-tuning of the solutions. The parameter \(\alpha \), also assumed constant in the CS, is primarily used to promote exploration of the search space. Therefore, it makes sense to modify it dynamically starting from a high value, \(\alpha _M\), to perform a extensive exploration and gradually reducing it until a low value, \(\alpha _m\), to promote exploitation and eventually homing into the optimum, in a rather similar way to the inertia weight in PSO. Consequently, it is modified as:

$$\begin{aligned} \alpha ^t=\alpha _M\, Exp\left( {{Ln\left( {\displaystyle {{\alpha _m} \over {\alpha _M}}}\right) } \over {\varLambda }} t\right) \end{aligned}$$
(8)

4 Proposed Approach

4.1 Hybrid ICS with Luus-Jakoola Heuristics

To address the IFS inverse problem described in Sect. 2.2, we propose a new hybrid scheme for proper balance between exploration and exploitation. Firstly, we consider the improved cuckoo search method for global optimization described in Sect. 3.2. This modified scheme is improved by its hybridization with a local search procedure. In particular, we apply the Luus-Jaakola (LJ) method, a gradient-free heuristics firstly proposed in [15] to solve nonlinear programming problems. LJ starts with an initialization step, where random uniform values are chosen within the search space by computing the upper and lower bounds for each dimension. Then, a random uniform value in-between is sampled for each component. This value is added to the current position of the potential solution to generate a new candidate solution, which replaces the current one only when the fitness improves; otherwise, the sampling space is multiplicatively decreased by a factor (usually of value 95%, but other values can also be used). In practice, we found that it is better to consider a self-adaptive size for this factor, with the effect of speeding up the convergence to the steady state. This process is repeated iteratively. With each iteration, the neighborhood of the point decreases, so the procedure eventually collapses to a point.

4.2 Application to the IFS Inverse Problem

Given a 2D self-similar binary fractal image comprised of \(\eta \) functions \(\phi _\kappa \), we apply our hybrid method to solve the IFS inverse problem. We consider an initial population of \(\chi \) individuals \(\{\mathcal {C}_i\}_{i=1,\dots , \chi }\), where each individual \(\mathcal {C}_i=\{\mathcal {C}^{\kappa }_i\}_{\kappa }\) is a collection of \(\eta \) real-valued vectors \(\mathcal {C}_\kappa ^i\) of the free variables of Eq. (1), as:

$$\begin{aligned} \mathcal {C}_i^\kappa =(\theta _{1,1}^{\kappa ,i},\theta _{1,2}^{\kappa ,i},\theta _{2,1}^{\kappa ,i},\theta _{2,2}^{\kappa ,i} | \sigma _1^{\kappa ,i},\sigma _2^{\kappa ,i} | \omega _\kappa ^i) \end{aligned}$$
(9)

These individuals are initialized with uniform random values in \([-1,1]\) for the variables in \(\mathbf {\Theta }_\kappa \) and \(\mathbf {\Sigma }_\kappa \), and in [0, 1] for the \(\omega _\kappa ^i\), such that \(\sum _{\kappa =1}^{\eta } \omega _\kappa ^i =1\). After this initialization step, we compute the contractive factors \(\mu _\kappa \) and reinitialize all functions \(\phi _\kappa \) with \(\mu _\kappa \ge 1\) to ensure that only contractive functions are included in the initial population. Before applying our method, we also need to define a suitable fitness function. In this paper we use the Hamming distance: the fractal images are stored as bitmap images of 0s and 1s for a given resolution defined by a mesh size parameter, \(m_s\). Then, we divide the number of different values between the original and the reconstructed matrices by the total number of boxes in the image. This yields the normalized similarity error rate index between both images, denoted by , the fitness function used in this work.

Fig. 1.
figure 1

Example of the rotated triangle fractal: (left) original (top) and reconstructed image (bottom); (right) their different contractive functions with different colors. (Color figure online)

Fig. 2.
figure 2

Example of the Crystal fractal: (left) original (top) and reconstructed image (bottom); (right) their different contractive functions with different colors. (Color figure online)

Fig. 3.
figure 3

Example of the AIAI-2018 fractal (from top to bottom): original image in red, original image with different colors for each contractive function, reconstructed image in blue, and reconstructed image with different colors for each contractive function. (Color figure online)

4.3 Parameter Tuning

It is well-known that the parameter tuning of metaheuristic methods is troublesome and problem-dependent. The cuckoo search is specially advantageous in this regard, as it depends on only two parameters: the population size, \(\chi \), set to \(\chi =100\), and the probability \(p_a\), calculated taking: \(p_{a_M} = 0.5\) and \(p_{a_m} = 0.005\) in Eq. (7). Moreover, the method is executed for \(\varLambda \) iterations. In our simulations, we found that \(\varLambda =1500\) is enough to reach convergence in mp all cases. Our hybrid method also requires to define suitable values for \(\alpha _M\) and \(\alpha _m\) in Eq. (8). Similar to [16], in this work they are set to 0.5 and 0.01, respectively. Finally, our method requires to define the mesh size, \(\nu \), set to \(\nu =80\) in this work.

5 Experimental Results

Our method has been applied to several examples of fractals. Only three of them are included here because of limitations of space: rotated triangle, Crystal, and the AIAI-2018 fractal (especially created for this paper). They are shown in Figs. 1, 2 and 3, respectively. The input fractal images are displayed twice in each figure, one in red and another with one color for each individual contractive function. As the reader can see, the three fractals are comprised of 3, 4, and 26 functions, respectively. The application of our method to these input images returns the IFS minimizing the index, which are then used to render the reconstructed fractal images, shown in blue and with different colors as above.

Table 2. Numerical results of the best and mean values of the index for the examples in Figs. 1, 2 and 3 with the proposed method.

As the reader can see, although the matching is not optimal, our method captures the underlying structure of the fractal images with good visual quality. This is a remarkable result because our initial population is totally random, meaning that their corresponding images at early generations are all totally different from the given image. Our method is able to obtain a final image that replicates well the input image and is also a self-similar fractal for all instances in our benchmark. Our graphical results indicate that our method performs very well, as it provides visually satisfactory solutions for the IFS inverse problem.

This good visual appearance is confirmed by our numerical results, reported in Table 2. For each fractal example (in rows), the table shows (in columns): number of contractive functions \(\eta \), number of free variables of the optimization problem, and best and mean value of the index for 20 independent executions of the method. As the reader can see, the similarity index for the best execution yields errors ranging from \(20\%\) to \(30\%\), depending on the example. Although the reconstructed images are perfectly recognizable in all cases, this similarity error increases with the complexity of the model, with the third example exhibiting the larger value. This result is very reasonable because this example requires to solve an optimization problem with many more variables than the other two examples. In addition, the numerical values of the similarity index used in this work indicate that the results are not optimal yet, suggesting that the method might arguably be further improved.

All computations in this paper have been performed on a 2.6 GHz. Intel Core i7 processor with 16 GB of RAM. The source code has been implemented by the authors in the native programming language of the popular scientific program Matlab version 2015a and using the numerical libraries for fractals in [4, 6,7,8]. Regarding the CPU times, they depend on the complexity of the model and its number of contractive functions. In general, we noticed that the method is slow and time-consuming. For illustration, each single execution takes about 25–45 min for the first two examples, and more than 1 h for the third one.

6 Conclusions and Future Work

In this paper we introduced a new hybrid method to solve the following optimization problem: given any binary self-similar fractal image, the goal is to determine an IFS whose attractor is a good approximation of this input image. This problem, called the IFS inverse problem, is known to be a very difficult multivariate nonlinear continuous optimization problem. In this new hybrid method, a modification of the original cuckoo search method for global optimization called improved cuckoo search (ICS) is coupled with the Luus-Jakoola heuristics for local search. This hybrid methodology is applied to three fractal examples: rotated triangle, crystal, and the AIAI-2018 fractal. The method replicates the input images very well, yielding visually satisfactory results in all cases.

The numerical results show however that our final solutions are not optimal yet, so the method might be improved in several ways. On one hand, we want to modify our fitness function to obtain a better measure of the quality of the reconstructed fractal. On the other hand, we would like to obtain automatically the optimal value of the number of contractive functions for the IFS. We also wish to extend our results to the cases of images that are neither binary nor self-similar. Reducing our CPU times is also one of our future goals in the field.