1 Introduction

Image compression reduces the amount of data required to represent a digital image. A large size of digital image requires large storage space, large bandwidth and more time for uploading and downloading on the internet. The problem can be solved by reducing the redundant and/or irrelevant information from the image. Image compression is widely used in medical imaging, remote sensing, video conferencing, high definition television, fax etc. Many image compression methods have been developed in literature. Among these commonly used compression techniques include discrete cosine transform (DCT) based such as joint photographic experts group (JPEG), wavelet based methods such as JPEG2000, fuzzy based, neural networks based, optimization techniques based image compression methods [3, 13, 21, 30, 38, 39].

Motivation JPEG based on DCT is the most popularly used image compression standard. However when low bit rate is to be achieved, JPEG produces compressed images that suffer from annoying blocking artifacts. To reduce the blocking artifacts onto the compressed images fuzzy transform is utilized by various researchers [25, 26]. Since fuzzy transform converts a complex problem into a respective problem of linear algebra that deals with vectors making computations easier and also possess an important property of preserving monotonicity [28] that can be utilized significantly to improve the quality of reconstructed image, hence in this paper we propose pairFuzzy algorithm based on improved fuzzy transform to compress the images.

PairFuzzy based image compression algorithm consists of three main steps:

  1. 1.

    Preprocessing using competitive fuzzy edge detection In this step, input image blocks are classified into low-variation (LV) block, medium variation (MV) block or a high variation (HV) block using competitive fuzzy edge detector.

  2. 2.

    Compression and decompression using impro-ved fuzzy transform The LV, MV and HV block are compressed and decompressed using improved F-transform.

  3. 3.

    Postprocessing (Artifact reduction with fuzzy switched median filter) The resultant decompressed image may contain some blocking artifacts, that are reduced using fuzzy switched median filter during postprocessing.

Contribution It is well known that image blocks with many edge pixels have more information and hence should be less compressed, whereas image blocks with smooth regions should be more compressed. Fuzzy transform based image compression method [7] compresses each image block to the same level without taking into the consideration whether containing the edge information or not. Whereas, the algorithm proposed in this paper called pairFuzzy algorithm compresses each image block taking into account the amount of edge information contained in it. The proposed approach gives better visual quality of compressed images with well-preserved edges and reduced artifacts. The proposed pairFuzzy algorithm provides substantial improvement in the visual quality of compressed image as compared with the state-of-art techniques [7, 27] as shown in Figs. 8, 9, 10, and 11 and their quantitative results are also reported in Tables 2, 3, 4 and 5 with well-defined parameters.

The rest of paper is organized as follows: Sect. 2 gives literature review of image compression and edge detection alongwith review of artifact reduction methods. Section 3 and its subsections explain the proposed method in detail. Section 4 provide results and discussions and finally the conclusions are drawn in Sect. 5.

2 Literature review

Image compression means reduction of irrelevant information with the aim to reduce space and thereby transmission time. These techniques may either be classified as either lossless or lossy [35]. In lossless compression techniques, an image can be compressed and decompressed without any loss of information. These techniques are widely used in medical imaging, computer aided design, video containing text etc. The standard formats using lossless compression techniques are portable network graphics (PNG), graphics interchange format (GIF), tagged image file format [TIFF (lossless)]. In lossy compression techniques, an image is compressed by permanently discarding some redundant information and therefore the uncompressed image is not exactly the same as the original image, but is similar, in sense, that the change is not perceived by human eye. Lossy image compression techniques are used in video conferencing, mobile applications, and natural images over web etc. The standard file format using lossy image compression technique is JPEG, etc. Lossy compression techniques can provide high compression ratio as compared to lossless compression techniques. Lossy image compression techniques generally introduce artifacts when the image is compressed at low bit rate [38, 39].

According to human visual system for depth perception of an image [34], edges play an important role in image processing and computer vision. Edges contain important structural information [5, 17] and their detection forms a basis for representing an image from pixel level to feature level. Literature shows various works on edge detection based image compression. Horn et al. [6] proposed an edge based compression scheme by extracting edge and mean information for very low bit rate applications. Avramovic [2] presents a lossless image compression algorithm that uses edge information for eliminating spatial redundancy. This algorithm is based on gradient edge detection predictor that strongly depends on prediction, entropy coding and context modeling. Markus et al. [23, 24] proposed edge detection based image compression algorithm for cartoon-like images. This algorithm exploits the information that is present on both sides of edges extracted using Marr-Hildreth operator for compressing these images. In past few years, many edge detection image compression algorithm using fuzzy logic have been developed that are more robust and flexible compared to the classical approaches. Amarunnishad et al. [1] proposed a fuzzy based block truncation coding algorithm using the Yager involutive fuzzy complement edge operator (YIFCEO). The method uses fuzzy logical bit block (LBB) for encoding the input image along with block mean and the standard deviation. Gambhir et al. [9] proposed image compression algorithm that detects edge pixels based on entropy optimized fuzzy edge detector and uses adaptive quantization based compression and decompression. Petrosino et al. [29] proposed an image compression algorithm based on the rough fuzzy sets that depend on fuzzy vector quantization (FVQ) to determine optimal code vectors. The decoder proposed uses specific properties of rough fuzzy sets to reconstruct the original image blocks.

