{'fraction_non_alphanumeric': 0.02762299940723177, 'fraction_numerical': 0.009187907528156491, 'mean_word_length': 4.640588431962555, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Screen Content Image Segmentation Using Sparse-Smooth Decomposition

Sparse decomposition has been extensively used for different applications including signal compression and denoising and document analysis. In this paper, sparse decomposition is used for image segmentation. The proposed algorithm separates the background and foreground using a sparse-smooth decomposition technique such that the smooth and sparse components correspond to the background and foreground respectively. This algorithm is tested on several test images from HEVC test sequences and is shown to have superior performance over other methods, such as the hierarchical k-means clustering in DjVu. This segmentation algorithm can also be used for text extraction, video compression and medical image segmentation.


I. INTRODUCTION
Image segmentation aims to decompose an image into multiple parts, making its processing easier and more meaningful. One special case of this segmentation is background/foreground separation which tries to decompose an image into two components, background and foreground. This background/foreground separation can be used in various applications including: text extraction from document images [1], separate coding of background and foreground for compression of mixed content images [2], medical image segmentation and classification [3], and line extraction for palmprint recognition [4].
The segmentation algorithm in this paper is mainly designed for screen content images which refer to images generated by the display screens of electronic devices. These images have some fundamental differences with photographic images and the usual image compression algorithms such as JPEG2000 [5] and HEVC intra-frame coding [6] may not result in a good compression rate for this kind of images. This is due to the existence of many sharp edges in this type of images. As a result, the energy cannot be compacted in a few coefficients and will be distributed in most of the transform domain coefficients, resulting in a high bit-rate. In these cases, segmenting the image into two layers and coding them separately could be more efficient. The idea of segmenting an image for better compression was proposed in DjVu algorithm for scanned document compression [7] and the mixed raster content representation [2].
There are a few existing works for segmenting the image into background and foreground and coding them separately. Some of them use color clustering to perform the segmentation. Among them, DjVu [7] is a popular document format which uses hierarchical k-means clustering for segmentation. It applies the k-means clustering algorithm with k=2 on blocks in multi-resolution. Some of the other works use morphological operations to separate the background layer from the foreground. In [8], Huang proposed one such algorithm for check image compression where he first segments the check image into different layers using the morphological operation and then code them separately. Some other algorithms use simple color counting with some post-processing to perform background/foreground segmentation. Shape primitive extraction and coding (SPEC) [9] is an example of such algorithms. In SPEC a two-step segmentation algorithm is proposed to separate background from foreground. The first step uses the number of colors for segmentation and the second step will refine the results by extracting shape primitives (horizontal lines, vertical lines or rectangles with the same color). Most of these approaches have difficulty for some of the screen content images where the foreground is overlaid over a smoothly varying background that has a large color range that overlaps with the color of the foreground and they usually tend to segment some part of the background as foreground.
In this work, a sparse decomposition framework is proposed for background/foreground segmentation that it is able to perform a correct segmentation even if the background and foreground colors overlap. Sparse representation has been used for various applications in recent years, including face recognition [10], super-resolution [11], matrix decomposition [12], image restoration [13], detection and estimation [14], sparse coding [15] and image classification [16]. Despite the huge application of sparse representation, to the best of our knowledge, it has not been used for image segmentation so far. The proposed algorithm in this paper is designed based on the intuition that in most of screen content images, background contains the smoothly varying part of the image, while foreground contains text, line and graphics creating sharp discontinuity. Therefore background can be approximately represented by a smooth model, whereas the foreground cannot be modeled with this smooth representation. Then the main effort is to find a suitable low-order smooth representation for background and classifying each pixel in the image into either background or foreground part. Since the foreground layer is expected to contain the high frequency part of the image, this algorithm can also be used for extraction of iris patterns from iris images arXiv:1511.06911v1 [cs.CV] 21 Nov 2015 [17], and also minutiae from fingerprint [18].
The rest of this paper is structured as follows. Sparsesmooth decomposition formulation is explained in Section II. Section III presents the overall segmentation algorithms. The experimental results and comparisons are provided in Section IV and the paper is concluded in Section V.

SEGMENTATION
Sparsity-based signal decomposition has drawn a lot of attention in recent years because of its tremendous success in achieving the state-of-the-art results in many areas. To decompose a signal into its components using sparse representation, usually two or more suitable dictionaries are found which are suitable for sparse representation of only one signal component, but not the others. As an example, to decompose a signal into two components as x = x 1 + x 2 , we need to find two over-complete dictionaries T 1 and T 2 which are suitable to sparsify x 1 and x 2 respectively. Then x can be written as x = T 1 α 1 + T 2 α 2 by solving the following optimization problem: arg min α1,α2 After solving this optimization problem, T 1 α 1 will correspond to the first component and T 2 α 2 will correspond to the second component. The same technique can also be used for decomposition of a signal into more than two components. In [19], Starck used a similar idea for image decomposition into texture and natural part. They also used total variation penalization to enforce smoothness to decomposition. In this paper, a segmentation algorithm is designed based on decomposition of the image into a smooth and a sparse component, which we call smooth-sparse decomposition. It is designed based on the observation that the background part of the images mostly consist of smooth regions. Therefore they should be well-represented with a low order smooth model. By well-representation, we mean that the error of smooth approximation should be less than a desired threshold.
First the image is divided into non-overlapping blocks. Then each image block of size N×N, F (x, y), is represented with a smooth modelF (x, y; α 1 , ..., α K ), where x and y denote the horizontal and vertical axes and α 1 , ..., α K are the parameters of smooth model. HereF (x, y; α 1 , ..., α K ) is proposed to be chosen as a linear combination of K smooth basis functions K k=1 α k P k (x, y), where P k (x, y) denotes a 2D smooth basis function. Here we use a set of low frequency two-dimensional DCT basis functions, since they are shown to be very suitable for natural image representation [20] which is usually smooth. The 2-D DCT function is defined as: where u and v denote the frequency of the basis. All basis functions are ordered in a zig-zag fashion in the (u,v) plane, and the first K basis functions are chosen. Therefore the smooth approximation of an image block will beF (x, y) = K k=1 α k P k (x, y). As mentioned earlier, some parts of images cannot be represented with this smooth model, such as texts, lines and other high-frequency components which are overlaid on the smooth regions. To have a more general model which can represent both smooth and non-smooth parts of the image, we propose to add another component S to the model as: where K i=1 α i P i (x, y) and S(x, y) correspond to the smooth background region and foreground pixels respectively. The S component is usually sparse and contains the sharp edges and texts. So after performing this decomposition, those pixels which can be approximated as K i=1 α i P i (x, y) will be considered as background and the rest as foreground.
To have a more compact notation, we can look at the 1D version of this problem by converting the 2D blocks of size N ×N into a vector of length N 2 , denoted by f , and denoting K k=1 α k P k (x, y) as P α where P is a matrix of size N 2 × K in which the k-th column corresponds to the vectorized version of P k (x, y) and α = [α 1 , ..., α K ] T . The 1D version of S(x, y) is denoted by s. Now to decompose the image, we need to derive the α i 's and S. To do so, we need to have some prior knowledge about these components. Here we proposed to solve this decomposition problem by maximizing the number of background pixels or equivalently minimizing the number of foreground pixels such that we do not try to model high frequency component in the image. This method is very desirable in image and video compression applications, because the background component can be easily represented using a set of low-order DCT bases. So the more background pixels we have, the smaller bit-rate we usually need. But we have to be careful not to represent the text and graphics by smooth model. To achieve this, we can have a regularization term which penalizes using too many basis. Therefore we can solve the following optimization problem: minimize where q is a the scalar which controls the trade-off between these two terms. Since L0 minimization is not a convex problem, we use L1 minimization as an approximation of L0 minimization which results in the following basis pursuit problem: minimize s,α To further simplify this optimization, we can push q in P and minimize s 1 + α 1 instead of s 1 + q α 1 . Therefore we can solve the following problem which is equivalent to (2): minimize s,α where P = 1 q P . Now this problem can be written in a more compact way by defining the new variable y as the concatenated version of s and α, as y T = [S α] and defining G N 2 ×(N 2 +K) as: After solving this optimization problem, the first N 2 elements of y will correspond to the S component in the initial model and the rest of y components correspond to α i 's. We can also look at the unconstrained version of this problem which is usually easier to solve by choosing a proper λ as: Solving the unconstrained problem is usually simpler than the constrained version, and in the remaining part of the paper, we focus on solving (5). As it can be seen, this is the standard basis pursuit denoising problem and can be solved with iterative algorithms such as ISTA [21], FISTA [22] and ADMM [23]. In this work, we have used ADMM algorithm to solve this problem.

A. ADMM Formulation For LASSO
ADMM (Alternating Direction Method of Multipliers) is a popular algorithm which combines superior convergence properties of method of multiplier and decomposability of dual ascent. In the ADMM form, the optimization problem in (5) can be formulated as: Then the following updates can be used for each iteration in ADMM [23]: where ρ is the augmented Lagrangian parameter and S λ/ρ denotes the soft-thresholding operator applied elementwise and is defined as: We have to mention that the decomposition problem in (1) can also be done using robust regression which is studied in [24] and [25].

III. OVERALL SEGMENTATION ALGORITHM
Some parts of images might be very simple to segment. Therefore we may not need to use sparse decomposition for segmentation of the entire image. Consequently we have some initial steps which first check if a block can be segmented using simpler approaches. These simpler approaches take care of two categories of blocks: entirely flat block in which all pixels have the same value and are common in screen content images and smoothly varying background without foreground in which the intensity of all pixels can be modeled well by the smooth function. Entirely flat blocks can be declared as background or foreground based on their neighboring blocks' background color. For these blocks, if we could find at least one neighbor block with a background color close enough to the current block's color (with a difference less than 2 ), it would be segmented as background. For smoothly varying background, we try to fit K DCT basis to all pixels using least square fitting and if the intensity of all pixels can be predicted with distortion less than 3 , that block would be segmented entirely as background. We will use the sparse decomposition method only if a block does not satisfy these two conditions.
The segmentation algorithm is summarized below: 1) If all pixels in the block have the same color intensity (i.e. it is entirely flat block), declare the entire block as background or foreground as explained above. If not, go to the next step; 2) Perform least square fitting using the luminance values of all pixels. If all pixels can be predicted with an absolute error less than 3 , declare the entire block as background. If not, go to the next step; 3) Use sparse-smooth decomposition to fit a model to the luminance values of image block and find the absolute fitting error of all pixels using the smooth model. Each pixel with a distortion less than a threshold 1 will be considered as background, otherwise as foreground. IV.

