Full text
Noname manuscript No. (will be inserted by the editor) GPU Accelerated Waterpixel algorithm for Superpixel Segmentation of Hyperspectral Images Pablo Quesada-Barriuso ·Dora B. Heras · Francisco Arg¨ uello Received: date / Accepted: date Abstract The high computational cost of the superpixel segmentation algorithms for hyperspectral remote sensing images makes them ideal candidates for parallel computation. The waterpixel algorithm, in particular, extracts segmentation regions called waterpixels and consists of four stages called vectorial gradient, spatial regularization, marker selection, and watershed transform. In this paper, an efficient version of a GPU algorithm for waterpixel segmentation using the Compute Unified Device Architecture (CUDA) is presented. The algorithm extracts all the spectral information available in the bands of the hyperspectral image through the vectorial gradient. A cellular automaton is selected for the computation of the watershed transform using a block-asynchronous implementation with 8-connectivity. The experimental analysis shows high speedup values for the resulting GPU algorithm when it is compared to a multicore OpenMP implementation using 8 threads. Keywords Superpixel segmentation ·Watershed transform ·Waterpixel segmentation ·Hyperspectral image ·Remote sensing ·CUDA 1 Introduction Hyperspectral remote sensing is concerned with the measurement and analysis of the spectra acquired for a given scene at a short, medium or long distance by an airborne or satellite sensor [1]. One of the reasons of its widespread use is the progressive Pablo Quesada-Barriuso Departamento de Electr´ onica y Computaci´ on, Universidad de Santiago de Compostela, Santiago de Compostela, Spain E-mail: [email protected] Dora B. Heras Centro Singular de Investigaci´ on en Tecnolog´ ıas Inteligentes (CiTIUS), Universidad de Santiago de Compostela, Santiago de Compostela, Spain E-mail: [email protected] Francisco Arg¨ uello Departamento de Electr´ onica y Computaci´ on, Universidad de Santiago de Compostela, Santiago de Compostela, Spain E-mail: [email protected] This is a post-peer-review, pre-copyedit version of an article published in The Journal of Supercomputing. The final authenticated version is available online at: https://link.springer.com/article/10.1007/s11227-021-03666-y 1
2 Pablo Quesada-Barriuso et al. reduction in cost of the sensors that makes, for example, the use of a multispectral or hyperspectral sensor on board Unmanned Aerial Vehicles (UAV) affordable for different purposes [2]. The huge amount of data acquired by these sensors need to be processed in most cases automatically, and in many cases with real-time processing requirements, making the demand for processing power increasing. This is usually obtained by both, optimizing the tasks required to process the images, and using advanced computing platforms [3]. This work focuses on the use of single graphics processing unit (GPU) to exploit its streaming processing and performing efficient computing as close as possible to the final user. Superpixel-based segmentation [4,5], extracts regions called superpixels replacing the pixel-based grid of an image by a higher scale grid. A superpixel is a set of neighbouring pixels which are similar in terms of low-level properties such as color similarity or intensity, among others. It captures image redundancy, provides a convenient primitive from which to compute image features, and greatly reduces the complexity of subsequent image processing tasks [6]. Examples of the use of superpixels in hyperspectral classification as a way to exploit context information and reduce the cost of the classification task can be found in [6–9]. Waterpixel segmentation [10] is a gradient ascent method [6]. It defines as a general strategy for generating superpixels called waterpixels and it relies on the marker controlled watershed transformation. A spatially regularized gradient is applied to achieve a tunable tradeoff between the superpixel regularity and the adherence to object boundaries. The complexity of the resulting method is linear with respect to the number of pixels in the image. Although the waterpixels are in some cases irregular in size and shape, the watershed algorithm presents the advantage of a complexity that is linear with the number of pixels. On the contrary, other more tunable superpixel algorithms such as Simple Linear Iterative Clustering (SLIC) [11], which requires a higher complexity iterative process, offer more robust segmentation results. Considering that remote sensing images are large, techniques for superpixel segmentation of hyperspectral images can be very time consuming, which makes them good candidates for HPC. Different computationally efficient solutions can be found in the literature. Focusing on GPU, SLIC is the most frequently implemented superpixel algorithm. A baseline GPU implementation is presented in [12]. The algorithm, called gSLIC, is split into two parts: GPU k-means iteration, and CPU connectivity enforcement. In the GPU part, one cluster per thread is used to update the center of the superpixel eliminating the need for atomic operations. A further improvement of this method, called gSLICr [13], implements the connectivity enforcement part in GPU. GPU implementations of other superpixel algorithms have also been proposed in the bibliography. In [14] a GPU implementation of the quick shift algorithm is presented. For superpixel algorithms based on the Gaussian mixture model (GMM), the performance reported in [15] achieves a speedup of 21×as compared to that of the OpenMP implementation. In this paper, we propose an efficient GPU implementation of a waterpixel segmentation algorithm [10] using the CUDA framework. it is based on the asynchronous implementation of a cellular automata and exploits the resources provided by a Pascal GPU architecture. This is a post-peer-review, pre-copyedit version of an article published in The Journal of Supercomputing. The final authenticated version is available online at: https://link.springer.com/article/10.1007/s11227-021-03666-y 2
GPU Accelerated Waterpixel algorithm for Superpixel Segmentation of Hyperspectral Images 3 Fig. 1 Waterpixel segmentation of a hyperspectral image. 2 Waterpixel segmentation of hyperspectral images In this section we explain the waterpixel segmentation algorithm used in this paper. It is a based on segmenting by applying the watershed transform to the gradient of the image [16]. Figure 1 shows the process consisting mainly of 4 steps: vectorial gradient, spatial regularization, selection of markers, and watershed transform. 2.1 Vectorial gradient As the watershed segmentation algorithm is defined for grayscale images [17], the first step transforms the input image to a scale of gray values by means of a vectorial gradient, as shown in Figure 1. For hyperspectral images, each pixel is represented as a vector of values corresponding to the different wavelength responses (spectral bands) of reflected light acquired by a hyperspectral sensor. Different gradient operators can be used to perform this reduction [18]. Let XNbe a hyperspectral image with pixel vectors of size N, with Nthe number of spectral bands, and g= [x1 N,x2 N,...,xn N]be a set of npixel vectors inside a structuring element gcentered at xp N. The vectorial gradient of the hyperspectral image ∇(X) is defined as: ∇(X) = max i,j∈g{||xi N−xj N||2}.(1) Different metrics can be used for computing distances among pixel vectors. In this work we use the Euclidean distance, as indicated in Eq. (1). This is a post-peer-review, pre-copyedit version of an article published in The Journal of Supercomputing. The final authenticated version is available online at: https://link.springer.com/article/10.1007/s11227-021-03666-y 3
4 Pablo Quesada-Barriuso et al. Fig. 2 Example of spatial regularization over a hexagonal grid: (a) a vectorial gradient, (b): hexagonal grid and, (c) distance of a pixel to the center of two adjacent cells. The closest distance is marked in red. 2.2 Spatial regularization and selection of markers The second and the third steps of the waterpixel algorithm (See Figure 1) have the vectorial gradient as input. The gradient is divided into a regular grid of Scells of radius σ, with Sbeing the number of superpixels. These cells can be of any regular shape, i.e., square, circle or hexagon. Figure 2(a) shows a vectorial gradient and Figure 2(b) the cells of the corresponding hexagonal grid. The spatial regularization of the gradient (∇r) ensures a limit in the size of the superpixels based on the size of the cells through the radius σand a parameter k∈R+as defined by the following equation [16]: ∇r(X) = ∇(X)+k2d σ,(2) where dis the distance of a pixel to the closest cell center. Figure 2(c) shows an example of the distance of a pixel (in green) to the center of two adjacent cells of radius 4. The closest distance to the center is marked in red. In Eq. (2), the parameter kcontrols the compactness that is related to the regularity and smoothness of the superpixels. No regularization is applied if k=0, whereas the result approaches a regular grid if k→∞. The third step of the waterpixel algorithm (See Figure 1) is the marker selection. A set of markers are selected as starting seeds for the segmentation. For each cell of the regular grid, the minimum grayscale value of each pixel within the cell is used as a marker. 2.3 Watershed transform In the last step of the algorithm, step 4 in Fig. 1, the watershed segmentation is applied to the regularized gradient starting from the markers. In this work we use the hillclimbing algorithm based on distances [19]. The idea is based on a representation of the image as a topographic relief, where the height of each pixel is directly related to its gray level. The markers are initialized with unique labels which are propagated upwards, climbing up the hill, inside a 3 ×3 structuring element. The hill-climbing algorithm used in this paper focuses on a method that is based on a three-state cellular automaton (CA) [20]. The CA, illustrated in Figure 3(a), initializes all the pixels of the image with unique labels and indicates the propagation direction through two different states. Considering that a plateau is a region of the image of constant gray values, these states This is a post-peer-review, pre-copyedit version of an article published in The Journal of Supercomputing. The final authenticated version is available online at: https://link.springer.com/article/10.1007/s11227-021-03666-y 4
GPU Accelerated Waterpixel algorithm for Superpixel Segmentation of Hyperspectral Images 5 Fig. 3 Watershed transform based on cellular automata: (a) three-state automaton implementing the Hill- Climbing algorithm [20], (b) example of the evolution of the automaton for an image represented as a terrain (top lines) and the corresponding gray values of each pixel (bottom squares). are ”minimum or plateau” (MP) and non-minimum (NM). The automaton evolves iteratively and propagates the same label through the plateau if the state is MP and switches to NM state if the gray value of the plateau is non-minimum. If a pixel is in the NM state, the label is propagated in the climbing direction. Figure 3(b) shows an example in one dimension of the evolution of the automaton for an image represented as a terrain (top lines) and the corresponding gray values of each pixel (bottom squares). 3 CUDA implementation of the waterpixel algorithm In this section, the main challenges when programming the waterpixel segmentation algorithm on GPU as well as the four stages of the GPU algorithm are described. CUDA is the computing platform and programming model for parallel computing on Nvidia GPUs. In this architecture, a program, that is known as a kernel, is executed in parallel by hundreds of threads arranged in a grid of blocks [21]. Various optimization strategies should be considered when programming a GPU: (1) reduce data transfer among the CPU and GPU, (2) reuse data in the GPU memory, and (3) search for the best configuration of threads that takes the maximum profit of the resources available on the GPU. The first two strategies affect the memory read and write latencies. The third one is related to the occupancy, which offers a first idea of the GPU implementation performance[21]. In this work we also considered: (4) use atomic operations to prevent race conditions among threads, (5) data partitioning in the spectral domain [22], and (6) block asynchronous strategies for CA [23]. In the following sections, the kernels shown in the pseudocodes are placed between <> symbols and threads within a block are indicated as tid, whereas threads within the grid are indicated as gid. The pseudocode highlights the use of global memory (GM) and shared memory (SM) to indicate where data are placed. The optimization strategies applied to each kernel will also be described. The GPU waterpixel segmentation of hyperspectral images is detailed in Algorithm 1. This is a post-peer-review, pre-copyedit version of an article published in The Journal of Supercomputing. The final authenticated version is available online at: https://link.springer.com/article/10.1007/s11227-021-03666-y 5
6 Pablo Quesada-Barriuso et al. Algorithm 1: GPU waterpixel segmentation Input: A hyperspectral image X Output: Waterpixel segmentation WX 1copy Xto GPU memory 2∇(X)←<vectorial gradient>(X)// SM 3∇r(X)←<spatial regularization>(∇(X),σ)// GM 4M←<selection of markers>(X,σ)// GM 5CA ←<initialize automaton>(∇r(X),M)// GM 6while CA is not stable do 7CAk+1←<update automaton>(CAk)// SM 8global synchronization among threads within the GPU 9end 3.1 GPU vectorial gradient The vectorial gradient is implemented in one kernel, where threads are organized in 2-D blocks and loop through the hyperspectral bands of the image. This technique is known as spectral-domain partitioning [22]. The pseudocode in Algorithm 2 summarizes this kernel. Algorithm 2: kernel vectorial gradient Input: A hyperspectral image X Output: A two dimensional morphological gradient ∇(X) 1for each band Xk∈X do 2calculate gid within the Xkband 3shared xk[tid] = Xk[gid]// GM →SM 4synchronize threads within the same block 5vgrad += maxi,j∈g{||Xi k−Xj k||2}// SM (Eq.1) 6end 7∇[gid]= vgrad // GM ←SM 8 A tile of data are read into the shared memory (line 3) and distances among pixels are accumulated in registers (line 5). Thus, this kernel reuses data in the GPU shared memory when computing Xi k−Xj kat each step of the loop. One thread processes all the spectral components of one pixel vector and the gradient is copied to global memory at the end of the loop. The main strategies used for optimizing this kernel are optimization strategies (2) (reuse data in the GPU memory) and (5) (data partitioning in the spectral domain) listed in Section 3. 3.2 GPU spatial regularization and selection of markers As explained in Section 2.2 the spatial regularization and the selection of markers use the vectorial gradient as input. Algorithm 3 shows the pseudocode for the spatial regularization. This is a post-peer-review, pre-copyedit version of an article published in The Journal of Supercomputing. The final authenticated version is available online at: https://link.springer.com/article/10.1007/s11227-021-03666-y 6
GPU Accelerated Waterpixel algorithm for Superpixel Segmentation of Hyperspectral Images 7 Algorithm 3: kernel spatial regularization Input: A two dimensional morphological gradient ∇(X) Output: A spatial regularized gradient ∇r(X) 1calculate the cell center within ∇(X) 2for y=−σ,+σdo 3for x=−σ,+σdo 4calculate the gid within the cell 5d = p(x2+y2) 6∇r[gid]=∇[gid]+k2d σ// GM (Eq.2) 7end 8end Threads are organized in 1-D blocks. One thread processes all the pixels in a σ×σsquare cell, as indicated in lines 2–8 in Algorithm 3. Each pixel of the gradient is updated directly in global memory (line 5). The loop in lines 2–8 could be modified for processing other regular cells (see Section 2.2) by applying a mask with the shape of the desired cell, for example, a hexagon. The same approach described in Algorithm 3 is used for the selection of markers. One thread searches the position of the minimum grayscale value within a cell. In both kernels, spatial regularization and selection of markers,the block size and the grid configuration depend on σ, the superpixel size. Optimization strategy (3), the selection of the best thread configuration, was the key for optimizing both kernels. 3.3 GPU watershed transform based on cellular automata The watershed transform based on a cellular automaton (CA-watershed) has been efficiently implemented on GPU in the literature [23]. Among the various proposals in [23] we use the artifact-free block-asynchronous implementation. As it starts the segmentation from any minimum values and the waterpixel segmentation algorithm [16] requires to start the segmentation from markers, some modifications were necessary. Algorithm 4: Asynchronous watershed based on a cellular automaton using GPU Input: Spatial regularized gradient ∇r(X), a set of markers M Output: Waterpixel segmentation WX 1<initialize automaton>(∇r(X),M)→∇r,labels, states, connectivity // GM 2while CA is not stable do 3CAk+1←<update automaton>(CAk)// SM 4global synchronization among threads within the GPU 5end Algorithm 4 shows the pseudocode for the block-asynchronous CA-watershed. The algorithm has two kernels (lines 1 and 3) implementing the initialization and updating stages of the automaton described in Section 2.3. These kernels are config- This is a post-peer-review, pre-copyedit version of an article published in The Journal of Supercomputing. The final authenticated version is available online at: https://link.springer.com/article/10.1007/s11227-021-03666-y 7
8 Pablo Quesada-Barriuso et al. ured to work in two dimensional blocks, where each thread processes one pixel of the spatial regularized gradient ∇r(X). 4 Results The waterpixel segmentation of hyperspectral images has been evaluated on a PC with a quad-core Intel Xeon E5-2623v4 at 2.6 Ghz and 128 GB of RAM under Ubuntu 16.04.6. The computer has a Tesla P40 GPU with a CC 6.1 (Pascal architecture). The P40 has 3840 cores, operating at 1.5 Ghz and distributed in 30 multiprocessors. The size of global memory is 24 GB. The CPU implementation has been compiled using the gcc 7.5.0 version with OpenMP 4.5 support, and the GPU implementation using the nvcc compiler version 10.0 (CUDA version). Full optimization flags (-O3) were used in both cases. Arithmetic operations were computed in single precision (4 bytes) and eight threads were used for the OpenMP implementation. The size of the superpixel (σ) was set to 9 and the parameter kfor controlling the compactness of the superpixel was empirically setup to 12000. Four hyperspectral images with different dimensions in the spectral and spatial domain, as well as different land-cover thematic (farmland, mountains and urban areas) were used for evaluating the implementation. The dimensions of the images are summarized in Table 1. Figure 4 shows a colour composition of the hyperspectral images. Note that the images in this figure are scaled for a better layout. The real dimensions of the hyperspectral images are detailed in Table 1 for the. Performance results in terms computation time and speedup are presented as the average of ten independent executions. The time required for I/O operations was excluded from the analysis. Table 1 Hyperspectral image description Hyperspectral image Sensor Width ×Height ×Bands Size (MBytes) Santa Barbara Line 1 AVIRIS 716 ×8192 ×224 5012 Santa Barbara Line 2 AVIRIS 769 ×1024 ×224 673 Indiana North South AVIRIS 614 ×2678 ×220 1280 Pavia City ROSIS-03 1400 ×512 ×102 279 Fig. 4 Hyperspectral images used in the performance evaluation: (a) Santa Barbara Line 1, (b) Santa Barbara Line 2, (c) Indiana North South, (d) Pavia City. This is a post-peer-review, pre-copyedit version of an article published in The Journal of Supercomputing. The final authenticated version is available online at: https://link.springer.com/article/10.1007/s11227-021-03666-y 8
GPU Accelerated Waterpixel algorithm for Superpixel Segmentation of Hyperspectral Images 9 An OpenMP implementation has been developed as a baseline for evaluation of the GPU implementation. It follows the same scheme described in Algorithm 1. Figure 5(a) shows the speedup for the 8-thread OpenMP code over the sequential CPU one for each hyperspectral image. As expected, a higher speedup is observed as the number of threads increases. Other factors that influence the speedup are the size of the image, the number of bands, and the image structure. The latter factor is especially important since the regularity of the homogeneous regions in the image increases the time required by the segmentation step. The reason is that the homogeneous regions require longer paths for the label propagation and, as a consequence, a higher number of updates in the evolution of the cellular automaton. A breakdown of the speedup of each step for the multi-threaded OpenMP implementation with respect to the sequential CPU version is shown in Figs. 5(b) to 5(e). The speedup for the vectorial gradient (Fig. 5(b)) is higher for the bigger images, Indiana North South and Santa Barbara Line 1. The work is divided in tiles among threads with each thread processing all the spectral components of a set of neighbouring pixels (see Eq. (1)). The vectorial gradient is a cache-intensive algorithm that benefits from parallel execution. This is observed in the 10.2×superlinear speedup obtained with 8 threads for the vectorial gradient for the Indiana image (see Fig. 5(b)). Finally, the speedup for the watershed transform based on a CA (Fig. 5(e)) depends on the size of the image, on how the labels are propagated, and on the number of segmented regions. This is the reason why the scaling for the image of Pavia City is better than that for the image Santa Barbara Line 1 and similar to the image Santa Barbara Line 2 scaling, despite the dimensions of the Pavia City image are smaller. It takes longer for the CA update the homogeneous regions in Pavia City, so a better speedup is obtained as the Fig. 5 Speedups for the 8-thread OpenMP implementation over the sequential CPU implementation for different hyperspectral images. a) global speedup, b) speedup for the vectorial gradient, c) speedup for the regularization step, d) speedup for the marker selection, e) speedup for the watershed transform. This is a post-peer-review, pre-copyedit version of an article published in The Journal of Supercomputing. The final authenticated version is available online at: https://link.springer.com/article/10.1007/s11227-021-03666-y 9