However, compressing an image at low bit rate introduces blocking artifact that seriously degrades the visual quality of the image [15, 31]. Gambhir et al. [10] proposed artifact reduction of DCT compressed images using the values obtained from fuzzy s-shaped membership function that obtains the edge class of pixel from the Gaussian fuzzy edge detector. Zou et. al [41] proposed a projection onto convex sets (POCS) based blocking artifact reduction algorithm by considering the intensity variation across and along the edges. The algorithm uses two convex sets, a smoothness constraint set and a narrow quantization constraint set. Luo et al. [22] proposed a method of reducing blocking artifact of block based DCT compressed images which performs artifact reduction in transform domain as well as in spatial domain. The method takes advantage of the continuity provided by original pixels belonging to the same block and also the correlation between the neighboring blocks to reduce the pixel discontinuity along the boundaries. Kim et al. [14] proposed a signal adaptive weighted sum (SAWS) technique to reduce the blocking artifact obtained in highly compressed images. The technique is based on adaptively adjusting the weights based on correlation as well as on the activities across the boundaries. Gambhir et al. [11] proposed dualFuzzy algorithm that classifies each input image block into either smooth block or edge block using histogram based fuzzy edge classifier. At the encoder, smooth image blocks are encoded to its mean value and the edge block are compressed using fuzzy transform. At the decoder, the reconstructed image obtained using the mean value and the decompression using inverse fuzzy transform, contains artifact that are reduced using Gaussian block based enhancement scheme, whereas this paper classifies each input image block into either LV, MV and HV using competitive fuzzy edge detector, compresses and decompresses each classified block using improved fuzzy transform and uses fuzzy switched median filter for reducing blocking artifacts.

Fig. 1
figure 1

Proposed method

3 Proposed method

The proposed pairFuzzy method follow three steps: (1) preprocessing based on competitive fuzzy edge detection, (2) compression and decompression using improved fuzzy transform, and (3) postprocessing using fuzzy switched median filter based artifact reduction. Figure 1 shows the block diagram for proposed pairFuzzy method and the subsections below describe each step in detail:

3.1 Preprocessing using competitive fuzzy edge detection (CFED)

In this step, CFED assigns each input pixel to one of the six classes depending on its neighborhood. These classes are then classified into LV, MV and HV blocks depending on the number of edge pixels contained in them.

Fig. 2
figure 2

Competitive fuzzy edge detection (CFED)

CFED can speedily detect edge pixels effectively because it uses different fuzzy membership functions based on neighborhood situation for different directions and hence is used for segmenting the blocks. CFED accepts input either in the form of feature vectors based on fuzzy set membership functions or vectors belonging to various classes based upon fuzzy memberships. Each input vector is assigned a class depending upon the max/min fuzzy membership function. The competitive fuzzy edge detector proposed by Liang and Looney [16] first detect the edge pixels and then apply competitive rules for thinning the edges. Figure 2 shows the flow diagram for competitive fuzzy edge detection.

3.1.1 4D Feature vector

A four-dimensional (4D) feature vector defined such as \(V=\{v_1, v_2, v_3, v_4\}\) and is computed for each pixel in an input image, by summing the gray level magnitude difference of the pixels in the four directions (shown in Fig. 3) on \(3 \times 3\) neighborhood about the center pixel. The bidirectional sum magnitudes differences (\(v_1, v_2,v_3, v_4\)) along the four directions (diagonal \(D_1\), diagonal \(D_2\), horizontal \(H\) and vertical \(V\)) for a pixel \(x(i,j)\) are obtained respectively as:

$$\begin{aligned} v_1&=|x(i,j)-x(i+1,j-1)|+|x(i,j)-x(i-1,j+1)|\\ v_2&=|x(i,j)-x(i-1,j-1)|+|x(i,j)-x(i+1,j+1)|\\ v_3&=|x(i,j)-x(i,j-1)|+|x(i,j)-x(i,j+1)|\\ v_4&=|x(i,j)-x(i-1,j)|+|x(i,j)-x(i+1,j)| \end{aligned}$$
(1)
Fig. 3
figure 3

Edge directions for a pixel at (i,j)

3.1.2 Edge classification

The competitive fuzzy classifier distinguishes pixels into six classes: class 0 (smooth class), class 1–4 (edge classes) and class 5 (sure edge class) depending upon its neighborhood situations. The smooth class is assigned to a pixel that has low magnitude intensity differences along all the four directions in its neighborhood. A sure edge class is assigned to a pixel that has high magnitude of pixel intensity differences along all the directions in its neighborhood. Class 1 is assigned to a pixel that has low magnitude intensity difference along diagonal D2 and high magnitude differences along remaining directions. Class 2 is assigned to a pixel that has low magnitude intensity difference along vertical \(V\) and high magnitude differences along remaining directions. Class 3 is assigned to a pixel that has low magnitude intensity difference along diagonal \(D1\) and high magnitude differences along remaining directions. Class 4 is assigned to a pixel that has low magnitude intensity difference along horizontal \(H\) and high magnitude differences along remaining directions. Pixels with feature vector not satisfying any of the above six conditions are assigned to one of the edge class for further processing. Once a feature vector for each pixel has been determined six-4D prototype vectors \(C_i,\; i = 0\) to \(5\), are constructed to represent the respective center of six classes i.e. a smooth class, four-edge classes and a sure edge class. These centers are assigned a value ‘low’ to represent low sum magnitude difference and a value ‘high’ to represent high sum magnitude difference in the given direction.

