My task:
Create a program for copying an image (specified as an input) using only primitives (for example, a triangle or something else). The program should use an evolutionary algorithm to create an output image.
My question is:
I need to invent an algorithm for creating populations and test them (how many - in% - they correspond to the input image). I have a thought; You can find it below.
So what do I want from you: advice (if you find that my idea is not so bad) or inspiration (maybe you have a better idea?)
My idea:
Say that I will only use triangles to create the output image.
My first population is P pictures (generated using T randomly generated triangles - called Elements).
I check my fitness function for every photo in the population and select E from them, as the elite and the rest of the population are simply deleted:
To compare 2 pictures we check every pixel in picture A and compare his R,G,B with the same pixel (the same coordinates) in picture B. I use this: SingleDif = sqrt[ (Ar - Br)^2 + (Ag - Bg)^2 + (Ab - Bb)^2] then i sum all differences (from all pixels) - lets call it SumDif and use: PictureDif = (DifMax - SumDif)/DifMax where DifMax = pictureHeight * pictureWidth * 255*3
The best ones are used to create the following population as follows:
picture MakeChild(picture Mother, picture Father) { picture child; for( int i = 0; i < T; ++i ) { j //this is a random number from 0 to 1 - created now if( j < 0.5 ) child.element(i) = Mother.element(i); else child.element(i) = Father.element(i) if( j < some small % ) mutate( child.element(i) ); } return child; }
So it's pretty simple. Only the mutation needs comment: therefore, there is always a slight chance that the element X in the child will differ from X in its parent. To do this, we make random changes in the element of the child (we change its color by a random number or add a random number to its coordinate (x, y) - or its node).
So this is my idea ... I have not tested it, I have not encoded it. Please check out my idea - what do you think of this?