1 Introduction

Digital image processing method is widely used in all kinds of fields, such as face detection and recognition [112], tracking [1316], and biomedical image processing [1719]. Binary image denoising techniques are very important in modern digital image processing. Many denoising algorithms had been proposed, such as information entropy filter [20], optimization of partition-based weighted sum filters [21], nonlocal transform-domain filter [22], based on wavelet filters [2326], and based on independent component analysis and hierarchical fusion hybrid filter [27]. The performance of binary image processing can be affected by the presence of salt and pepper noise [28, 29].

Min and Max filters are two classical denoising methods, which can remove salt and pepper noise, respectively. However, the min and max filters can not be work when both types of noise are included in the binary image. Therefore, many researchers proposed all kinds of median filters and morphological operations-based filters. Median filter is a kind of nonlinear filters, and it has good abilities of keeping edge. But, it requires sorting within the pixel neighbourhood specified by the filter size. The computational burden will increase as the size of the filter increases. According to the structuring element, morphological operations erosion and dilation can be applied to remove either salt or pepper noise. In addition, the combination of erosion and dilation operations can be used to remove noise with salt and pepper both types. In [30], Liu et al. used Laplacian regularization denoising. In [31], Anbarjafari et al. proposed a multi-diagonal matrix filter for binary image denoising. But, the authors only considered a special case. The pixel in the hybrid noisy binary image is replaced with a new value which is the sum of its horizontal and vertical neighbourhood. However, it is not very accurate in terms of Anbarjafari et al. proposed elements of main diagonal is 1 in the multi-diagonal matrix. Therefore, in this paper, an improved method was proposed. The proposed approach is a three-step technique: first, the users need to choose an appropriate lambda value from the set \(\{\lambda |\lambda \in [0.5,1]\}\), and then the hybrid noisy binary image matrix can be obtained by adding the noisy binary image matrix times the \(\lambda \)-MDBM and the transpose of the noisy binary image matrix times the \(\lambda \)-MDBM, and finally the hybrid noisy binary image denoising can be achieved by processing preset threshold.

The remainder of this paper is organized as follows. Section 2 describes the proposed approach in detail. Section 3 reports the experimental results. Section 4 concludes this paper.

2 Lambda multi-diagonal matrix filter

2.1 Concept of lambda multi-diagonal matrix

A lambda \(\xi \)-diagonal matrix is defined to be a symmetric square matrix, \(\psi _{k\times k}(\lambda ,\xi )\), which has the value \(\lambda \) on its main diagonal, the value 1 on its \(\xi \)-diagonals, and 0 on the remaining members [31]. The mathematical formulation can be written as Eq. (1).