Competitive rules are then applied to each edge pixel according to class assigned to it. Only the pixels classified as edge pixels and sure edge pixels are assigned the value high (representing white pixels) in the output image and all the other pixels are assigned low in the output image (representing black pixels). This result in white edges on black background. The fuzzy set membership functions for six-classes based on 4D feature vector (V) and 4D prototype vector (C) are obtained using extended Epanechnikov function as:

$$\begin{aligned} \mu _i (v) = Max\left\{ 0,\left( 1-\frac{|v-c_i|^2}{W^2 }\right) \right\} \end{aligned}$$
(2)

where \(i = 0\) represents the smooth class, \(i = 1,2,3,4\) represents edge class, \(i = 5\) represent the sure edge class, and \(W\) defines the width of these fuzzy set membership functions. Membership functions based on uniform, triangular, Epanechnikov kernels can be used, however, Epanechnikov function is optimal in mean square error sense and hence is preferred [20].

Fig. 4
figure 4

Results of various edge detection algorithms for Lenna and Graffiti. a Sobel edge, b Prewitt edge, c Canny edge, d CFED, e Sobel edge, f Prewitt edge, g Canny edge, h CFED

3.1.3 Fuzzy rule firing and defuzzification

Before classifying an edge pixel to either white or black, it is compared to neighborhood edge pixels. After classifying edge pixel to an edge class, it is compared with the pixel on either side of it and the pixel with the largest absolute difference is stored as white (edge) pixel and the others are saved as black (smooth) pixel thereby thinning the edges. The rules for this competition are given below:

  1. 1.

    Rule 1: If \(x\) belongs to smooth class (class 0), then change pixel to black.

  2. 2.

    Rule 2: If \(x\) belongs to edge class 1, compare \(v_1\) with its neighboring pixels along the diagonal \(D_2\). If \(v_1\) is large then change pixel value to white else black.

  3. 3.

    Rule 3: If \(x\) belongs to edge class 2, compare \(v_3\) with its neighboring pixels along the horizontal \(H\). If it is large then change pixel to white else black.

  4. 4.

    Rule 4: If \(x\) belongs to edge class 3, compare \(v_2\) with its neighboring pixels along the diagonal \(D_1\). If it is large then change pixel to white else black.

  5. 5.

    Rule 5: If \(x\) belongs to edge class 4, compare \(v_4\) with its neighboring pixels along the vertical \(V\). If it is large then change pixel to white else black.

  6. 6.

    Rule 6: If \(x\) belong to sure edge class (class 5), then change pixel to white.

The competitive fuzzy edge detection method classifies the pixel either as a edge class or as a smooth class using the competitive rules and yielded white lines on black background which are neither thick nor noisy as yielded by threshold based Prewitt or Sobel operator. The method yielded thin black lines even for the diffused edge as well as even when the required parameters are adjusted roughly by the user (magnitude intensity difference nearly equal to 3–10 is assigned low and between 30 to 40 is assigned high [16]). The use of six fuzzy set membership functions help in the speedy detection of edges in all the directions. The parameters of competitive fuzzy edge detector for producing desirable results could be selected in very less number of trials as compared to Canny edge detector [4] that required many number of trials with different combination of parameters before arriving at final set of parameters. Also Canny edge detector sometimes connect lines into closed contour thereby misinterpreting the edges whereas competitive fuzzy edge detector is free from this drawback. The results of various edge detection algorithms for Lenna and Graffiti are shown in Fig. 4.

The competitive fuzzy edge detector can efficiently detect edges in the image block. These image blocks are then classified into LV, MV and HV block depending upon number of edge pixels contained in them. On extensively experimenting CFED on different standard images and real time images, it is concluded that treating blocks with less than 20 % of edge pixels as LV block, between 20 and 70 % of edge pixels as MV block and rest as HV block yields an optimum quality of compressed image at low bit rate.

3.2 Compression and decompression using improved fuzzy transform

Fuzzy transform based image compression and decompression have been proposed in [7, 8] and compared with fuzzy relation equations (FEQ) and JPEG. Fuzzy transform gives better results than FEQ and but results obtained using Fuzzy transform are similar or slightly less than JPEG based compression. Thus an attempt is made to provide an algorithm that performs better than JPEG and fuzzy transform. In the proposed algorithm, the improved fuzzy transform treats each of the LV, MV and HV blocks differently for compression. These blocks are compressed to different size blocks thereby maintaining an average value of compression rate and performing better than JPEG at similar compression rates. Figure 5 shows proposed fuzzy edge detection based improved fuzzy transform compression.

3.2.1 Fuzzy transform

A fuzzy transform converts a continuous function on the closed interval \([a,b]\) into a set of \(N\)-dimensional vector. The inverse fuzzy transform converts this \(N\)-dimensional vector into a continuous function which approximates the original function up to a small quantity \(\epsilon\). Fuzzy transform has an advantage of producing a simple and unique representation of an original function which if used in place of original function makes complex computations easier.