RESULTS
We have tested our algorithm on several test images selected from HEVC standard test sequences for screen content coding. We have generated a dataset consisting of 332 image blocks of size 64 × 64. The ground truth foreground maps for these images are extracted manually. This dataset is publicly available and can be downloaded from [26].
Before showing the results, let us discuss about the parameters used in our algorithm. The block size and the number of DCT bases are chosen to be N =64 and K=10 respectively. The weight parameter q is chosen to be q = 1 100 . For the segmentation steps, the parameters are chosen as 1 , 2 = 10 and 3 = 3, which have been found to perform well on a training set. For the ADMM algorithm, the implementation by Stephen Boyd [27] is used. The number of iterations is chosen to be 100 and the parameter ρ is set to 1 as the default value.
We have compared the segmentation result of the proposed algorithm with hierarchical k-means clustering in [7] and shape primitive extraction and coding in [9]. To provide a numerical comparison between the proposed scheme and the previous approaches, we have calculated the average precision and recall achieved by different segmentation algorithms over this dataset. The average precision and recall by different algorithms are given in Table 1. As it can be seen, the proposed scheme achieves a much higher precision and recall than other algorithms.   Figure 1 shows the segmentation result by different algorithms for 5 test images. As it can be seen, the proposed scheme outperforms both the hierarchical k-means clustering and SPEC algorithm in terms of visual quality of the segmentation. We have mainly used challenging images in our dataset where the background and foreground have overlapping color ranges. For simpler cases where the background has a narrow color range that is quite different from the foreground, hierarchical k-means clustering algorithm will also perform well.

V. CONCLUSION
In this paper, an algorithm for separation of background and foreground is proposed, assuming that the background usually contains the smooth parts of the image and foreground contains text, lines and graphics. This algorithm decomposes the image into two components, smooth and sparse, which correspond to the background and foreground layers respectively. A regularized L1 optimization problem is used to perform this decomposition. A pixel is considered background if it can be represented accurately by the smooth model; otherwise it will be considered as foreground. To speed up the algorithm, we developed some initial steps to segment the simple blocks. The proposed scheme has been tested on a set of screen content images and is compared with two other algorithms, DjVu and SPEC, exhibiting superior performance for cases where foreground and background colors overlap. Besides screen content image segmentation, this algorithm can be utilized in text extraction from images and medical image segmentation.