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