Fuzzy partition of the universe: Consider a closed interval \([a,b]\) as a universe consisting of \(n\) fixed nodes \((n \ge 2) \; x_1 \le x_2 \le x_3 \cdots \le x_n\), such that \(x_1 = a\) and \(x_n = b\). The fuzzy sets \([A_1, A_2,\ldots A_n]\) identified with their membership functions \([A_1(x), A_2(x),\ldots A_n(x)]\) defined on \([a,b]\) forms the fuzzy partition of the universe, if the following conditions are satisfied for \(k = 1,2,3\ldots n\).

  1. 1.

    \(A_k : [a,b] \rightarrow [0,1]\), and \(A_k(x_k) = 1\).

  2. 2.

    \(A_k(x) = 0\) if \(x \notin (x_{k-1},x_{k+1})\).

  3. 3.

    \(A_k(x)\) is a continuous function on the domain \([a,b]\).

  4. 4.

    \(A_k(x)\) monotonically increases on \([x_{k-1},x_k]\) and monotonically decreases on \([x_k,x_{k+1}]\).

  5. 5.

    For all \(x,\sum _{k=1}^{n}A_k (x)=1\). If the set of points \(x_1, x_2, x_3 \ldots x_n\) for \(n\ge 3\) are equidistant, i.e. \(x_k = x_1 + \Delta (k-1)\), where \(\Delta = \frac{(x_n-x_1)}{(n-1)}\) for \(n\ge 2\) then \([A_1, A_2, \ldots A_n]\) forms a uniform fuzzy partition, if the following two additional conditions are satisfied.

    1. (a)

      \(A_k(x_k-x) = A_k(x_k+x)\), for all \(x\) and \(k = 2,\ldots n-1 (n\ge 2)\).

    2. (b)

      \(A_{k+1}(x) = A_k(x-\Delta )\), for all \(x\) and \(k = 2,\ldots n-1 (n\ge 2)\).

For a uniform fuzzy partition, \(\Delta\) is the length of support of \(A_1(x)\) and \(A_n(x)\) whereas, \(2\Delta\) is the support of other fuzzy functions, \(A_k(x)\) for \(k = 2,\ldots n-1\).

3.2.2 Discrete fuzzy transform and its inverse for one variable

Let the original function \(f(x)\), be known only at some nodes, \(x_1, x_2, x_3 \ldots x_N \in [a,b]\) which are sufficiently dense with respect to fixed partition i.e. for every \(i = 1,2,3\ldots N\), there exist an index \(j \in \{1,2,\ldots n\}\) such that \(A_i(x_j) \ge 0\). Then the \(n\)-tuple \(F = [F_1, F_2, F_3 \ldots F_N]\) is defined as the discrete fuzzy transform of \(f(x)\) with respect to \([A_1, A_2, A_3 \ldots A_N]\), if

$$\begin{aligned} F_i= \frac{\sum _{j=1}^{n}f(x_j)A_i (x_j)}{\sum _{j=1}^{n}A_i (x_j)} \end{aligned}$$
(3)

for \(i= 1,2 ,3\ldots N\).

Fig. 5
figure 5

Proposed fuzzy edge detection based improved fuzzy transform compression

It is clear from Eq. 3 that the components of the discrete fuzzy transform i.e. \(F_i\) are the weighted mean values of the given function, where the weights are given by membership functions.

The inverse discrete fuzzy transform \(f_{FN} (x_j)\) of \(F\) with respect to \(\{A_1, A_2, A_3, \ldots A_N\}\) such that it approximately reconstructs the original function \(f(x)\) and is defined as:

$$\begin{aligned} f_{FN} (x_j ) = \sum _{i=1}^{N}F_i A_i (x_j) \end{aligned}$$
(4)

The inverse discrete fuzzy transform \(f_{FN}(x)\) can approximate the original function, \(f(x)\) over a set of points \(x = \{x_1, x_2, x_3\ldots x_N\} \in [a,b]\) if,

$$\begin{aligned} |f(x_j )-f_{FN}(x_j)| < \epsilon \end{aligned}$$
(5)

for \(j = 1,2,3\ldots N\), where \(\epsilon\) is very small positive quantity and \(0<\epsilon <1\).

Fig. 6
figure 6

Fuzzy membership function

3.2.3 Discrete fuzzy transform and its inverse for two variables

