Journal of Visual Communication and Image Representation
Efficient method of pixel neighborhood traversal
Highlights
► The pixel neighbor access without boundary checks is organized. ► Images of arbitrary dimensionality can be handled. ► The evaluation shows more than three times speedup.
Introduction
There are several important groups of image processing algorithms, which require the processing of a neighborhood of each image pixel. First, linear filters, including difference filters used in numerical solvers of differential equations, require neighborhood processing. Second, neighborhood processing is involved in many nonlinear filters, such as mathematical morphology operators with defined structural element, rank filters and, particularly, median filters.
Although fast implementations of many filters are already provided, rapid development of image processing technology requires to implement a lot of new algorithms (e.g. [1], [2], [3]), which are not yet included in popular image processing libraries. Therefore, a general, flexible, and easy-to-use solution for neighborhood traversal is of high interest. Here, flexibility means the ability to use a neighborhood traversal module for a wide range of algorithms without rewriting its inner parts. Particularly, it requires the support of different neighborhood types, different boundary conditions, and images with any dimensionality and any pixel type. Easiness means to hide implementation details from the user and to minimize of the amount of code required to setup a neighborhood traversal. This implies faster development and less amount of mistakes.
Additionally, the solution should consume a minimal amount of the system resources. First, since almost all image processing applications have a user interface, it is critical to provide the response with a minimal delay. Second, the amount of additional memory should be independent of the image size, i.e. the creation of additional copies of the processed image should be avoided. For example, it is common nowadays to handle volumes of size about 1024 × 1024 × 2048 in medical image processing applications, and if the algorithm requires image pixels to be floating-point numbers, only a few such volumes can be stored in the memory simultaneously.
When only high-level programming languages are used, branch handling and memory accesses organization are among the most decisive factors influencing the computational efficiency [4], [5], [6]. In this work, we concentrate on reducing the number of branches in the program by avoiding boundary checks in neighborhood processing. The advantages of the proposed neighborhood traversal method are:
- 1.
support of an arbitrary neighborhood type;
- 2.
support of different boundary conditions, including boundary conditions implemented by the user;
- 3.
support of images with an arbitrary dimensionality;
- 4.
independence of the image pixel type;
- 5.
simple interface, which hides all implementation details;
- 6.
high computational efficiency compared with the existing solutions with similar flexibility;
- 7.
the amount of additional memory independent of the image size.
Section snippets
Previous work
Among image processing libraries, which are based on generic programming, Vigra [7], [8], ITK [9], Milena [10] and ImLib3D [11] have the ability for pixel neighborhood traversal.
In the Vigra library (v1.7.1), neighborhood traversal is implemented in the NeighborhoodCirculator class. This class can be used only for 2D images and supports only 4- and 8-neighborhood. The object of this class has to be constructed before processing neighborhood of each image pixel, which results in a performance
Efficient neighborhood traversal
When accessing a neighbor of a pixel, its offset from the beginning of the image buffer should be computed. This offset can be represented as the sum of the offset of the pixel in the image buffer and the offset of the neighbor from the pixel. The main idea is to precompute the second summand before the image traversal in such a way that the neighbor can be accessed without boundary checks. To realize this idea, our algorithm is designed with the following concepts:
- 1.
Functions, which map pixels
Implementation
Now we describe the implementation of our method in C++ [16]. This implementation is required to be efficient, flexible and easy-to-use. If an image traversal iterator is used, as written in Algorithm1, the implementation is not so easy as required, since the user should enumerate subsets {Di} each time by himself. Therefore we are using a special iterator type, let us call it NeighborhoodIterator. Similar idea is used in the ITK library. In order to support images of any dimensionality, the
Evaluation
The evaluation was done on a PC with CPU Intel i7 920 (2.67 GHz) and 3 GB RAM using the MinGW 4.4.0 compiler with -O3 compilation flag.
In the 2D case, we used the 500 grayscale 8-bit images taken from the Berkeley Segmentation Dataset (BSDS500) [18]. The images were converted from RGB to grayscale using the standard formula [19]: gray = 0.3R + 0.59G + 0.11B. In the 3D case, we used 10 grayscale 8-bit cubic volumes filled with the Gaussian noise (mean = 128, standard deviation = 32). In both cases, the
Discussion
As one can see from representations (9), (10), different functions Pk and Vk are used for handling out-of-bounds accesses for each dimension k, which allows utilization of different boundary conditions for different dimensions. This is useful when solving some types of differential equations and processing 4D images, where different behaviors should be implemented for the space dimensions and for the time dimension.
Regarding the implementation of image filters on a GPU, one usually does not
Conclusion
In this paper, we present a method of pixel neighborhood traversal, which is independent of the neighborhood type and can handle images of any dimensionality and any pixel type. The amount of additional memory required by the proposed algorithm is independent of the image size. Compared with libraries having similar flexibility and memory requirements, the proposed approach is more than three times faster.
An easy-to-use implementation of the algorithm in C++ is discussed as well. It hides all
References (20)
- A. Buades, B. Coll, J. Morel, On image denoising methods, in: Technical Note, CMLA (Centre de Mathematiques et de Leurs...
- et al.
Fast gradient-based algorithms for constrained total variation image denoising and deblurring problems
IEEE Transactions on Image Processing
(2009) - et al.
Distance regularized level set evolution and its application to image segmentation
IEEE Transactions on Image Processing
(2010) The basics of performance-monitoring hardware
IEEE Micro
(2002)- Intel, Intel 64 and ia-32 Architectures Optimization Reference Manual,...
Basic performance measurements for AMD AthlonTM 64 and AMD OpteronTM processors
AMD Developer Central
(2006)Reusable software in computer vision
(1999)STL-style generic programming with images
C++ Report Magazine
(2000)- et al.
The ITK Software Guide
(2005) - et al.
Milena: write generic morphological algorithms once, run on many kinds of images
Mathematical Morphology and Its Application to Signal and Image Processing
(2009)
Cited by (1)
Human body tracking algorithm of ant colony detection with pigment information under the weak light environment
2013, Guangdian Gongcheng/Opto-Electronic Engineering