Next, let's talk about some simple algorithms in the previous article.
In this article, let's talk about the fragment algorithm. Let's talk about it first:
This is a destructive filter. For beauty, it is because 90% of the people who engage in images are men and half of the men.
The principles of the fragment filter can be found on the network to create four copies of the image at the same offset to produce a similar effect.
With the above sentence, we can start it.
Analysis: Through the comparison of the above images, especially the eye area, we can see that the processed image should be like a single eye with four eyes. Therefore, the network is reliable.
So where is the center of the offset, and what is the number of Offsets? Four offsets, respectively, are offset to those directions. These problems are also very simple. You can verify them by using the PS:
The procedure is as follows: open an image, fill in a 2*2 pixel red place where the color of the image is monotonous (such as the beauty's arm), and copy the layer, perform fragment filter on the copied layer, and adjust the transparency of the layer to 50%. The partial enlargement result is as follows:
With this effect, you can easily draw a conclusion:
The center of the Offset is centered on each pixel. The four offsets are symmetric in the center, arranged in a circular direction of 45 degrees oblique, and 45 degrees horizontal and vertical offsets, respectively. The offset is 4 pixels.
We can guess how to overlay the data by taking the average value of the accumulated value after four offsets.
To solve this problem, I wrote the following algorithms:
Private void initialize fragment_click (Object sender, eventargs e) {int X, Y, Z, XX, YY; int width, height, stride; int speed, index; int sumr, sumg, sumb; bitmap BMP = (Bitmap) pic. image; If (BMP. pixelformat! = Pixelformat. format24bpprgb) throw new exception ("unsupported image format. "); width = BMP. width; Height = BMP. height; stride = (INT) (BMP. width * 3 + 3) & 0 xfffffffc); byte [] imagedata = new byte [stride * Height]; // used to save image data (all before and after processing) byte [] imagedatac = new byte [stride * Height]; // int [] offsetx = new int [] {4,-4,-4, 4}; // offset of each vertex int [] offsety = new int [] {-4,-4, 4, 4}; fixed (byte * P = & Amp; imagedata [0], CP = & amp; imagedatac [0]) {byte * datap = P, datacp = CP; bitmapdata bmp data = new bitmapdata (); BMP data. scan0 = (intptr) datap; // the address of the first element in the byte array in the memory. stride = stride; BMP. lockbits (New rectangle (0, 0, BMP. width, BMP. height), imagelockmode. readwrite | imagelockmode. userinputbuffer, pixelformat. format24bpprgb, BMP data); stopwatch Sw = new stopwatch (); // obtain the SW for computing only. start (); lead E M. buffer. blockcopy (imagedata, 0, imagedatac, 0, stride * Height); // fill in the cloned data for (y = 0; y
In the algorithm, offsetx and offsety represent the offset of the pixel at the sampling point. Likewise, because the filter involves a field operation, pixel backup is required before processing, but backup data is not extended here. Therefore, in the internal code, you need to verify the coordinates of the sampling points to see if they exceed the range. if they exceed the range, there are usually three processing methods within the range of the image filter algorithm:
(1) If the value is exceeded, it is regarded as the closest boundary value, that is, the duplicate edge pixel. This part of the code is the IF... else if part posted above.
(2) fold back, which can be described using the following code:
while (XX >= Width) XX = XX - Width;while (XX < 0) XX = XX + Width;while (YY >= Height) YY = YY - Height;while (YY < 0) YY = YY + Height;
(3) Calculate only pixels within the image range:
If (XX> = 0 & XX <width & YY> = 0 & YY
Of course, to do this, you must use a variable to record how many times the conditional calculation has been performed.
If you are interested, you can change the code and try again.
In the above Code segment, datap [speed] = (byte) (sumb + 2)> 2); the reason for adding 2 to sumb is to rounding the result, this is more reasonable.
After testing, the above Code and PS processing results are 100% consistent. This shows that our guesses are completely correct.
The algorithm can also be further expanded: the thought is far away. Why is it not four duplicates? It must be a 45-degree angle. It must be a four-pixel horizontal and vertical offset. I will research and develop it for interested readers.
In the figure, the angle is 32 degrees, the radius is 10, and the number of fragments is 7, which can produce a similar effect (which can be verified by my imageshop ):
Complete: http://files.cnblogs.com/Imageshop/Fragement.rar
* *********** Basically, I do not provide source code, however, I will try to use text to clearly describe the corresponding algorithm or provide reference documents **************
* ************ It is your own things because of your own efforts and practical effects, people must rely on their own *****************
* ************ Author: laviewpbt time: 2013.7.5 contact QQ: 33184777 reprinted please keep the information of this bank **********