Consider a two dimensional (2D) function, \(f(x,y)\) on closed interval \([a,b] \times [c,d]\) as a universe consisting of \((N+M)\) fixed nodes (where \(N,M \ge 2\)), \(x_1, x_2, x_3,\ldots x_N\), such that \(x_1=a\) and \(x_N=b\), be the N number of fixed nodes on \([a,b]\) and \(y_1, y_2, y_3,\ldots y_M\) such that \(y_1=c\) and \(y_M=d\) be the M number of fixed nodes on \([c,d]\). Let \([A_1, A_2, A_3, \ldots A_N]\) and \([B_1, B_2, B_3,\ldots B_M]\) be the fuzzy partition of \([a,b]\) and \([c,d]\) respectively and \([A_1(x), A_2(x),\ldots A_N(x)]\) and \([B_1(y), B_2(y),\ldots B_M(y)]\) be the membership functions of the related fuzzy partition such that \(A_i(x)> 0\) for \([i=1,2,3,\ldots N]\) and \(B_j(y)>0\) for \([j=1,2,3\ldots M]\). Moreover these nodes are sufficiently dense with respect to the chosen partitions i.e for \(i=1, 2, 3 \ldots N\) there exists an index \(k = 1,2,3\ldots n\) such that \(A_i(x_k) > 0\) and for each \(j = 1,2,3\ldots M\) there exists an index \(l=1,2,3\ldots m\) such that \(B_j(y_l)> 0\). The 2D discrete fuzzy transform of the function \(f(x,y)\), with respect to \([A_1, A_2,\ldots A_N]\) and \([B_1, B_2,\ldots B_M]\) is defined as:

$$\begin{aligned} F_{k,l}=\frac{\sum _{j=1}^{m}\sum _{i=1}^{n}f(x_i,y_j)A_k (x_i)B_l (y_j)}{\sum _{j=1}^{m}\sum _{i=1}^{n}A_k (x_i)B_l (y_j)} \end{aligned}$$
(6)

for \(k=1,2,3,\ldots N\) and \(l=1,2,3,\ldots M\). And the discrete inverse discrete fuzzy transform of \(F\) with respect to \(\{A_1, A_2,\ldots A_N\}\) and \(\{B_1, B_2, \ldots B_M\}\) is defined as:

$$\begin{aligned} f_{FN}(x_i,y_j )= \sum _{k=1}^{N}\sum _{l=1}^{M}F_{k,l} A_k (x_j)B_l (y_j) \end{aligned}$$
(7)

for \(i = 1,2,3 \ldots n\) and \(j = 1,2,3,\ldots m\).

The inverse discrete fuzzy transform \(f_{FN}(x,y)\) can be approximates the original function, f(x,y) over the set of points \(x=\{x_1, x_2, x_3 \ldots x_N\}\) and \(y = \{y_1, y_2, y_3, \ldots y_M\}\) which are used to be made sufficiently dense with respect to \(\{A_1, A_2, A_3, \ldots A_N\}\) and \(\{B_1, B_2, B_3, \ldots B_M\}\), if

$$\begin{aligned} |f(x_i,y_j) - f_{FN}(x_i,y_j)|<\epsilon \end{aligned}$$
(8)

for \(i = 1,2,3,\ldots n\) and \(j=1,2,3,\ldots m\). Perfilieva and Martino [7, 27] proposes, a method of lossy image compression and its reconstruction based on discrete fuzzy transform.

Fig. 7
figure 7

Proposed fuzzy switched median filter based artifact reduction algorithm

Fig. 8
figure 8

Lenna test image. a Lenna original, b edge image, c JPEG, d fuzzy transform, e fuzzy transform with ARFSM, f pairFuzzy

3.3 Postprocessing [artifact reduction with fuzzy switched median filter (ARFSM)]

The reconstructed image obtained by applying improved inverse fuzzy transform on compressed image may contain artifacts at the boundary of the blocks. Liu et al. [18] proposed a DCT-domain algorithm for blind measurement of blocking artifacts and reduced them by using a DCT based post filtering method. Kim et al. [14] proposed signal adaptive weighted sum filter for reducing blocking artifacts, these were reduced by assigning weights higher to the pixels that are nearer to the boundary than those that are away from the boundary. These weights are assigned according to the correlation and activity in the neighborhood. Jagroop et al. [31] reduced the artifacts in block based DCT compressed images using signal adaptive filter. Researches have considered pixels at the boundary of the block as the noisy pixels and reduces them using filtering action. Thus this paper proposes fuzzy switched median filter for reducing the blocking artifacts. Since fuzzy switched median filter is more robust than the mean filter and also it does not create unrealistic pixels value when it processes an edge. For this reason, median filter is preferred for reducing the artifact and preserving edges.

Artifacts can be successfully reduced by using a square filtering window \(W_{(2M+1)\times (2M+1)}\) (\(M\): an even integer) with \((2M+1)\) rows and \((2M+1)\) columns centered at pixel \(x(i,j)\), positioned at \(i,j\). The filtering operation is required only at the boundary of the adjacent blocks and the pixel under artifact is replaced by a corrected pixel value obtained using fuzzy switched median filter [32, 33]. When the window is placed on the right (left) boundary of the image, then the neighboring pixels on its left (right) side are assumed to be free from any artifact. The value of the corrected pixel is calculated based on the median value of pixels under the square filtering window (W).

Fig. 9
figure 9

Peppers test image. a Peppers original, b edge image, c JPEG, d fuzzy transform, e fuzzy transform with ARFSM, f pairFuzzy

$$\begin{aligned} Med(i,j) = Median\{x(i+k,j+l)\} \end{aligned}$$
(9)

for \(k,l = -M\) to \(+M\).

After computing the median value, the fuzzy input variable \(D(i,j)\) that provides local information in \((2M+1)\times (2M+1)\) window is calculated as maximum of absolute difference between intensities of pixel \(i,j\) with its neighboring pixels.

