Summary of the invention
To the objective of the invention is in order solving the problems of the technologies described above, a kind of generation method of weave effect picture to be provided, in the hope of realizing the generation of weave effect picture.
The technical scheme that the present invention takes is:
A kind of generation method of weave effect picture is characterized in that, comprises the steps:
The first step: based on the source picture, set up a blank Target Photo with described source picture same size;
Second step: the end condition of determining to draw at described Target Photo lines;
The 3rd step: determine one section straight line at described source picture, start position and the final position of recording this straight line, and the colour of definite described straight line;
The 4th step: use identical colour to draw the straight line of weave effect in the same position of described Target Photo.
The 5th step: judge whether end condition is set up, then finish in this way to draw the export target picture; As otherwise returned for the 3rd step;
Further, the end condition in described second step reaches predetermined number of times for the number of times of drawing straight line at described Target Photo.
Further, the end condition in described second step is to draw straight line on the described Target Photo to reach specified density.
Further, the end condition in described second step is to draw the straight line time on the described Target Photo to reach the fixed time.
Further, in described the 3rd step, according to the colour distribution of the straight line of determining, use iterative algorithm to redefine the final position of straight line.
Further, described iterative algorithm comprises the steps:
Whether the colour of judging described straight line changes difference greater than preset threshold value, judge that whether the length of described straight line is greater than pre-set length, if two judged results are all and are, be the length that basic point shortens described straight line with the straight line start position then, the duplicate step of laying equal stress on; If two judgements have one for not, then determine the final position of straight line.
Further, described iterative algorithm comprises the steps:
Judge that whether the graded difference of described straight line is greater than preset threshold value, judge that whether the length of described straight line is greater than pre-set length, if two judged results are all and are, be the length that basic point shortens described straight line with the straight line start position then, the duplicate step of laying equal stress on; If two judgements have one for not, then determine the final position of straight line.
Further, the colour of described straight line is the colour of pixel of the mid point of described straight line.
Further, in described the 3rd step, draw the start position of straight line for the first time for obtaining at random, from for the second time, the starting point of drafting straight line is the terminal point of last straight line.
Further, if described source picture and Target Photo are cromogram, the colour of described straight line is the color-values of described straight line.
Further, if described source picture and Target Photo are gray-scale map, the colour of described straight line is the gray-scale value of described straight line.
The invention has the beneficial effects as follows:
Be instrument with the computing machine, at digital picture, produce the picture of different weave effect automatically and quickly.
Embodiment
Elaborate below in conjunction with the embodiment of accompanying drawing to the generation method of a kind of weave effect picture of the present invention.
Weave effect picture texture is well arranged, and artistic effect is strong, in beautifying and decorating, publicity and art are used very strong application prospect is arranged.
Generation method with weave effect picture comprises the steps:
The first step: based on the source picture, set up a blank Target Photo with described source picture same size.
The source picture is electronic pictures, and for cromogram, Target Photo corresponds to cromogram; For the gray scale picture, Target Photo should be gray-scale map.
Second step: the end condition of determining to draw at described Target Photo lines.
The condition of end condition for determining that Target Photo is completed, end condition can determine that a kind of is when reaching predetermined number of times according to the number of times of drawing straight line on the Target Photo, to be defined as drawing end condition by following several algorithms; Another kind is when drawing straight line on the Target Photo and reach specified density, is defined as drawing end condition; Also having a kind of is to reach the fixed time according to the drafting straight line time on the Target Photo, is defined as drawing end condition.These three kinds of end conditions can be selected according to the source picture size of practical application, the parameters such as color of source picture.
The 3rd step: determine one section straight line at described source picture, start position and the final position of recording this straight line, and the colour of definite described straight line.
When determining the straight line on the picture of source for the first time, can determine start position and the final position of straight line at random.When determining straight line later on, can determine at random also that perhaps the terminal point of above straight line is determined the terminal point of current straight line more at random as the starting point of current straight line at every turn.The mode of Que Dinging is when the straight line of drawing is abundant at random, substantially can make definite straight line cover whole source picture, but the straight line that random fashion is determined, the colour of the pixel on whole straight line may have very big difference, therefore, increase the method that a straight line terminal point recomputates in this step, distribute by the colour of analyzing straight line and use iterative algorithm to redefine the final position of straight line.
A kind of iterative algorithm is, whether the colour of judging described straight line changes difference greater than preset threshold value, judges the length of described straight line whether greater than pre-set length, if two judged results are all is, be the length that basic point shortens described straight line with the straight line start position then, the duplicate step of laying equal stress on; If two judgements have one for not, then determine the final position of straight line.
Another kind of iterative algorithm is, whether judge the graded difference of described straight line greater than preset threshold value, judge the length of described straight line whether greater than pre-set length, if two judged results are all is, be the length that basic point shortens described straight line with the straight line start position then, the duplicate step of laying equal stress on; If two judgements have one for not, then determine the final position of straight line.
After determining the starting point and final position of straight line, determine the colour of this straight line, colour can be chosen the colour of any point pixel on the colour of pixel of straight line mid point or the straight line, and for colour picture, colour is color-values, and for the gray scale picture, colour is gray-scale value.
The 4th step: use identical colour to draw the straight line of weave effect in the same position of described Target Photo.
After having determined the correlation parameter of straight line, use these parameters to draw the straight line of weave effect in the same position of Target Photo.
The 5th step: judge whether draw end condition sets up, then finish in this way to draw the export target picture; As otherwise returned for the 3rd step.
Referring to accompanying drawing 1, with a specific embodiment the present invention is set forth now.Present embodiment is the generative process that a colour picture carries out weave effect, its end condition is the number of times of predetermined drafting straight line, the alternative manner of its terminal point is that the colour by straight line changes difference and calculates, and the colour of its straight line is the colour of the pixel of straight line mid point.
Concrete method is as follows:
The 1st step: initialization is drawn end condition for drawing maximum times N; The blank Target Photo (step S01 among the figure) of initialization.
The 2nd step: the initial starting point (step S02 among the figure) of selecting drafting at random.
The 3rd step: the terminal point (step S03 among the figure) of selecting lines at random.
The 4th step: according to the length (step S04 among the figure) of starting point and the definite braiding of terminal point lines.
The 5th step: according to iteration cut-off condition, calculate and adjust braiding lines length, determine terminal point coordinate (step S05 among the figure).
Referring to accompanying drawing 2, the step of iterative computation is:
The 501st step: set basic parameter, comprise straight line reduction step-length S, step S501 among the threshold value T(figure of the minimum length L of straight line and colour);
The 502nd step: the coordinate of each pixel on the calculated line (step S502 among the figure);
The 503rd step: the color pixel cell on the straight line is converted into gray scale, the half-tone information of each pixel on the calculated line (step S503 among the figure);
The 504th step: whether judge length that whether tonal range surpass threshold value T or straight line greater than minimum length L, if, then entered for the 505th step, if not, then enter the 506th and go on foot (step S504 among the figure);
The 505th the step: with terminal point coordinate along rectilinear direction to starting point coordinate moving step length S; Then repeating step the 502nd step until length that tonal range surpasses threshold value T or straight line less than minimum length L(figure in step S505);
The 506th the step: with current terminal point coordinate as final terminal point coordinate (step S506 among the figure).
The 6th step: the color (or gray scale: for gray scale source picture) (step S06 among the figure) of determining the braiding lines according to the source picture.
Referring to accompanying drawing 3, the definite of color finishes by following step:
The 601st step: the middle point coordinate of calculated line (step S601 among the figure).
The 602nd step: with the color of the mid point color (step S602 among the figure) as the straight line that will draw in the Target Photo.
The 7th step: braiding straight line (step S07 among the figure) is drawn in beginning in Target Photo.
The 8th step: judge and whether draw number of times greater than initial preset times N, if, draw and finish ((step S10 among the figure)), if not, enter next step (step S08 among the figure).
The 9th step: with the starting point of current terminal point as next straight line, repeated for the 3rd step, repeat to draw the braiding straight line until arriving default number of times (step S09 among the figure).
The above only is preferred implementation of the present invention; should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the principle of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.