Moving average algorithms for diamond, hexagon, and general polygonal shaped window operations Changming Sun * CSIRO Mathematical and Information Sciences, Locked Bag 17, North Ryde, NSW 1670, Australia Received 29 November 2004; received in revised form 9 June 2005 Available online 26 October 2005 Communicated by Prof. L. Younes Abstract This paper presents fast moving window algorithms for calculating local statistics in a diamond, hexagon, and general polygonal shaped windows of an image which is important for real-time applications. The algorithms for a diamond shaped window requires only seven or eight additions and subtractions per pixel. A fast sparse algorithm only needs four additions and subtractions for a sparse dia- mond shaped window. A number of other shapes of diamond windows such as skewed or parallelogram shaped diamond, long diamond, and lozenged diamond shaped, are also investigated. Similar algorithms are also developed for hexagon shaped windows. The compu- tation for a hexagon window only needs eight additions and subtractions for each pixel. Fast algorithms for general polygonal shaped windows are also developed. The computation cost of all these algorithms is independent of the window size. A variety of synthetic and real images have been tested. Ó 2005 Elsevier B.V. All rights reserved. Keywords: Moving average algorithm; Diamond shaped windows; Hexagon shaped windows; Polygonal shaped windows; Local statistics 1. Introduction In most of the image analysis and computer vision appli- cations, the local processing windows are usually square or rectangular shaped. The edges of these windows are aligned with the image rows and columns. Because of the use of such simple shapes, efficient processing of images can be achieved. McDonnell (1981) described a box-filtering pro- cedure for local mean calculation where the window is rect- angular shaped. The main advantage of box-filtering is its speed, which approaches four operations for each output pixel and is independent of the box size. The filtering oper- ation is also separable: two-dimensional filtering can be implemented as two 1D filtering. Other shapes of windows are also used. A circular shaped window gives good isotropic property, but its com- putational cost is linearly proportional to the radius of the circular window. Glasbey and Jones (1997) presented fast algorithms for moving average and related filters in regular octagonal windows as approximations to circular windows. The algorithm requires twelve additions and subtractions per pixel irrespective of the window size. Ferrari and Sklan- sky (1984) proposed a two step method for obtaining the mean of an arbitrary shaped window. The number of oper- ations is equal to the total number of concave and convex vertices of the window boundary. Because of the sampling effect, the boundaries of diamond and hexagon windows have many vertices, and the number of vertices also depends on the size of the window. Therefore Ferrari and SklanskyÕs method will not be very efficient for diamond and hexagon shaped windows. Verbeek et al. (1988) pre- sented min or max filters for low-level image processing. They gave six shapes for the min or max filter, including a full square, a full diamond, a sampled diamond, a dis- crete approximation of a full circle, the rim and the center, 0167-8655/$ - see front matter Ó 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.patrec.2005.09.020 * Tel.: +61 2 9325 3207; fax: +61 2 9325 3200. E-mail address: changming.sun@csiro.au www.elsevier.com/locate/patrec Pattern Recognition Letters 27 (2006) 556–566