- Open Access
Two-way partitioning of a recursive Gaussian filter in CUDA
© Lee et al.; licensee Springer. 2014
- Received: 15 November 2013
- Accepted: 10 June 2014
- Published: 30 June 2014
Recursive Gaussian filters are more efficient than basic Gaussian filters when its filter window size is large. Since the computation of a point should start after the computation of its neighborhood points, recursive Gaussian filters are line oriented. Thus, the degree of parallelism is restricted by the length of the data image. In order to increase the parallelism of recursive Gaussian filters, we propose a two-way partitioned recursive Gaussian filter. The proposed filter partitions a line into two lines and a point, which is used for Gaussian blur effect across the two lines. This partition increases the parallelism because the filter is applied to the two blocks in parallel. Experimental results show that the process time of the proposed filter is half compared to the time of an one-way parallel recursive Gaussian filter while the peak signal-to-noise ratio is maintained within an acceptable rate of 26 to 33 dB.
- Graphic Processing Unit
- Gaussian Filter
- Global Memory
- Finite Impulse Response Filter
- Boundary Pixel
A Gaussian blur filter, or Gaussian filter, is one of the fundamental and widely used image processing techniques. A typical use of the filter is denoising. It is also used as a preprocessing step for down/up sampling, edge detection[1, 2], or scale space representation. Contrast enhancement techniques such as Retinex[4–6] or unsharp filters are the other uses for Gaussian blur where it approximates the illumination component of an image at a large scale.
According to the definition of Gaussian filter, filtered value of a pixel in a two-dimensional image is computed using nearby pixel values. The range of the pixels to be used is determined by filter window size N × N. It is known that the filtered value of a pixel can be computed by pixels in a horizontal line and a vertical line that pass through the pixel. Let us call the Gaussian filter that computes filtered value of a pixel using the crossing two lines as finite impulse response (FIR) filter. FIR filter has 4N × width × height computation steps if the size of given image is width × height.
Although FIR filter implements Gaussian blur filter in the exact discrete way, the processing time of the filter depends on the filter window size N × N. Recursive Gaussian filters that implement Gaussian filter are developed in order to eliminate effect of the filter window size. A recursive Gaussian filter computes filtered value of a pixel using differential values of its neighborhood pixels. Since the differential values of neighborhood pixels contain all approximated data within the range of the filter window size, the filter window size is not involved in the number of computation steps. Computation step of a recursive Gaussian filter proposed by van Vliet et al. is about 32 × width × height. Thus, recursive Gaussian filters is faster than the FIR filter if a filter window size is greater than 8. Unfortunately, recursive Gaussian filters make dependence between pixels and restrict the degree of parallelism. Pixel p[i][j] must wait until the filtered value of pixel p[i-1][j] is computed in the row-oriented step.
As graphic processing unit (GPU) cores can be used for general purpose computation, many image processing algorithms have been implemented in general purpose GPU (GPGPU). NVIDIA supports Compute Unified Device Architecture (CUDA) as a GPGPU architecture and a development environment. Since recursive Gaussian filters make dependencies between pixels, it is conventional to allocate a line into a thread in a core processes. On the other side, the bitmap Gaussian filter can allocate 1 pixel per 1 thread, which fully utilizes available cores. Thus, recursive Gaussian filters shows better performance in the restricted area where the number of cores is small and the filter window size is large.
We propose a refined recursive Gaussian filter for GPGPU that partitions working domain into two ways. The proposed filter combines a recursive Gaussian filter and FIR filter in order to minimize error rate that occurs by splitting the working domain. The remainder of this paper is structured as follows: ‘Problem environment and related work’ section explains the problem environment and reviews related work. ‘Proposed filter’ section gives details of the proposed refined recursive Gaussian filter. ‘Experimental results’ section gives the experimental results of the proposed filter. Finally, ‘Conclusions’ section concludes with future works.
In order to increase the parallelism of a recursive Gaussian filter, we propose a two-way recursive Gaussian filter. The filter partitions an image in line-based orientation and partitions each line into three blocks again. The first and third blocks use the recursive Gaussian filter, while the second block uses a general Gaussian filter. One major problem is that all pixels in a line are related by a precedence dependency, as shown in Equations 3 and 4. However, we note two facts that circumvent the dependencies in a line:
When out [x,y] is computed in backward pass, out [x + 1,y] through out [x + 3,y] are required. Pixels out [x + 1,y] through out [x + 3,y] are the results of a row-oriented step. If the pixels have already been computed using the basic Gaussian filter, out [x,y] has no precedence dependency on out [x + k,y] where k > 3.
There is no priority between forward and backward passes. Thus, any pass can start in any order.
These facts motivate us to partition a line into the following three parts:
Bl: the left half of the line from index 0 to width/2 - 1, where width is the number of horizontal pixels in the picture.
Pc: the pixel located at width/2.
Br: the right half of the line from index width/2+1 to width -1.
Since forward and backward passes are used to reflect the left-side and right-side neighborhood pixels, respectively, the execution order of the forward and backward passes does not affect the filtering results. After finishing the first pass, that is, computation of w[ ], each block starts a reverse directed pass. It is important to notice the filtering boundary pixels. Boundary pixels like w[0,y],w[1,y], and w[2,y] need values w[-3,y], w[-2,y], and w[-1,y]. Since these values are not available, w[0,y] is used instead. When the direction of computation is changed, pixel out [width/2 - 1,y] needs value out [width/2,y], out [width/2 + 1,y], and out [width/2 + 2,y]. Although these indexes have been computed in Br, they are not the same values as in Equation 4 because those values are generated by the second pass while the values in Br are generated by the first pass.
Algorithm 1 shows the detailed process of row-oriented step of the proposed two-way filter. Three threads are assigned to each row calculated in line 1. Thus a block takes charge of adjacent lines in an image. For example, if four lines are allocated to each block (blockDim.x = 4), the third block filters line 12 ∼ 15. The three threads are identified by pre-assigned value threadIdx.y. If a thread has index (blockIdx.x = 2, threadIdx.x = 2, threadIdx.y = 1), the thread tasks charge of central pixel Pc of line 10. Neighborhood values for boundary pixels are initialized at line 3, 9, 14, and 21. Intermediate array w[row][ ] is divided to two sub arrays w l and w r in order to prevent race condition in w[row][width/2 - 2] ∼ w[row][width/2 + 2], which are overlapped and are accessed concurrently by two threads.
The time complexity of the proposed filter is determined by two factors: line width and filter window size. Assuming that there are enough processors, three processors are allocated to each line. If l = max(width, height), then 3l processors are required in order to maximize the performance. A processor for block Bl or Br computes half of the l/2 pixels in a pass. Since each pixel requires eight multiplications and four additions, 6l operations are required for each pixel. The center pixel Pc requires 3N operations, where N × N is the filter window size. Thus, max(6l,3N) + 6l operations are required per step and max(12l,6N) + 12l steps are required during the proposed filter. In short, the process time of the filter is halved or speedup is doubled compared to those of a one-way recursive Gaussian filter if the number of cores is equal to or greater than 3l.
Intel core i5 750 (2.67 GHz)
Geforce GTX 670 (GK104)
Compute capability, 3.0
Number of CUDA cores 1,344
Graphic clock, 915 MHz
Processor clock, 980 MHz
Visual Studio 2010
512 × 512 bitmap
Gaussian filters usually have been used to de-noise in differential operations for image processing or to achieve image blurring effects. For the differential operations, the typical filter window size is 3 × 3. To obtain a proper blurring effect, we should carefully determine the filter window size according to image sizes. One of the thumb rules suggests 1% ∼5% of the image size for the Gaussian half-width σ and two times of σ for the filter window size. If we take 3% of σ for a 512 × 512 resolution image, the filter window size becomes about 30. Bilateral filters require 10% of σ, then the mask size becomes 102 for the same image resolution. The larger image size requires much larger mask size. In this paper, we take 3 × 3 and 30 × 30 mask size for Lena image.
Validity of the proposed filter
Measure using cudaEventRecord()
Since the parallel CUDA code runs in a GPU, general clock measure functions like gettimeofday() or clock() cannot measure its process time correctly. CUDA provides the cudaEvent family of functions in order to measure process time in a GPU.
Measure using Nsight
Nsight is a development tool provided by NVIDIA and it tells occupancy of parallel applications in GPU. Thus, Nsight can be used to investigate GPU utilization. Occupancy is the percentage of active warps against the maximum active warps, where a warp means a group of 32 threads. The amount of active warps is decided by the number of allocated threads per block, amount of available registers, and amount of shared memory. Allocating more threads to block increases occupancy.Figure10b shows an occupancy comparison between one-way recursive Gaussian filter and two-way recursive Gaussian filter. Since the total number of threads is fixed to data image width or height, that is, 512 in the case of Lena image, many CUDA cores are idle and it makes the CUDA occupancy at the low value. On the other side, two-way recursive Gaussian filter increases its occupancy as the number of lines per block increases over 16 as shown in Figure10b.
Improvement using local memory
Figure9 shows that performances of recursive Gaussian filters degrade as the number of lines per block exceeds 16. The imbalanced block allocation to SMs and sequential global memory access are assumed to be the main reasons of the degradation. Since the balanced allocation policy changes by different graphic card models, finding efficient memory access is focused in order to improve the proposed filter. CUDA provides following four-level hierarchical memory model: constant memory, per-thread local memory, per-block shared memory, and global memory. Constant memory is used to store constant values. Thus, constants in Equations 3 and 4 are stored in constant memory. Image data is stored in the global memory in order to be accessed by all threads. During a forward pass, each pixel in array in [ ] is read once or twice according to filter window size. Thus it is not highly required to copy it in shared or local memory. Since array w[ ] is generated and frequently accessed by each thread, it is good target for locating in local memory. Pixel P c is read six times by adjacent two threads. Since P c is stored in cache of the thread after being read, its memory location does not highly affect the performance of the filtering. As the result, major variables are located in each memory as follows:
Kernel process time components
In this paper, we have noticed that line-oriented recursive Gaussian filter can be partitioned more and proposed a two-way recursive filter that increases CUDA GPGPU utilization. The proposed filter divides each line into two sub-lines and a central point. The central point is used to compensate mismatches occurred by dividing a line into two parts. PSNR shows that the quality of the filter locates between non-recursive Gaussian filter and the one-way line-oriented recursive Gaussian filter. The process time of the proposed filter is reduced to half by setting the number of lines per block to the same or greater than 16.
The research can be expanded by considering following various concerns. Starting from the proposed two-way recursive Gaussian filter, a line can be partitioned to three or more blocks, where quality and speedup are major concerns. Another consideration is the central points. The central points or boundary points between blocks in the partitioned line can be designed differently. The central points are required as boundary points in each block. If recursive equations are designed carefully, it could be possible to partition a line without any central point or boundary point.
- Canny J: A computational approach to edge detection. IEEE Trans. Pattern Anal. Mach. Intell 1986, 8(6):679-698.View ArticleGoogle Scholar
- Luo Y, Duraiswami R: Canny edge detection on NVIDIA CUDA. In IEEE Computer Society Conference on Computer Vision and Pattern Recognition Workshops, 2008. CVPRW’08. IEEE, Anchorage, AK, USA; 2008:1-8.Google Scholar
- Lowe DG: Distinctive image features from scale-invariant keypoints. Int. J. Comput. Vis 2004, 60(2):91-110.View ArticleGoogle Scholar
- Land EH: The Retinex theory of color vision. Sci Am 1977, 237(6):108-128. 10.1038/scientificamerican1277-108View ArticleGoogle Scholar
- Jobson DJ, Rahman Z, Woodell GA: Properties and performance of a center/surround retinex. IEEE Trans. Image Process 1997, 6(3):451-462. 10.1109/83.557356View ArticleGoogle Scholar
- Jobson DJ, Rahman Z-U, Woodell GA: A multi-scale retinex for bridging the gap between colour images and the human observation of scenes. IEEE Trans. Image Process 1997, 6(7):965-976. 10.1109/83.597272View ArticleGoogle Scholar
- Haralick R, Shapiro L: Computer and Robot Vision. Addison-Wesley, Boston, USA; 1992.Google Scholar
- Young IT, van Vliet LJ: Recursive implementation of the Gaussian filter. Signal Process. 1995, 44: 139-151. 10.1016/0165-1684(95)00020-EView ArticleGoogle Scholar
- Shapiro LG, Stockman GC: Image smoothing. In Computer Vision. Prentice Hall, Upper Saddle River, NJ, USA; 2001:137-137.Google Scholar
- Hale D: Recursive gaussian filters. CWP-546 2006. http://www.cwp.mines.edu/Meetings/Project06/cwp546.pdfGoogle Scholar
- Podlozhnyuk V: Image convolution with CUDA. NVIDIA Corporation White Paper, June 2007., 2097(3): https://cluster.earlham.edu/trac/bccd-ng/export/2037/branches/cuda/trees/software/bccd/software/cuda-0.2.1221/sdk/projects/convolutionSeparable/doc/convolutionSeparable.pdfGoogle Scholar
- Vliet LJV, Young IT, Verbeek PW: Recursive Gaussian derivative filters. In Proceedings of the Fourteenth International Conference on Pattern Recognition, 1998. IEEE, Brisbane, Queensland, Australia; 1998:509-514.Google Scholar
- NVIDIA Corporation: White Paper NVIDIA GeForce GTX 680. 2012.http://www.geforce.com/Active/en_US/en_US/pdf/GeForce-GTX-680-Whitepaper-FINAL.pdfGoogle Scholar
- Jaaskelainen P, de La Lama CS, Huerta P, Takala JH: OpenCL-based design methodology for application-specific processors. In 2010 International Conference on Embedded Computer Systems. IEEE, Samos, Greek; 2010:223-230s.Google Scholar
- CUDA Parallel computing platform , Jan. 2014 http://www.nvidia.com/object/cuda_home_new.html
- Foster I, Zhao Y, Raicu I, Lu S: Cloud computing and grid computing 360-degree compared. In Grid Computing Environments Workshop, 2008. GCE’08. IEEE; 2008:1-10.View ArticleGoogle Scholar
- Su Y, Xu Z, Jiang X: GPGPU-based Gaussian filtering for surface metrological data processing. In IV. IEEE Computer Society; 2008:94-99. doi:10.1109/IV.2008.14Google Scholar
- Trabelsi A, Savaria Y: A 2D Gaussian smoothing kernel mapped to heterogeneous platforms. In 2013 IEEE 11th International New Circuits and Systems Conference (NEWCAS). IEEE, Paris, France; 2013:1-4.View ArticleGoogle Scholar
- Ryu J, Nishimura TH: Fast image blurring using Lookup Table for real time feature extraction. In IEEE International Symposium on Industrial Electronics, 2009. ISIE 2009. IEEE, Seoul, Korea; 2009:1864-1869.View ArticleGoogle Scholar
- Deriche R: Recursively implementating the Gaussian and its derivatives. 1993.http://hal.archives-ouvertes.fr/docs/00/07/47/78/PDF/RR-1893.pdfGoogle Scholar
- Ma Y, Xie K, Peng M: A parallel Gaussian filtering algorithm based on color difference. In IPTC. IEEE; 2011:51-54. http://ieeexplore.ieee.org/xpl/mostRecentIssue.jsp?punumber=6099690Google Scholar
- Nehab D, Maximo A, Lima RS, Hoppe H: GPU-efficient recursive filtering and summed-area tables. ACM Trans. Graph. 2011, 30(6):176:1-176:11.View ArticleGoogle Scholar
- Adams A, Gelfand N, Dolson J, MsLevoy: Gaussian KD-trees for fast high-dimensional filtering. In ACM Transactions on Graphics (TOG), Volume 28. ACM; 2009:21-21.Google Scholar
- Paris S, Durand F: A fast approximation of the bilateral filter using a signal processing approach. In Computer Vision–ECCV 2006. Springer, Graz, Austria; 2006:568-580.View ArticleGoogle Scholar
- Park SK, Kim BS, Chung EY, Lee KH: A new illumination estimation method based on local gradient for retinex. In IEEE International Symposium on Industrial Electronics, 2009. ISIE 2009. IEEE, Seoul, Korea; 2009:569-574.View ArticleGoogle Scholar
- Luitjens J, Rennich S: CUDA warps and occupancy. GPU Computing Webinar 2011.Google Scholar
- NVIDIA Nsight Visual Studio Edition June 2014 https://developer.nvidia.com/nvidia-nsight-visual-studio-edition
- NVIDIA: Programming model. In CUDA C Programming Guide, Design Guide. NVIDIA; 2013:12-13. June 2014 http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#axzz34o3nNnUFGoogle Scholar
This article is published under license to BioMed Central Ltd. This is an Open Access article distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/by/2.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly credited.