The realization of C # processing digital photo mosaic

Source: Internet
Author: User

Many image processing algorithms are actually very simple in principle, the difficulty is often how to write algorithm to achieve it, more difficult is how to optimize the implementation of the algorithm. Although I always think that the efficiency of programmers is more important than the efficiency of the program, but to wait for processing a digital photo of their own, sneak out to buy a cup of tea and then buy a lottery ticket back to find not good, in any case, is intolerable.

Mosaic algorithm is very simple, to put it plainly is to divide a picture into several Val * val pixel of small blocks (may be at the edge of a small block, but do not affect the overall algorithm), each small block color is the same. For convenience, let's use the color of the point in the upper-left corner of the area. Of course, there are other methods, such as taking the color of the center of the block, or the color of the random points in the block to represent and so on.

The following diagram is the result of taking val=2.

Original image Element

ABCDEFG

Hijklmn

Opqrstu

VWXYZ01

2345678

After mosaic processing

Aacceeg

Aacceeg

Ooqqssu

Ooqqssu

2244668

The principle is so simple. The concrete realization depends on each person's thinking habits. My idea is:

When Y (current height) is an integer multiple of Val:

Scans each point x in the current row, if X is also an integral number of Val, records the color value of the current x,y, and if x is not an integer multiple of Val, the last color value that was recorded.

When y is not a multiple integral of Val:

Quite simply, copy the previous line directly.

Simply put the line with the surface, the final realization so that we can not see clearly

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.