$$\begin{aligned} D(i,j)=Max\{|x(i+k,j+l)-x(i,j)|\} \end{aligned}$$
(10)

where \(x_{i+k,j+l} \ne x_{i,j}\).

The switched median filter uses the fuzzy variable \(D(i,j)\) for reducing the blocking artifacts from the decompressed image, by defining the fuzzy membership function \(\mu (i,j)\) (shown in Fig. 6) as:

  1. 1.

    Pixels with value of \(D(i,j)\) between \(0\) and \(TH1\) are most likely to be non-edge pixels and hence treated as noise free pixels with zero membership value and requires no correction for reducing artifacts.

  2. 2.

    Pixels with value of \(D(i,j)\) between \(TH1\) and \(TH2\) are most likely to be edge pixels and hence treated as noisy pixels with membership value between \(0\) and \(1\) and requires some correction on the basis of their membership for reducing artifacts.

  3. 3.

    Pixels with value of \(D(i,j)\) greater than \(TH2\) are sure edge pixels and hence has membership value equal to \(1\) and needs to be corrected for reducing artifact.

$$\begin{aligned} \mu (i,j) = \left\{ \begin{array}{ll} 0 &\quad for\; D(i,j) \le TH1\\ mD(i,j)+c &\quad TH1 < D(i,j) < TH2\\ 1 &\quad D(i,j) \ge TH2\\ \end{array} \right\} \end{aligned}$$
(11)

Where \(m\) is

$$\begin{aligned} m= \frac{1}{(TH2-TH1)} \end{aligned}$$

and \(c\) is

$$\begin{aligned} c= \frac{(-TH1)}{(TH2-TH1)} \end{aligned}.$$

Finally, artifact reduced resultant image is obtained by replacing the current pixel \(x(i,j)\) with a corrected pixel \(y(i,j)\), defined as:

$$\begin{aligned} y(i,j)=[(1- \mu (i,j))] x(i,j)+ \mu (i,\,j) Med(i,j) \end{aligned}$$
(12)

The corrected pixel is a linear fuzzy weighted combination of the original pixel \(x(i,j)\) and the median value \(Med(i,j)\) for the block. Extensive experiments show that ARFSM is successful in producing a high quality of compressed image with very negligible artifact if the two thresholds \(TH1\) and \(TH2\) are in the range of \(5 < TH1 < 15\) and \(25 < TH2 < 35\) for a gray scale image having number of levels \(L = 256\) and these value of thresholds agrees with those stated in [32]. Figure 7 shows flow diagram for the proposed fuzzy switched median filter based artifact reduction technique.

The proposed work is summarized as: The pairFuzzy algorithm preprocesses an image using CFED and then compresses it using improved fuzzy transform. The sensitivity of the proposed algorithm lies in the edge detection algorithm. If too many edge pixels are detected then the images are compressed less by the proposed algorithm and achieves low compression ratio whereas, too less detected edge pixels results in heavy compression of image, achieving high compression ratio but loss of information. Canny edge detector with its best sensitivity [16] for Lena image is achieved with Threshold \((T) = 0.2\) and standard deviation \((\sigma ) = 0.5\) whereas, competitive fuzzy edge detector with \({\text{low }}= 0\), \({\text{high}} = 20\) and width (W) \(= 256\). However Canny edge detector detects some spurious edges (shown in Fig. 4c, region A) and even misses some of the edges (shown in Fig. 4c, region B) that affect the performance of the proposed algorithm in terms of image quality and compression ratio. The fuzzy transform based image compression proposed by Perfilieva and Martino [7, 27] compressed all blocks of an image into same dimensions, whereas the authors improve fuzzy transform by reducing all blocks of an image into different dimensions depending upon the number of edges contained in them. The proposed pairFuzzy uses the idea such that each block of the image is to be compressed is classified to either low variation (LV) block or medium variation (MV) block or high variation (HV) block based upon competitive fuzzy edge detection. A block with large number of edge pixels is termed as HV, with very small number of edge pixels is termed as LV and remaining as MV. These blocks are the compressed using improved fuzzy transform. Since HV block contains more edge information hence it is compressed less as compared to LV block. For example: a \(8\times 8\) LV block is compressed to \(3\times 3\) block, \(8\times 8\) MV block is compressed to \(5\times 5\) block and \(8\times 8\) HV block is compressed to \(7\times 7\) block. The improved inverse fuzzy transform of these compressed blocks then results in the compressed image. The compressed image contain blocking artifacts. To reduce these artifacts, the proposed pairFuzzy algorithm uses fuzzy switched median filter scheme. This scheme uses the property that pixels at the block boundary are uncorrelated with pixels around the center of the blocks, hence treated as the noisy pixels and improvement of these pixels is achieved using linear combination of fuzzy weighted pixel value and its median value.

Fig. 10
figure 10

House test image. a House original, b Edge image, c JPEG, d Fuzzy transform, e Fuzzy transform with ARFSM, f pairFuzzy

Fig. 11
figure 11

Graffiti test image from the database of Oxford University, UK [12]. a Graffiti original, b edge image, c JPEG, d fuzzy transform, e fuzzy transform with ARFSM, f pairFuzzy

4 Results and discussions

To evaluate the performance of the proposed pairFuzzy algorithm, it has been applied to a variety of test images of size \(256\times 256\) as well as to images of size \(512\times 512\). Test images on which experiment is performed include general test images and images taken from Oxford University, UK [12]. For compression, the images are initially divided into blocks, the total number of \(8\times 8\) size blocks for \(256\times 256\) size image is \(\frac{(256\times 256)}{(8\times 8)}=1024\) and for \(512\times 512\) size image is \(\frac{(512\times 512)}{(8\times 8)}=4096\). Table 1 shows the number of low variation (LV) blocks, medium variation (MV) blocks and high variation (HV) blocks for both size of images. Experimentally it has been found that block containing less than 20 % of edge pixels should be treated as LV block, between 20 and 70 % of edge pixels as MV block and rest as HV block. Fuzzy switched median filter for artifact reduction has also been applied to reduce the artifact present in compressed images obtained using fuzzy transform based image compression. The proposed algorithm is also analyzed using both objective and subjective measures and the results obtained are compared with those obtained using JPEG, fuzzy transform and fuzzy transform with ARFSM. Figures 8, 9, 10, and 11 shows the subjective comparison of the above said algorithms on the various test images. These figures show the original image (Figs. 8, 9, 10, 11a), edge image obtained using competitive fuzzy edge detector (Figs. 8, 9, 10, 11b), compressed images obtained using JPEG (Figs. 8, 9, 10, 11c), fuzzy transform (Figs. 8, 9, 10, 11 d), fuzzy transform with ARFSM (Figs. 8, 9, 10, 11e) and pairFuzzy (Figs. 8, 9, 10, 11f) image compression methods. It is observed that the proposed algorithm provides better visual quality than the other methods. JPEG compressed images suffers from huge blocking artifacts that degrades the visual image quality. Fuzzy transform compressed images also exhibit artifacts but smaller than those contained in the JPEG compressed images. ARFSM helps in detection and reduction of these artifacts hence improving the performance of fuzzy transform with ARFSM. Pairfuzzy produces most pleasing results that contains significantly reduced artifacts while simultaneously preserving small details and sharp discontinuities. Figure 12 shows the zoomed upper left corner visual results of JPEG, fuzzy transform and pairFuzzy compression methods for Lenna and Grafiti images. From these results it is observed that compressed image obtained using pairFuzzy method has proper contrast, smooth edges and negligible artifacts as compared to JPEG and Fuzzy transform. The presented image results is at compression of \(\sim\)0.144 bpp (bits per pixel). For objective analysis, widely used statistical parameters such as: peak signal to noise ratio (PSNR), mean square error (MSE), mean structural similarity index measure (MSSIM) [37] and feature similarity index measure (FSIM) [40] are calculated. Peak signal to noise ratio (PSNR) is defined as

$$\begin{aligned} PSNR(X,Y)=10 \; log_{10}\bigg (\frac{L^2}{MSE}\bigg ) \end{aligned}$$
(13)

where \(L\) is the maximum possible value of intensity (for 8 bit image, L \(=\) 255) and mean square error (MSE) [36] is defined as

Fig. 12
figure 12

Zoomed images for comparison. a Zoom Lenna JPEG, b zoom Lenna fuzzy transform, c zoom Lenna pairFuzzy, d zoom Graffiti JPEG, e zoom Graffiti fuzzy transform, f zoom Graffiti pairFuzzy

Table 1 No. of LV, MV and HV blocks for different images
$$\begin{aligned} MSE(X,Y)=\sqrt{\frac{\sum _{i=1}^{N}\sum _{j=1}^{M}[X(i,j)-Y(i,j)]^2}{M\times N}} \end{aligned}$$
(14)
Table 2 Comparison results of different algorithms in terms of MSE
Table 3 Comparison results of different algorithms in terms of PSNR (dB)

where \(M\times N\) is total number of pixels in an image and \(X(i,j)\) and \(Y(i,j)\) are the gray level pixel values of original and reconstructed image respectively.

In general, a compression technique resulting in high PSNR and low MSE is generally considered as a better technique. Tables 2 and 3 indicates that the proposed algorithm outperforms all above said algorithms in terms of PSNR and MSE. Though PSNR and MSE are most commonly used measures as they are easy to calculate and have clear physical meaning but they are not well matched to visual image quality. These measures are based on pixel level calculation and do not take into account the inter-dependencies between pixels and hence not sufficient for evaluating the performance of an algorithm. Since human visual system understands an image mainly according to its low-level features and feature similarity index measure (FSIM) brings image assessment from pixel level to feature level, hence preferred in this paper. In FSIM, phase congruency (PC) measures the significance of local structures and gradient magnitude (GM) takes into account the visual contrast. FSIM however does not consider various visual masking effects. Structural similarity index measure (SSIM) also avoids pixel wise calculation and considers loss of structure in an image, hence provides good approximation of perceived image quality. FSIM and MSSIM are good measures for assessing the quality of image.

Table 4 Comparison results of different algorithms in terms of MSSIM
Table 5 Comparison results of different algorithms in terms of FSIM

Structural similarity index measure (SSIM) measures the structural similarity between the original image and the reconstructed image and is calculated as

