Krita: Green coordinates or how to make a kangaroo from a dragon

    The other day, 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 distortion into the image. We’ll talk about him today ...

    Green coordinates

    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, which contained the object of interest. By moving the vertices of the polyhedron, the user could deform the selected object, getting the required bend and shape. In our case, we are working not with three-dimensional models, but with flat images, so the task is greatly simplified: the cell becomes an ordinary polygon, and the deformable object becomes a set of pixels inside it. By manipulating the vertices of this polygon, you can obtain the required image deformation.

    There are many ways to specify such a cell, but most of them come down to expressing the coordinates of each pixel inside the cell through the weighted sum of the coordinates of the vertices of that same cell. The resulting weights are subsequently used to calculate the new position of the pixels after the user moves the cell nodes. This method is simple and clear, but it has one significant drawback: when using it, the shape of the object suffers greatly due to the presence of shear deformations (the transformation does not have the property of conformity).

    To get around this shortcoming, developers from the University of Tel Aviv came up withanother way. In order to get rid of shear deformations and preserve the shape of the object, they proposed using not only the coordinates of the vertices of the cell to calculate the coordinates of the pixels, but also the orientation of the normals of its edges. The resulting coordinates are called the Green coordinates in honor of the theory of Green functions used in the derivation.

    The following is a comparison of different cell conversion methods: a) the original image; b) conversion using Green coordinates; c) the classical method of harmonic coordinates. Source: [1]

    The method using Green coordinates has many nice properties:
    • it allows you to get explicit expressions for the new pixel coordinates, i.e. we don’t need to solve equations or use other iterative methods
    • like other "cellular" algorithms, it works in two stages, separated in time: at the first stage, Green coordinates are calculated for each pixel of the image taking into account the initial configuration of the cell, and the second coordinates are simply multiplied by user-modified values ​​of the coordinates of the vertices and edges normals of a new cell. Thus, the first stage, the most resource-intensive, needs to be calculated only once, at the beginning of work, and all subsequent modifications will be recalculated by a fast algorithm
    • unlike all other algorithms, Green coordinates have the property of conformity , i.e. the display of any point in the image can be represented in the form of displacement and rotation, while in the resulting display there will be no shear deformations (shear). This means that any infinitesimal circle will be transformed into a circle, and not into an ellipse, as it would with conventional methods

    Crete implementation and challenges

    When implementing the algorithm in Crete, developers are faced with some interesting features of the algorithm. As already mentioned above, according to the authors ’initial idea, the transformation was divided into two stages, the first of which, the slow, should have been counted 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 real-size objects (> 2k pixels on the long side) took several seconds, so as a result, interpolation was added over the original algorithm. The image is divided by a grid in increments of 8 pixels, Green's coordinate values ​​are considered for its nodes, and the remaining pixels are interpolated. As it turned out, for real images, the difference is almost imperceptible.

    Pepper and Carrot by David Revoy

    To feel the full degree of speed of the original algorithm, the reader is invited to open the Gimp editor, create there an image of 640x480 pixels in size and try to apply the Cell Transform tool to it.

    Conclusions and plans for the future

    Cell transformation is already available in the latest builds of Crete 2.9 Beta2. Together with the rewritten Warp Transform tool, it allows you to change the pose and facial expressions of a two-dimensional character without additional creation and binding of the skeleton.

    However, in addition to the basic algorithm, cell transformation has another interesting extension. Now changing only 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, because in order to change, for example, the character’s hand, it will be necessary to bring it into the cell as a whole (see video) To correct this situation, there is a method that allows you to fix the selected edges of the cell and edit parts of the character separately. This will be the topic for the future work of developers!

    The beta version of Krita 2.9 for Windows and Linux can be downloaded on the official website of the project.

    In conclusion, a video on how to create a title illustration:

    Also popular now: