1 Introduction

Nowadays, Radiography Testing (RT) plays an essential rule in many medical and industrial applications. In medicine, RT is used to diagnose different parts of the human body. In industry, RT is used to diagnose the weld quality of the welded components in the pipelines that carry natural gas or oil (Kasban et al. 2011). The most important advantages of the RT include; It is a non-destructive testing, non-invasively, more rapidly, and cheaply. RT uses a radiation source (gamma radiation source or X-rays) to inspect the materials, where, a radiation detector (film, camera, et. al.) captures the image.

Daily, a huge number of radiographic images are collected and, in many cases, there is an essential need for storing the collected images in a database or for transferring these images among different practitioners. The challenge that faces storing or transmission of these images with keeping its high diagnostic quality is the high required capacity of the storage media or the transmission channel. So, efficient compression of these images can be used to overcome this challenge through reducing the amount of data that represent the image and obtaining a compact representation of the image, hence leading to a great storage reduction reducing of the image or transmission requirements. Image compression reduces the number of bits required for representing the image as much as possible with keeping the quality of the reconstructed image as close to the original image as possible. Image compression helps in saving storage space and enables easy sharing of files. Image compression may be lossy or lossless compression, as shown in Table 1 which compares between the two types.

Table 1 Comparison between the lossy and lossless compression

There are many methods can be utilized for image compression, some of these methods depend on mathematical transforms such as; Discrete Cosine Transform (DCT) (Haweel et al. 2016; Almurib et al. 2017; Messaoudi and Srairi 2016), Discrete Wavelet Transforms (DWT) (Bruylants et al. 2015; Vaish et al. 2017), Integer Wavelet Transforms (IWT) (Zhang and Tong 2017), Karhunen Loeve Transforms (KLT) (Zhang et al. 2004), Hartley Transform (Sunder et al. 2006), Watershed Transform (Hsu 2012), Walsh Hadamard transform (Venugopal et al. 2016). Tchebichef Transform (Ernawan et al. 2017; Kiruba and Sumathy 2018; Xiao et al. 2016), and Singular Value Decomposition (SVD) (Kumar and Vaish 2017). The performance of the image compression methods is related to the performance of the mathematical transforms with respect to the energy compaction and the spatial frequency. Vector Quantization (VQ) is considered a powerful method for lossy image compression (Hosseini and Nilchi 2012; Nguyen et al. 2011; Chiranjeevi and Jena 2017; Jiang et al. 2017) because it can use more points where the power density function is higher and it exploits statistical dependence between the vector components. Huffman coding is developed by David Huffman and it is the most common technique for lossless image compression (Dubey and Singh 2012; Anitha 2015; Kasmeera et al. 2016) due to its simplicity and its variable length coding scheme.

The digital radiographic image consists of two main parts; the first part is very important and represents the region that contains the important information in the image and it is called ROI or object area. For example, the image of any part of human body in medical applications or the welded area or any important parts in industrial applications. The other part is less important which represents the image background, sometimes; it contains some useful information such as; image number, image capturing date, etc. Therefore, the radiographic image compression process should be carried out with a maximum possible compression ratio while keeping all the details in the ROI without any information loss because any loss could cause an error in the interpretation of the image. In the image background, it may be overtaking for the loss of some information.

Radiographic image compression is rarely studied by researchers, because of its main challenge as any loss, even in small details could cause wrong interpretation of the image. Few researchers presented some radiographic image compression techniques, especially medical ones. (Zhang et al. 2004) used the DCT, KLT, and DWT for compressing ultrasonic images. (Karimi et al. 2016) analyzed the performance of different multi-stage compression techniques.

This paper proposes a method for digital radiography image compression with maximum compression ratio while keeping all the details in the ROI by separating this region from the image background. The image background is compressed using one stage image pyramid compression followed by lossy vector quantization compression technique with high compression ratio and low quality while the ROI is compressed using the lossless Huffman code with low compression ratio and without any loss of any details. The compressed image obtained by combing the compressed background and the compressed ROI.

The rest of this paper is arranged as follows; Sect. 2 presents the proposed adaptive hierarchical radiographic image compression technique. Section 3 presents the ROI and background separation method. Section 4 presents the image background compression using pyramid compression and vector quantization technique. Section 5 presents the ROI compression using the Huffman encoding. Section 6 presents the image reconstruction method. Section 7 gives the simulation results. Finally, Sect. 8 gives the conclusions remarks.

2 Proposed adaptive radiographic image compression technique

The block diagram of the proposed method is shown in Fig. 1. It consists of two main stages; compression stage as shown in Fig. 1a and decompression stage as shown in Fig. 1b. In the compression stage, the radiographic image is separated into ROI and background. The image background is compressed using one stage image pyramid compression followed by VQ encoding technique while the ROI is compressed using the Huffman encoding. The final compressed image is obtained by combing both the compressed background and the compressed ROI. In decompression stage, the compression steps are reversed by decoding algorithms to obtain the decompressed radiographic image, the steps of the proposed compression technique will present in details in the following subsections.

Fig. 1
figure 1

Block diagram of the proposed radiographic image compression method

3 ROI and background separation

The ROI is separated from the background after determining the ROI. The block diagram of the ROI and background separation is shown in Fig. 2.

Fig. 2
figure 2

Block diagram of the ROI and background separation process

The separation process consists of the following steps:

  1. 1.

    Constructing a variance image from the original image with the same size by moving a small rectangular window across the image as shown in Fig. 3a, b.

  2. 2.

    Thresholding the variance image by an automatic threshold value obtained from the occurrence histogram of the variance image. Where the histogram of the variance image normally contains few peaks, the first peak represents the image background, while the other peaks represent the ROIs in the image. The threshold value is the gray level value that corresponds to the first trough between the first two peaks. The output of variance thresholding is the variance mask as shown in Fig. 3c.

  3. 3.

    Thresholding the variance mask using erosion morphological operation. During this operation, any pixel group smaller than the structuring element size is changed into background pixels. The used structuring element size is determined by calculating the largest of pixel group size represents ROI and dividing the size by 2. This step is important because some radiographic images may contain some information in the background rather than the ROI, so the variance mask it may contain some of this information as shown in Fig. 3d.

  4. 4.

    Locating the dimensions of all ROI in the image to obtain a rectangular mask as shown in Fig. 3e.

  5. 5.

    Adding the rectangular mask to the original radiographic image, the output is the radiographic image with outlined ROI as shown in Fig. 3f.

  6. 6.

    Cutting the ROI from the image based on the rectangular mask dimension, the outputs are the ROI image as shown in Fig. 3g and the background image as shown in Fig. 3h.

Fig. 3
figure 3

Results of the ROI and background separation process steps

4 Image Background Compression

Although the radiographic image background is less important than the ROI, sometimes, it contains some useful information that may help the user. Therefore, radiographic image background could be carried out with a maximum possible compression ratio and with an acceptable loss of some information. In this paper, the radiographic image background compression is carried out using two steps; the first step is performing the pyramid image compression, where the image is hierarchically represented by its levels corresponding to a reduced resolution approximation. The compressed image for the radiographic background image is shown in Fig. 4. The results show than one stage only can be used.

Fig. 4
figure 4

Results of image background compression using pyramid image compression

The second step is the vector quantization compression technique based on GLA method for generating the codebook. VQ based image compression consists of two main stages; encoding and decoding as shown in the block diagram shown in Fig. 5.

Fig. 5
figure 5

Image compression using vector quantization

In encoding stage; firstly, the image is divided into a set of k-dimensional training vectors. Then, clustering these vectors is carried out to obtain the codebook of codewords. After that the encoder takes the vector and returns the index of the code vector with lowest distortion. The compression process is carried out by storing or transmitting the address of the vector rather than the vector itself. In the decoding stage, searching about the code-vector index in the codebook is done for obtaining its corresponding code-vector that is used in image reconstruction.

There are many algorithms can be used for VQ performing such as; Generalized Lloyd Algorithm (GLA) (Linde et al. 1980). Back Propagation Neural Network (BPNN), Fast Back Propagation (FBP) and Equitz Nearest Neighbor (ENN). The basic algorithm is the GLA also called Linde Buzo Gray (LBG) Algorithm. The GLA is the standard method of VQ and it generates the local optimal codebook. Considering the training vector with length N is X = (X1, X2, ….., XN), and the desired number of code vectors is M. The GLA algorithm can be carried out in the following steps:

Generating an initial codebook Y(0) from the average of the entire training sequence.

$$Y\left( 0 \right){\text{ }}={\text{ }}\left\{ {{\text{ }}{Y_1},{\text{ }}{Y_2},{\text{ }} \ldots ,{\text{ }}{Y_M}} \right\}$$
(1)

Searching about the nearest codeword among the ith codeword Y(i) by calculating the Euclidean distances d(X; Y) between the training vector and the codewords as:

$$d({X_i},{Y_i})=\sqrt {\sum\limits_{{j=1}}^{N} ( {X_i} - {Y_{ij}}{)^2}{\text{ }}}$$
(2)

where, Xj is jth component of the training vector, and Yij is jth component of the code-vector Yi.

Calculating the centroid of each cluster in obtaining nearest codebook:

$${C_i}=\frac{1}{m}\sum\limits_{i}^{m} {{X_{ij}}}$$
(3)

where, i is the component of each vector and m is the number of vectors in the cluster.

Calculating the average distortion for the codebook Yi+1, between the training vectors and the codebook is given as:

$$\mathop D\nolimits_{{avg}}^{i} =\frac{1}{{M.k}}\sum\limits_{i}^{M} {\mathop {\left\| {{{\text{X}}_{\text{i}}} - {{\text{C}}_{\text{i}}}} \right\|}\nolimits^{{\text{2}}} }$$
(4)

where, M is the size of training set, k is the size of each vector and ||.|| is a symbol for Euclidean distance.

If possible, converging the average distortion to a dynamic constant value ɛ (threshold value), to obtain codebook the procedure stops.

$$\frac{{{\text{D}}_{{{\text{avg}}}}^{{{\text{i-1}}}} - D_{{avg}}^{i}}}{{{\text{D}}_{{{\text{avg}}}}^{{\text{i}}}}} \leq \varepsilon {\text{ }}$$
(5)

Otherwise, go to Step 3 and the process is repeated until getting the threshold value.

Several researchers presented a lot of schemes for improving the GLA method using different Codebook Search Algorithms (CSAs). (Ra and Kim 1993) presented CSA based on the mean distance ordered. (Wu and Lin 2000) presented fast CSA based on the Cauchy Schwarz inequality. (Pan et al. 2003) presented fast CSA based on sub-vector technique. (Hu and Chang 2003) presented CSA based on integer projection. (Pan et al. 2005) presented fast CSA using the modified L2-norm pyramid. Hu et al. (2008) presented fast CSA by combining the test condition of triangular inequality elimination. (Huang et al. 2009) presented fast CSA based on histogram thresholding. (Wen et al. 2014) presented an improved algorithm FIVQ based on the special optical characteristics. Recently, Karri and Jena (2016) presented CSA based Bat algorithm with automatic zooming features, the results give good Peak Signal-to-Noise Ratio (PSNR) with less computational time due to adjustable pulse emission rate and loudness of bats. Jiang et al. (2012) proposed medical image compression approach based on wavelet transform and vector quantization with variable block size. The results show that the proposed method improved the compression performance.

Although the above improvements achieved good results for the image quality with more complexity, but in our case, we used the GLA standard method of VQ for a codebook generation because it is simple and for background the image quality is not an essential task. Figure 6 shows the results of the image compression after using the GLA VQ compression step.

Fig. 6
figure 6

Results of image background compression using VQ

5 ROI compression

The ROI compression in the radiographic image process must be carried out with a maximum possible compression ratio without affecting on any details or any loss of the information, so that a lossless image compression is carried out using Huffman coding. Performing of Huffman code is simple as shown in the flowchart shown in Fig. 7 (Kaur and Kaur 2013). Firstly, the pixels are sorted by occurrence probabilities in descending order, then merge the two lowest probabilities creating a parent node with a frequency that is the sum of the two lower element’s occurrence probabilities, after that, assigning zero for the left branch and one for the right branch. The process is repeated by merging the two lowest elements until there is only one element left in the list. Finally, this element becomes the root of the binary Huffman tree and used for generating the Huffman code.

Fig. 7
figure 7

Performing Huffman code flowchart

Huffman code is usually utilized in lossless image compression, where it uses the lower number of bits to encode the pixels that occurs more frequently. The codes are stored in the codebook which constructed for each image or for a set of images. The compression process maintains the count of how many times each pixel is occurring so far in the image. Encoding the next pixel, the pixel counts are used as estimates of the occurrence probabilities of the pixels and a table of Huffman codes based on these occurrence probabilities is constructed. The table of Huffman code is used to encode the next pixel. The decoding process is performed by rearranging the same set of pixel occurrence probabilities to from the decompressed image pixels and use the table to reconstruct the same Huffman code table.

Figure 8 shows the results of the ROI compression after using Huffman coding compression.

Fig. 8
figure 8

Results of ROI compression using Huffman coding compression

6 Image reconstruction

The Image reconstruction is carried out in the following steps:

  1. 1.

    Applying the same background ROI described above on the compressed background image.

  2. 2.

    Replace the ROI area with zeros matrix in the resultant background image.

  3. 3.

    Adding the compressed ROI to the resultant image from step 2.

  4. 4.

    Output the compressed image.

  5. 5.

    Applying the same background ROI on the decompressed background image.

  6. 6.

    Replace the ROI area with zeros matrix in the resultant background image.

  7. 7.

    Adding the decompressed ROI to the resultant image from step 6.

  8. 8.

    Output the decompressed image.

Two examples of radiographic images after compression and decompression are shown in Fig. 9.

Fig. 9
figure 9

Radiographic images examples after compression and decompression

7 Experimental results

To evaluate the proposed compression method, the radiographic images database has been collected. The collected database contains welded pipelines images as an industrial application and chest images as a medical application. The industrial radiographic images are 150 welds images including about 150 weld defects for welded pipes obtained using gamma radiography (Zahran et al. 2013). The medical radiographic images are 150 chests images collected from literature and Internet pages.

The performance of the image compression process is normally specified using the compression efficiency which is determined by the compression ratio. Compression Ratio (CR) is the ratio between the compressed image size and the original image size. For quantitative evaluation of the image compression process, two parameters are calculated with different CR. The two parameters are the NCC and the SSIM between the original image and the recovered image after decompressing. The NCC is used for measuring the reliability of the compression process by evaluating the similarity between the original image and the decompressed image, it is defined as (Kasban 2017) [37]:

$$NCC({I_x},{I_y})=\frac{{\sum\nolimits_{i} {\sum\nolimits_{j} {({I_x} - \mu _{x}^{{}})({I_y} - {\mu _y})} } }}{{\sqrt {\sum\nolimits_{i} {\sum\nolimits_{j} {{{({I_x} - {\mu _x})}^2}} } } \sqrt {\sum\nolimits_{i} {\sum\nolimits_{j} {{{({I_y} - {\mu _y})}^2}} } } }}$$
(6)

where Ix and Iy are the original and the decompressed images respectively, while µx and µy represent the mean values of the original and the decompressed images respectively.

The SSIM measures the compression process performance by capturing the similarity between the original and the decompressed images. The images similarities are in luminance, contrast, and structure. The SSIM is defined as (Wang et al. 2004):

$$SSIM({I_x},{I_y})=\frac{{2(2{\mu _x}{\mu _y}+{{({K_s}{L_s})}^2})({\sigma _{xy}}+{{({K_s}{L_s})}^2})}}{{(\mu _{x}^{2}+\mu _{y}^{2}+{{({K_s}{L_s})}^2})(\sigma _{x}^{2}+\sigma _{y}^{2}+2{{({K_s}{L_s})}^2})}}$$
(7)

where σf and σg are the standard deviations of original and the decompressed images respectively. σfg is the correlation coefficient between the original and the decompressed images. Ls is the dynamic range of the pixel values, and Ks is a small constant less than 1 and used for avoiding the instability when µx and µy is very close to zero.

The results of the proposed compression method are evaluated by calculating the NCC and the SSIM between the original image and the recovered image after decompressing with different CRs. These values are calculated for all images in the database and the average is plotted. The same procedure is carried out with compression of the radiographic images without separation using VQ, HC, DCT, and JPEG2000 compression methods. Figures 10 and 11 shows the variation of the SSIM with the CR for the welds images and for the chest images respectively. Figures 12 and 13 shows the variation of the NCC with the CR for the welds images and for the chest images respectively.

Fig. 10
figure 10

The variation of the SSIM with the CR for the welds images

Fig. 11
figure 11

The variation of the SSIM with the CR for the chest images

Fig. 12
figure 12

The variation of the NCC with the CR for the welds images

Fig. 13
figure 13

The variation of the NCC with the CR for the chest images

The results show that the SSIM and the NCC values are decreased by increasing the CR. The upper curve represents the ROI compression gives the highest NCCs and SSIMs values where the information lost between the original and the decompressed images are very small. On the other hand, the lower curve represents the background compression gives the lowest NCCs and SSIMs values where the information lost between the original and the decompressed images are very large. The other curves representing the compression of the whole image without separation using the proposed approach, VQ, HC, DCT, and JPEG2000 compression methods. The different between the weld images results and chest images results because the background in weld images is larger than the background in the chest images. The results proved that, the proposed method is more reliable performance than compression the radiographic image without separation using other compared compression methods.

Furthermore, the proposed compression method has been compared with other published results for a single image to verify the effectiveness of the proposed method. Figure 14 shows the compressed images with a compression ratio of 25% using DCT, JPEG2000, and HC, VQ, VQ in wavelet domain [34] and our proposed method. Table 2 shows the PSNR, SSIM, and NNC values corresponding to these compressed images with respect to the original image.

Fig. 14
figure 14

Compressed images using different compression methods

Table 2 PSNR, SSIM, and NNC values corresponding to the compressed images using different compression methods

The above results showed that the proposed method can be reliable for compression of radiographic images. The proposed method didn’t achieve the highest values of NCC and SSIM because the decreasing in these values may be resulting from using the lossy compression for compressing the background area, this means that the high information loss in the background only while the ROI were compressed using lossless compression for keeping most of the image details in ROI area, especially that contains the important information in the image. The PSNR value of the proposed method is higher than the other comparison methods demonstrating the efficiency of the proposed method.

8 Conclusions and future work

This paper presented a proposed method for radiographic image compression based on separating the radiographic images into ROI and image background. The image background compressed using image pyramid compression followed by VQ based GLA compression algorithm. The ROI is compressed without any details lost using the Huffman coding compression technique. The compressed image is obtained by combing the compressed background and the compressed ROI. The obtained results show that the proposed method gives a better performance than the compressing the whole image without separation using DCT, JPEG2000, HC, and VQ compression in terms of NCC and SSIM for different CRs.

Although the proposed approach achieved good results, there are still some aspects which can be developed in the future to increase the efficiency of the compression process and add more facilities to be suitable for in-site real-time implementation such as doing some image preprocessing and testing the proposed method in cloud storage. Hardware implementation of the proposed method based on Field Programmable Gate Array (FPGA) using Xilinx system generator is the future task in our research project of this point.