$$\begin{aligned} SSIM(X,Y) = \frac{(2\mu _x\mu _y+(K_1 L)^2)(2\sigma _{xy}+(K_2 L)^2)}{(\mu _x^2+\mu _y^2+(K_1 L)^2)(\sigma _x^2+\sigma _y^2+(K_2 L)^2)} \end{aligned}$$
(15)

where \(\mu _x, \mu _y\) and \(\sigma _x, \sigma _y\) are mean intensities and standard deviations for X and Y respectively, \(K_x\) and \(K_y\) are constants such that \(0<K_x,K_y<1\). For image quality assessment, SSIM index is applied locally rather than globally. The local statistics and the SSIM are computed within a square window of size \(m\times m\), which moves from one pixel to another over the whole image. To compute the overall measure of the complete image, a mean structural similarity index measure (MSSIM) is computed as

$$\begin{aligned} MSSIM(X,Y) = \frac{1}{N}\sum _{i=1}^{N}SSIM(x_i,y_i) \end{aligned}$$
(16)

where \(X\) and \(Y\) are the original and reconstructed images respectively, \(x_i\) and \(y_i\) are the contents of image at the \(i\)th local window and \(N\) is the number of local windows in the image. A large value of MSSIM shows its ability to retain the structural similarity of the original image. For two identical images, MSSIM is equal to \(1\).

The feature similarity measure (FSIM) evaluates the similarity between two images by computing locally the combination of the phase congruency (PC) and gradient magnitude (GM) information. PC and GM are complementary to each other and they reflect different aspects of human visual system in assessing the local image quality. PC provides information about local structures in an image whereas GM provides contrast information.

The overall similarity index for grayscale images is defined as

$$\begin{aligned} FSIM(X,Y) = \frac{\sum _{i}^{}\sum _{j}^{} S(i,j) max\left\{ PC_x(i,j),PC_y(i,j)\right\} }{\sum _{i}^{}\sum _{j}^{} max\left\{ PC_x(i,j)PC_y(i,j)\right\} } \end{aligned}$$
(17)

where \(PC_x\) and \(PC_y\) are the local phase congruency values determined for the original image and the reconstructed image respectively, and S(i, j) is the local similarity value determined as

$$\begin{aligned} S(i,j)= & {} \bigg \{\frac{2\cdot PC_x(i,j)\cdot PC_y(i,j) + K_{PC}}{PC_x^2(i,j) + PC_y^2(i,j) + K_{PC}}\bigg \}\nonumber \\&\times \bigg \{\frac{2\cdot GM_x(i,j)\cdot GM_y(i,j) +K_{GM}}{GM_x^2(i,j) + GM_y^2(i,j) + K_{GM}}\bigg \} \end{aligned}$$
(18)

where \(K_{PC}\) and \(K_{GM}\) are small stabilizing constants. The value of \(K_{PC}\) depends on the dynamic range of \(PC\) values. The value of GM can be determined using gradient operators such as the Prewitt operator, the Sobel operator or the Scharr operator. The detailed analysis of the phase congruency measurement is presented in the paper [19]. Tables 4 and 5 show the values of MSSIM and FSIM indices respectively obtained using different algorithms for different images and it is observed that there is significant improvement in these parameters using the proposed algorithm as compared to above-said algorithms. Table 6 shows comparison of PSNR values obtained for various images of size \(256\times 256\) using different artifact reduction methods presented in [14, 22, 41] when applied to improved fuzzy transform.

Figure 13 shows the performance comparison of various algorithms to proposed method in terms of percentage reduction in MSE and percentage gain in PSNR for different test images. It is concluded that the performance of pairFuzzy algorithm has significantly improved over JPEG while compressing both

Fig. 13
figure 13

Performance comparison of various algorithms in terms of percentage reduction in MSE and percentage gain in PSNR. a Percentage reduction in MSE for various test images of sizes 256 × 256, b percentage reduction in MSE for various test images of sizes 512 × 512, c percentage gain in PSNR for various test images of sizes 256 × 256, d percentage gain in PSNR for various test images of sizes 512 × 512

Table 6 PSNR comparison for artifact reduction methods

\(256\times 256\) size image as well as \(512\times 512\) image. It is further concluded that there is significant improvement in the performance of fuzzy transform over JPEG, fuzzy transform with ARFSM over fuzzy transform and in turn pairFuzzy over fuzzy transform with ARFSM.

5 Conclusion

This paper proposes an image compression method named pairFuzzy. The proposed method preprocesses an image using competitive fuzzy edge detector algorithm that results in classification of each image block as either LV, MV and HV. These blocks are then compressed and decompressed using improved fuzzy transform. The reconstructed image may contain the blocking artifacts that are further reduced using fuzzy switched median filter after reconstructing the image. The proposed method is both subjectively and objectively analyzed as well as compared to other methods and found to be superior in terms of quality of the reconstructed image and artifact reduction as compared to JPEG and fuzzy transform algorithm. The proposed method presented in this paper achieves significant improvement in terms of quality of the image and reducing the artifacts but still it needs more improvement. In future, the advantage of neural network alongwith fuzzy transform can be used to develop image compression algorithm at low bit rate.