Krita: Green coordinates or how to make a kangaroo from a dragon
A few days ago, the second beta version of Crete 2.9 was released. With this article I would like to start a story about the new functionality that awaits users in the upcoming release.
One of the most interesting features of this release is cell transformation. It allows you to change the shape of objects without introducing distortions in the image. About him and will be discussed today ...
')
Coordinates of Green
Initially, interest in cell transformation tools arose as a means of transforming three-dimensional objects. Usually such a “cell” was a polyhedron with a small number of polygons, in which the object of interest consisted. By moving the vertices of the polyhedron, the user could deform the selected object, obtaining the desired bend and shape. In our case, we work not with three-dimensional models, but with flat images, so the task is greatly simplified: the cell becomes a regular polygon, and the deformable object becomes a set of pixels inside it. By manipulating the vertices of this polygon, one can obtain the required image deformations.
There are many ways to specify such a cell, but most of them are reduced to expressing the coordinates of each pixel inside the cell through a weighted sum of the coordinates of the vertices of the cell itself. The resulting weights are then used to calculate the new position of the pixels after the user moves the cell nodes. This method is simple and straightforward, but it has one major drawback: when it is used, the shape of the object suffers because of the presence of shear deformations (the transformation does not have the conformance property).
To get around this flaw, the developers at the University of Tel Aviv came up with another way. In order to get rid of the shear deformations and preserve the shape of the object, they suggested using not only the coordinates of the cell vertices, but also the orientation of the normals of its edges to calculate the coordinates of the pixels. The coordinates obtained are called Green coordinates in honor of the theory of Green functions used in the derivation.
Below is a comparison of different cell transformation methods: a) source image; b) transformation using Green coordinates; c) the classical harmonic coordinate method. Source: [1]
The method of using Green coordinates has many pleasant properties:
It allows to get explicit expressions for new pixel coordinates, i.e. we do not need to solve equations or use other iterative methods
as well as other “cellular” algorithms, it works in two stages separated in time: in the first stage, Green coordinates are calculated for each pixel of the image taking into account the initial configuration of the cell, and in the second, the obtained coordinates are simply multiplied by the user-modified values of the coordinates of the vertices and rib normals of the new cell. Thus, the first stage, the most resource-intensive, is required to be counted only once, at the beginning of the work, and all subsequent modifications will be recalculated by a fast algorithm.
unlike all other algorithms, the Green coordinates have the property of conformity , i.e. the display of any point of the image can be represented in the form of displacement and rotation, while in the resulting display there will be no shear deformations. This means that any infinitely small circle will be transformed into a circle, and not into an ellipse, as would happen with conventional methods.
Implementation in Crete and problems
When implementing the algorithm in Crete, developers are faced with some interesting features of the algorithm. As mentioned above, according to the original idea of the authors, the transformation was divided into two stages, the first of which, the slow, had to be considered only once during the initialization of the tool, and the second, fast, with each modification of the cell by the user. The problem is that the “fast” stage of the algorithm was not so fast. Converting objects of real size (> 2k pixels on the long side) took a few seconds, so as a result, interpolation was added over the original algorithm. The image is broken by a grid in increments of 8 pixels, the values of the Green coordinates are calculated for its nodes, and the remaining pixels are interpolated. As it turned out, for real images, the difference is almost imperceptible.
To feel the full speed of the original algorithm, the reader is invited to open The Gimp editor, create an image 640x480 pixels in size and try to apply the Cell Transformation tool to it.
Conclusions and future plans
Cell transformation is already available in the latest builds of Crete 2.9 Beta2. Together with the Warp Transform tool, it allows you to change the posture and facial expressions of a two-dimensional character without creating and attaching a skeleton.
However, besides the basic algorithm, cell transformation has another interesting extension. Now, changing just one vertex can lead to changes in the entire selected area, even in those parts that are on the other side of the picture. This is not always convenient, since, in order to change, for example, the character's hand, you will need to put it in the entire cell (see video ). To correct this situation, there is a method that allows you to fix the selected edges of the cell and edit the parts of the character separately. This will be the theme for the future work of the developers!
The beta version of Crete 2.9 under Windows and Linux can be downloaded from the official project website.
In conclusion, a video on how the title was created: