Algorithm series (12) Polygon Region filling algorithm--recursive seed filling algorithm

Source: Internet
Author: User

The planar region filling algorithm is an important algorithm in the field of computer graphics, where the region fill gives the boundary of a region (or it can be without boundary, but gives the specified color), and requires that all pixel elements within the boundary range be modified to the specified color (or pattern fill). The most commonly used in area filling is the polygon fill, in this paper we discuss several polygon region filling algorithms.

One, seed filling algorithm (seed Filling)

If the area to be populated is given in the form of image metadata, you typically use the seed fill algorithm (seed Filling) for area padding. Seed filling algorithm needs to give the image data region, as well as a point in the region, this algorithm is suitable for human-computer interaction of image filling operation, not suitable for automatic processing and judge fill color. According to the definition of image region boundary and color modification method of the point, seed filling can be divided into several kinds, such as injection filling algorithm (Flood fill algorithm), Boundary filling algorithm (boundary fill algorithm) and to reduce The improved scanning line seed filling algorithm and so on by recursion and the number of compaction stacks.

The core of all seed filling algorithms is a recursive algorithm that starts at a specified seed point, searches in all directions, and processes each pixel, until it encounters a boundary, and a variety of seed-filling algorithms differ only in the way colors and boundaries are processed. Before we begin to introduce the seed filling algorithm, we first introduce two concepts, namely "4-Unicom algorithm" and "8-unicom algorithm". Since it is a search that involves the direction of the search problem, from any point in the region, if only through the upper, lower, left and right four directions to search for any pixel in the region, then the area filled with this method is called four-connected domain, this method is called "4-unicom algorithm." If you start at any point in the area, by reaching any pixel in the region through all eight directions on top, bottom, left, right, left, bottom, right, and lower right, this method of filling is called the eight-connected domain, which is called the "8-unicom algorithm". As shown in Figure 1 (a), assume that the center's Blue point is the current processing point, if the "4-unicom algorithm", then only the processing of the four points around the blue logo, if the "8-Unicom algorithm" In addition to processing the top, bottom, left, right four blue identified points, but also to deal with four red logo points. The fill effects of the two search algorithms, as shown in Figure 1 (b) and Figure 1 (c), if all are filled from a yellow dot, the "4-Unicom algorithm", shown in Figure 1 (b), searches only for the lower-left corner of the area, while the "8-Unicom algorithm", as shown in Figure 1 (c), fills the lower-left and upper-right corners.

Figure (1) "4-Unicom" and "8-unicom" fill effect

And not just because of the fill effect of Figure 1 that "8-unicom algorithm" must be better than "4-unicom algorithm", should be based on the application of the environment and the actual needs of the choice of Unicom search method, in many cases, only "4-unicom algorithm" to get the correct results.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.