Skip to main content
When matching a FlexiLayout with an image, FlexiLayout Studio attempts to find the objects on the image that correspond to the elements in the FlexiLayout. It then estimates how well a particular object matches its element. An estimate is a number from 0 to 1. A quality of 1 means that the detected object is a 100% match. If the quality is not 0, matching the FlexiLayout creates regions for the blocks.

How the tree of hypotheses is built

FlexiLayout Studio looks for elements consecutively, in the order in which they follow in the FlexiLayout tree, from top to bottom. For each element, it may find several matching objects (or sets of objects) in the search area. FlexiLayout Studio formulates a hypothesis for each object in the search area and estimates its quality: the better the match, the higher the quality of the hypothesis. The location of the detected object determines the location of the objects lower in the FlexiLayout tree. FlexiLayout Studio uses each of the hypotheses of the current element as starting points to look for the subsequent elements lower in the tree. Thus, the hypotheses for elements branch out, which results in a tree of hypotheses that contains many more branches than the tree of elements. If several elements are joined into one Group element, the entire group is considered as one element for which several hypotheses are formulated. The quality of a Group element is calculated by multiplying the qualities of the hypotheses for the constituent elements. The entire FlexiLayout may be considered as a Group element whose quality can be calculated by multiplying the qualities of the hypotheses for all of its elements.

The best complete branch of hypotheses

When matching a FlexiLayout with images, FlexiLayout Studio needs to find the best complete branch of hypotheses. A branch is complete if it includes all of the elements, from the top element to the bottom element. A generic solution would be to consider all the possible combinations of hypotheses for all the elements, building a complete set of possible complete branches and selecting the branch with the highest quality. This is not practical, since it would take too much time. Moreover, if the number of elements is fairly large and their search areas are only approximate, a combinatorial explosion may occur resulting in an uncontrollable growth of the number of hypotheses. FlexiLayout Studio uses several methods of optimizing the search to keep the number of hypotheses to a minimum.

Search optimization

Each element in the FlexiLayout has an important parameter called Number of surviving hypotheses. Use this parameter to limit the number of hypotheses that FlexiLayout Studio may use when looking for the subsequent element. By default, this parameter is set to 5 for simple elements, and to 1 for Group elements. That means that if FlexiLayout Studio finds 15 hypotheses for a given element, it selects the best five, leaving the other 10 chains of hypotheses incomplete. Group elements are typically detected more reliably than simple elements. Therefore, the best hypothesis for a Group element usually turns out to be the correct one. In most cases, FlexiLayout Studio has several incomplete chains of hypotheses and, consequently, several possible search directions. It looks for the best hypothesis using the classic “wide search” algorithm. This algorithm means that FlexiLayout Studio always tries to complete the chain that has the best quality at the moment, irrespective of its length. Suppose a FlexiLayout describes 30 elements for which two chains of hypotheses have been created: a chain of 29 elements that has an estimated quality of 0.89 and a chain of 2 elements that has an estimated quality of 0.92. FlexiLayout Studio attempts to complete the smaller chain, which is better in terms of quality, until the qualities of all its extensions become worse than the quality of the first chain. In the case of a Group element, FlexiLayout Studio uses quality optimization. When it finds an ideal complete chain of hypotheses for a given Group element (that is, the quality of this chain is 1), it ignores all the other variants. The total number of hypotheses for each element is limited to 10,000.