$$\begin{aligned}&\psi _{k\times k}(\lambda ,\xi )= {\left\{ \begin{array}{ll} \lambda , &{}\quad i=j\\ 1, &{}\quad |i-j|\le \xi \\ 0, &{}\quad \mathrm{otherwise} \end{array}\right. } \end{aligned}$$
(1)

where \(i,j=1,\ldots ,k, 3\le \xi <k, \xi \) is odd, \(\psi _{k\times k}(\lambda ,\xi )\) denotes a lambda \(\xi \)-diagonal matrix, k denotes the size of square matrix \(\psi _{k\times k}(\lambda ,\xi ), \lambda \) denotes input value by users from the set \(\{\lambda |\lambda \in [0.5,1]\}\), and \(\xi \) denotes the total number of diagonals including the main diagonal, \((\xi -1)/2\) above and \((\xi -1)/2\) below of the main diagonal.

Generally speaking, a lambda \(\xi \)-diagonal matrix can be denoted as follows:

$$\begin{aligned}&\psi _{k\times k}(\lambda ,\xi )= \left( \begin{array}{ccccccccccccccc} \lambda &{}\cdots &{}1 &{}0 &{}\cdots &{}0 &{}\cdots &{}0 &{}\cdots &{}0 &{}0 &{}\cdots &{}0 &{}\cdots &{}0\\ \vdots \\ 0 &{}\cdots &{}0 &{}0 &{}\cdots &{}1 &{}\cdots &{}\lambda &{}\cdots &{}1 &{}0 &{}\cdots &{}0 &{}\cdots &{}0\\ \vdots \\ 0 &{}\cdots &{}0 &{}0 &{}\cdots &{}0 &{}\cdots &{}0 &{}\cdots &{}0 &{}0 &{}\cdots &{}1 &{}\cdots &{}\lambda \end{array}\right) \end{aligned}$$
(2)

where the number of \(\lambda \cdots 1\) is \((\xi +1)/2\), the number of \(1\cdots \lambda \cdots 1\) is \(\xi \), and the number of \(1\cdots \lambda \) is \((\xi +1)/2\). In order to describe the lambda \(\xi \)-diagonal matrix more clearly, we give some examples as below.

Case 1 \(k=7, \xi =3\)

$$\begin{aligned}&\psi _{7\times 7}(\lambda ,3)= \left( \begin{array}{ccccccc} \lambda &{}1 &{}0 &{}0 &{}0 &{}0 &{}0\\ 1 &{}\lambda &{}1 &{}0 &{}0 &{}0 &{}0\\ 0 &{}1 &{}\lambda &{}1 &{}0 &{}0 &{}0\\ 0 &{}0 &{}1 &{}\lambda &{}1 &{}0 &{}0\\ 0 &{}0 &{}0 &{}1 &{}\lambda &{}1 &{}0\\ 0 &{}0 &{}0 &{}0 &{}1 &{}\lambda &{}1\\ 0 &{}0 &{}0 &{}0 &{}0 &{}1 &{}\lambda \end{array}\right) \end{aligned}$$
(3)

Case 2 \(k=7, \xi =5\)

$$\begin{aligned}&\psi _{7\times 7}(\lambda ,5)= \left( \begin{array}{ccccccc} \lambda &{}1 &{}1 &{}0 &{}0 &{}0 &{}0\\ 1 &{}\lambda &{}1 &{}1 &{}0 &{}0 &{}0\\ 1 &{}1 &{}\lambda &{}1 &{}1 &{}0 &{}0\\ 0 &{}1 &{}1 &{}\lambda &{}1 &{}1 &{}0\\ 0 &{}0 &{}1 &{}1 &{}\lambda &{}1 &{}1\\ 0 &{}0 &{}0 &{}1 &{}1 &{}\lambda &{}1\\ 0 &{}0 &{}0 &{}0 &{}1 &{}1 &{}\lambda \end{array}\right) \end{aligned}$$
(4)

Case 3 \(k=8, \xi =3\)

$$\begin{aligned}&\psi _{8\times 8}(\lambda ,3)= \left( \begin{array}{cccccccc} \lambda &{}1 &{}0 &{}0 &{}0 &{}0 &{}0 &{}0\\ 1 &{}\lambda &{}1 &{}0 &{}0 &{}0 &{}0 &{}0\\ 0 &{}1 &{}\lambda &{}1 &{}0 &{}0 &{}0 &{}0\\ 0 &{}0 &{}1 &{}\lambda &{}1 &{}0 &{}0 &{}0\\ 0 &{}0 &{}0 &{}1 &{}\lambda &{}1 &{}0 &{}0\\ 0 &{}0 &{}0 &{}0 &{}1 &{}\lambda &{}1 &{}0\\ 0 &{}0 &{}0 &{}0 &{}0 &{}1 &{}\lambda &{}1\\ 0 &{}0 &{}0 &{}0 &{}0 &{}0 &{}1 &{}\lambda \\ \end{array}\right) \end{aligned}$$
(5)

Case 4 \(k=8, \xi =5\)

$$\begin{aligned}&\psi _{8\times 8}(\lambda ,5)= \left( \begin{array}{cccccccc} \lambda &{}1 &{}1 &{}0 &{}0 &{}0 &{}0 &{}0\\ 1 &{}\lambda &{}1 &{}1 &{}0 &{}0 &{}0 &{}0\\ 1 &{}1 &{}\lambda &{}1 &{}1 &{}0 &{}0 &{}0\\ 0 &{}1 &{}1 &{}\lambda &{}1 &{}1 &{}0 &{}0\\ 0 &{}0 &{}1 &{}1 &{}\lambda &{}1 &{}1 &{}0\\ 0 &{}0 &{}0 &{}1 &{}1 &{}\lambda &{}1 &{}1\\ 0 &{}0 &{}0 &{}0 &{}1 &{}1 &{}\lambda &{}1\\ 0 &{}0 &{}0 &{}0 &{}0 &{}1 &{}1 &{}\lambda \\ \end{array}\right) \end{aligned}$$
(6)

Case 5 \(k=8, \xi =7\)

$$\begin{aligned}&\psi _{8\times 8}(\lambda ,7)= \left( \begin{array}{cccccccc} \lambda &{}1 &{}1 &{}1 &{}0 &{}0 &{}0 &{}0\\ 1 &{}\lambda &{}1 &{}1 &{}1 &{}0 &{}0 &{}0\\ 1 &{}1 &{}\lambda &{}1 &{}1 &{}1 &{}0 &{}0\\ 1 &{}1 &{}1 &{}\lambda &{}1 &{}1 &{}1 &{}0\\ 0 &{}1 &{}1 &{}1 &{}\lambda &{}1 &{}1 &{}1\\ 0 &{}0 &{}1 &{}1 &{}1 &{}\lambda &{}1 &{}1\\ 0 &{}0 &{}0 &{}1 &{}1 &{}1 &{}\lambda &{}1\\ 0 &{}0 &{}0 &{}0 &{}1 &{}1 &{}1 &{}\lambda \\ \end{array}\right) \end{aligned}$$
(7)

2.2 Lambda \(\xi \)-diagonal matrix multiplication based filtering

Let us consider a binary image matrix \(A_{m\times n}\in R^{m\times n}\), and \(\psi _{n\times n}(\lambda ,\xi )\) as follows:

$$\begin{aligned}&A_{m\times n}= \left( \begin{array}{ccccccc} a_{1,1} &{}\cdots &{}a_{1,j-1} &{}a_{1,j} &{}a_{1,j+1} &{}\cdots &{}a_{1,n}\\ \vdots \\ a_{i-1,1} &{}\cdots &{}a_{i-1,j-1} &{}a_{i-1,j} &{}a_{i-1,j+1} &{}\cdots &{}a_{i-1,n}\\ a_{i,1} &{}\cdots &{}a_{i,j-1} &{}a_{i,j} &{}a_{i,j+1} &{}\cdots &{}a_{i,n}\\ a_{i+1,1} &{}\cdots &{}a_{i+1,j-1} &{}a_{i+1,j} &{}a_{i+1,j+1} &{}\cdots &{}a_{i+1,n}\\ \vdots \\ a_{m,1} &{}\cdots &{}a_{m,j-1} &{}a_{m,j} &{}a_{m,j+1} &{}\cdots &{}a_{m,n} \end{array}\right) \end{aligned}$$
(8)
$$\begin{aligned}&\psi _{n\times n}(\lambda ,\xi )= \left( \begin{array}{ccccccccccccccc} \lambda &{}\cdots &{}1 &{}0 &{}\cdots &{}0 &{}\cdots &{}0 &{}\cdots &{}0 &{}0 &{}\cdots &{}0 &{}\cdots &{}0\\ \vdots \\ 0 &{}\cdots &{}0 &{}0 &{}\cdots &{}1 &{}\cdots &{}\lambda &{}\cdots &{}1 &{}0 &{}\cdots &{}0 &{}\cdots &{}0\\ \vdots \\ 0 &{}\cdots &{}0 &{}0 &{}\cdots &{}0 &{}\cdots &{}0 &{}\cdots &{}0 &{}0 &{}\cdots &{}1 &{}\cdots &{}\lambda \end{array}\right) \end{aligned}$$
(9)

To show the proposed approach, we set \(\xi =3\). The result of multiplication of \(A_{m\times n}\) by \(\psi _{n\times n}(\lambda ,3)\) is shown as below:

$$\begin{aligned}&\varOmega _1=A_{m\times n}\psi _{n\times n}(\lambda ,3)= \left( \begin{array}{ccccc} \lambda a_{1,1}+a_{1,2} &{}\cdots &{}a_{1,j-1}+\lambda a_{1,j}+a_{1,j+1} &{}\cdots &{}a_{1,n-1}+\lambda a_{1,n}\\ \vdots \\ \lambda a_{i,1}+a_{i,2} &{}\cdots &{}a_{i,j-1}+\lambda a_{i,j}+a_{i,j+1} &{}\cdots &{}a_{i,n-1}+\lambda a_{i,n}\\ \vdots \\ \lambda a_{m,1}+a_{m,2} &{}\cdots &{}a_{m,j-1}+\lambda a_{m,j}+a_{m,j+1} &{}\cdots &{}a_{m,n-1}+\lambda a_{m,n} \end{array}\right) \end{aligned}$$
(10)

In \(\varOmega _1\), each element of A has been replaced by addition of the pixel with its left and right neighbours in a row. Similarly, the result of multiplication of \(A^{\mathrm{T}}\) by \(\psi _{m\times m}(\lambda ,3)\) can be obtained. Where \(A^{\mathrm{T}}\) denotes the transpose of A.

$$\begin{aligned}&\varOmega _2=A_{m\times n}^{\mathrm{T}}\psi _{m\times m}(\lambda ,3)= \left( \begin{array}{ccccc} \lambda a_{1,1}+a_{2,1} &{}\cdots &{}a_{j-1,1}+\lambda a_{j,1}+a_{j+1,1} &{}\cdots &{}a_{n-1,1}+\lambda a_{n,1}\\ \vdots \\ \lambda a_{1,i}+a_{2,i} &{}\cdots &{}a_{j-1,i}+\lambda a_{j,i}+a_{j+1,i} &{}\cdots &{}a_{n-1,i}+\lambda a_{n,i}\\ \vdots \\ \lambda a_{1,m}+a_{2,n} &{}\cdots &{}a_{j-1,m}+\lambda a_{j,m}+a_{j+1,m} &{}\cdots &{}a_{n-1,m}+\lambda a_{n,m} \end{array}\right) \end{aligned}$$
(11)

Each element of \(\varOmega _2\) is addition of a pixel with its neighbours in a row of \(A^{\mathrm{T}}\). The new matrix \(\varOmega \) can be obtained by adding \(\varOmega _1\) and \(\varOmega _2^{\mathrm{T}}\) as follows:

$$\begin{aligned}&\varOmega =\varOmega _1+\varOmega _2^{\mathrm{T}}= \left( \begin{array}{ccccc} 2\lambda a_{1,1}+a_{1,2}+a_{2,1} &{}\cdots &{}a_{1,j-1}+2\lambda a_{1,j}+a_{2,j}+a_{1,j+1} &{}\cdots &{}a_{1,n-1}+a_{2,n}+2\lambda a_{1,n}\\ \vdots \\ 2\lambda a_{i,1}+a_{i-1,1}+a_{i,2}+a_{i+1,1} &{}\cdots &{}a_{i,j-1}+a_{i-1,j}+2\lambda a_{i,j}+a_{i+1,j}+a_{i,j+1} &{}\cdots &{}a_{i,n-1}+ 2\lambda a_{i,n}+a_{i-1,n}+a_{i+1,n}\\ \vdots \\ 2\lambda a_{m,1}+a_{m-1,1}+a_{m,2} &{}\cdots &{}a_{m,j-1}+2\lambda a_{m,j}+a_{m-1,j}+a_{m,j+1} &{}\cdots &{}a_{m,n-1}+2\lambda a_{m,n}+a_{m-1,n} \end{array}\right) \end{aligned}$$
(12)

From an image point of view, we can regard the matrix as a binary image in terms of Eq. (12). And if \(a_{i,j}\) denotes the pixels of this image, it is not hard to find that the pixel is replaced with a new value which is the sum of its horizontal and vertical neighbourhood. In addition, from the viewpoint of mathematics, the number of pixels in each neighbourhood direction (from above to below and from left to right) is a function of \(\lambda \) and \(\xi \) (viz. \(f(\lambda ,\xi )\)). The optimization problem of \(f(\lambda ,\xi )\) needs to be solved when we want to obtain the original pixels from the noise image. However, it is complicated. According to [31], each pixel of a connected component with 4-connectivity in \(\varOmega \) will accumulate a value less than \(\xi \), if and only if the width and height of the component is less than \(\xi \). Generally speaking, the threshold value can be set \(\xi \). The connected components with sizes less than \(\xi \) will be removed. The mathematical formulation will show how each pixel will be thresholded to generate the final image B, as Eq. (13).

$$\begin{aligned} B= {\left\{ \begin{array}{ll} 1 &{}\quad \varOmega (i,j)\ge \xi \\ 0 &{}\quad \mathrm{otherwise} \end{array}\right. } \end{aligned}$$
(13)

where \(1\le i\le m, 1\le j\le n\). When the \(\lambda \) and \(\xi \) are available, the final de-noised image B can be obtained according to Eq. (13). In [31], there is an important parameter \(\lambda \) has been neglected by Anbarjafari. An example is given to explain this point. If the pixel \(a_{i,j}\) is 0, for \(\lambda \in [0.5,1]\), we have \(a_{i,j-1}+a_{i-1,j}+2a_{i,j}+a_{i+1,j}+a_{i,j+1}=a_{i,j-1}+a_{i-1,j}+2\lambda a_{i,j}+a_{i+1,j}+a_{i,j+1}\) ([31] proposed method). On the contrary, if the pixel \(a_{i,j}\) is 1, we have \(a_{i,j-1}+a_{i-1,j}+2a_{i,j}+a_{i+1,j}+a_{i,j+1}\ge a_{i,j-1}+a_{i-1,j}+2\lambda a_{i,j}+a_{i+1,j}+a_{i,j+1}\). Hence, the parameter \(\lambda \) is very important in Eq. (13). Therefore, the calculation flow of proposed algorithm as shown below.

figure a

3 Experimental results

A binary image with \(10\times 10\) pixels can be used to show the performance of proposed method (Fig. 1). In addition, the circles, text, blobs, testpat1, coins, and rice are shown in Fig. 2 to test the performance with proposed method and many existing approaches. All the experiments are carried out on a PC MATLAB 2010b with 2.40 GHZ CPU, 3GB RAM. The proposed method and mean filter, median filter, morphological filter, and MDMF [31] were evaluated according to PSNR and MSE. The PSNR and MSE are defined as follows:

$$\begin{aligned} \mathrm{PSNR} =10\log _{10}\left( \frac{255^2}{\mathrm{MSE}}\right) \end{aligned}$$
(14)
$$\begin{aligned} \mathrm{MSE} =\frac{\sum _{i=1}^m\sum _{j=1}^n[Z(i,j)-A(i,j)]^2}{m\times n} \end{aligned}$$
(15)

where Z(ij) and A(ij) denote the de-noised image and original image, respectively. As we all know, for the better noise removal performance, the values of MSE should be very small and PSNR should be as high as possible.

Fig. 1
figure 1

a Original binary image, b corrupted image, c the generated intermediate image using Eq. (12) and d filter image using Eq. (13) with \(\lambda =1, \xi =3\)

Fig. 2
figure 2

Original images for the evaluation test: a circles, b text, c blobs, d testpat1, e coins, and f rice

Tables 12 and Fig. 3 show the PSNR, MSE, and graphical illustrations results with different methods, respectively. For convenience, we use MF1, MF2, and MF3 denote the mean filter, median filter, and morphological filter, respectively. From Tables 12 and Fig. 3, we can clearly to see that the proposed method outperforms other existing methods in terms of PSNR and MSE values in most cases. In addition, it must be note that the results are the same with different \(\lambda \). But the results are different when \(\lambda \), that is to say, MDMF method [31]. The main reason is that the result of \(\lambda \) operate is not exceed specified threshold. In other words, the performance of proposed method is stable when \(\lambda \in [0.5,1]\).

Table 1 The comparison of PSNR (dB) using existing and proposed methods, and the best results were marked bold
Table 2 The comparison of MSE using existing and proposed methods, and the best results were marked bold
Fig. 3
figure 3

MSE for different methods with six test images

Figures 45678 and 9 show the visual performance of all the evaluated filters on test images corrupted with noise (10 % density). The results show that the proposed filtering technique clears the noise while preserving the shape information. On the other hand, the median filter clears the noise; however, the shape information of the image is distorted. And the morphological filter using opening followed by closing with \(3\times 3\) disc structuring element, not only loses the shape information but also fails to remove the noise in most cases.

Fig. 4
figure 4

The restoration results of different methods (circles image): a original binary image, b 10 % salt and pepper corrupted image, c MF1, d MF2, e MF3, f MDMF [31], g \(\lambda =0.5\) and h \(\lambda =0.9\)

Fig. 5
figure 5

The restoration results of different methods (text image): a original binary image, b 10 % salt and pepper corrupted image, c MF1, d MF2, e MF3, f MDMF [31], g \(\lambda =0.5\) and h \(\lambda =0.9\)

Fig. 6
figure 6

The restoration results of different methods (blobs image): a original binary image, b 10 % salt and pepper corrupted image, c MF1, d MF2, e MF3, f MDMF [31], g \(\lambda =0.5\) and h \(\lambda =0.9\)

Fig. 7
figure 7

The restoration results of different methods (testpat1 image): a original binary image, b 10 % salt and pepper corrupted image, c MF1, d MF2, e MF3, f MDMF [31], g \(\lambda =0.5\) and h \(\lambda =0.9\)

Fig. 8
figure 8

The restoration results of different methods (coins image): a original binary image, b 10 % salt and pepper corrupted image, c MF1, d MF2, e MF3, f MDMF [31], g \(\lambda =0.5\) and h \(\lambda =0.9\)

Fig. 9
figure 9

The restoration results of different methods (rice image): a original binary image, b 10 % salt and pepper corrupted image, c MF1, d MF2, e MF3, f MDMF [31], g \(\lambda =0.5\) and h \(\lambda =0.9\)

4 Conclusion

In this paper, an effective filtering method was proposed to remove the low-density noise in binary image. This method is an improved model of MDMF method. In other words, this proposed method adds one parameter by user input. This technique is based on the multiplication of \(\lambda \)-MDBM with the noisy binary image followed by thresholding. Experimental results show that the proposed method outperforms some existing methods for binary low-density salt and pepper noise, both in PSNR and MSE.