Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说
box filtering,希望能够帮助你!!!。
转自:http://tech-algorithm.com/articles/boxfiltering/
Box filtering is basically an average-of-surrounding-pixel kind of image filtering. It is actually a convolution filter which is a commonly used mathematical operation for image filtering. A convolution filters provide a method of multiplying two arrays to produce a third one. In box filtering, image sample and the filter kernel are multiplied to get thefiltering result. The filter kernel is like a description of how the filtering is going to happen, it actually defines the type of filtering. The power of box filtering is one can write a general image filter that can do sharpen, emboss, edge-detect, smooth, motion-blur, etcetera. Provided approriate filter kernel is used.
Now that I probably had wet your appetite let us see further the coolness of box filtering and its filter kernel. A filter kernel defines filtering type, but what exactly is it? Think of it as a fixed size small box or window larger than a pixel. Imagine that it slides over the sample image through all positions. While doing so, it constantly calculates the average of what it sees through its window.
The minimum standard size of a filter kernel is 3x3, as shown in above diagram. Due to the rule that a filter kernel must fit within the boundary of sampling image, no filtering will be applied on all four sides of the image in question. With special treatment, it can be done, but what is more important than making the basic work first? Enough talk, lets get to the implementation asap!
Java code explanation
The parameter pixels is an array containing a total of width*height pixel information. The parameter kernel is an array with a fixed length of nine. This is because the implementation assumes a window of size 3x3. The function also assume each pixel is in the form ARGB (alpha, red, green, blue), where blue is the least significant byte. Alpha is the transparency information and should just be left untouched. The array indices is a simple optimization table used to find neighboring pixels. The denominator is the sum of parameter kernel, it will be the denominator when calculating average.
Check images below to see different kind of kernels gives varying results. Sample image is from MMORPG game Lineage II.
今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。
上一篇
已是最后文章
下一篇
已是最新文章