### Comparison of imaging efficiency of different ghost imaging algorithms

Figure 1(a,b) show the schematic setup of traditional two-detector GI and computational GI, respectively. In traditional two-detector GI, the illuminating patterns from the source are passive ones which are always random and non-deterministic. In computational GI, the illuminating patterns are computer-generated where deterministic patterns become possible^{9,14,31,32}. By calculating the correlation between the bucket object signals and illuminating patterns, the ghost image can be reconstructed. Reconstruction algorithms and illuminating patterns are two main factors give significant impacts on GI efficiency. Compared with the random patterns, different deterministic patterns (e.g., Hadamard^{33,34,35} and Fourier^{36} patterns) have been proposed and demonstrated their advantages in computational GI configuration with a low sampling ratio due to their characteristic (e.g., orthogonality). Nevertheless, the advantages of deterministic patterns are always accompanied by some limitations (e.g., the inapplicability in passive illumination cases, the size limitation of Hadamard matrix and the order effect of Hadamard patterns^{34,35}), which complicates the pattern effect on GI efficiency. For simplicity and without loss of generality, we here choose random patterns to focus on the study of GI algorithm effect. Eight different GI algorithms are compared below, and their definitions can be found in the Method Section.

Figure 2 shows the reconstructed ghost images with different GI algorithms in simulations. A grayscaled Baboon picture ((101times 101) pixels) acts as the imaging object, as shown in Fig. 2(a). In the simulation, we set (p=50) and (q=1) in HGI algorithm, because a large *p* and a small *q* will largely increase the image visibility and suppress the noise level^{25,26}. For both LGI and EGI algorithms, we set base (A,B=10) and constant (C=1) in the simulation. The measurement number *N* is 10,000 for all algorithms in the simulations. Peak signal-to-noise ratio (PSNR) is applied here to evaluate the image quality below, which is defined as

$$begin{aligned} text{ PSNR }=10text{ log}_{10}left( dfrac{text{ MAX}^2}{text{ MSE }}right) , end{aligned}$$

(1)

where MAX=255 is the maximum possible pixel value of the image. MSE is the mean square error, read by (dfrac{1}{mtimes n}sum _{i,j}left[ T_{re}(x_i,y_j)-T(x_i,y_j)right] ^2 ), where (T_{re}(x_i,y_j)) and (T(x_i,y_j)) are the pixel values of the recovered image and the object, respectively.

Figure 2(b–i) show a comparison of eight different GI algorithms introduced above. Simulation results manifest that GI with DC component and HGI algorithms provide no object information, indicating that neither of them can overcome the Nyquist limit ((N=101times 101)). A little improvement is achieved when one chooses the GI algorithm without DC component or LGI algorithm as shown in Fig. 2(d,e). Although EGI offers a better performance than former four algorithms, it fails to present a clear image structure as DGI and NGI do in Fig. 2(g,h). With a great advantage of the global optimization, CGI in Fig. 2(i) recovers nearly all details of the object image within the Nyquist limit. To clearly demonstrate the recovery efficiency of different GI algorithms, Fig. 3 is plotted with a grayscaled boat picture ((101times 101) pixels) acting as the object. PSNR values show that CGI can recover an image with the quality comparable to the ones of DGI and NGI by performing one order less measurements. Meanwhile, DGI and NGI take an advantage over the EGI, LGI and GI without DC component algorithms. GI with DC component and HGI algorithms conduct the simplest calculations in the imaging process, nevertheless, at the expense of the lowest imaging efficiency.

Because CGI has its unique merit in the imaging reconstruction calculation as demonstrated above, we further apply different (F(Io_i)) in other algorithms to replace the bucket object signal (Io_i) of the CGI as the input, and discuss their imaging efficiency. Figure 2(i–o) show a comparison of CGI with seven different bucket object signal functions (F(Io_i)). One can see that CGI with (F(Io_i)=Io_i) and (F(Io_i)=Io_i-X_ileftlangle {Io} rightrangle /leftlangle Xrightrangle ) take exactly the same PSNR values as shown in Fig. 2(i) and Fig. 2(n). More generally, one can prove that when (F(Io_i)=c_1 Io_i+c_2 X_i) ((c_1) and (c_2) are constant, (c_1ne 0)), CGI calculation will provide the same PSNR value as the one with (F(Io_i)=Io_i), indicating that the bucket reference signal (X_i) brings no effect on the orthogonal matching pursuit method applied in the CGI simulations. Meanwhile, as shown in Fig. 2(o), CGI with (F(Io_i)=Io_i/X_i-leftlangle {Io} rightrangle /leftlangle Xrightrangle ) can also achieve a high imaging efficiency comparable to the DGI and GI with DC cases in Fig. 2(i) and Fig. 2(n). In addition, CGI with bucket object signal of HGI, GI without DC component and LGI, show low recovery efficiencies, but EGI offers a medium imaging quality, as shown in Fig. 2(j–m). In order to quantitatively estimate the efficiency of CGI with different bucket object signal functions, Fig. 4 is plotted. A grayscaled peppers picture ((51times 51) pixels) plays the role of object. As can be seen, CGI with bucket object signal functions of DGI, NGI and GI with DC component always achieve a high imaging efficiency, in comparison to the medium efficiency of CGI (EGI) case and other three low efficiency cases, which is consistent with the results in Fig. 2.

In addition, it should be mentioned that, in the definition of Eq. (3), the DC component of the reference beam is sometimes removed together with the DC component of the object beam^{27,28}, leading Eq. (3) into the expression as (G^{(2)}=(1/N) sum _{i=1}^{N}(Io_{i}-leftlangle Io rightrangle ) (I_{i}(x,y)-leftlangle X rightrangle )). With this definition, the imaging efficiency of GI without DC component algorithm will keep unchanged. However, the efficiency of CGI (GI without DC) case will be improved as high as the one of CGI (GI with DC) case.

### Comparison of error tolerance of different ghost imaging algorithms

To further compare the reconstruction efficiency, the error tolerance of different GI algorithms are discussed below. We here introduce the error by messing up the order *i* of reference signals (or random matrix (M_i^{mtimes n})). In Fig. 5, one can see that CGI (GI with DC) algorithm shows a dramatic decrease as the error ratio increases although it has the highest recovery efficiency with no error. When the error ratio is greater than 10(%), the imaging quality of CGI (GI with DC) is lower than DGI and NGI algorithms. As the error ratio increases more than 30(%), the imaging quality of CGI (GI with DC) becomes comparable to the ones of GI without DC component and LGI algorithms. It implies that a global optimization algorithm is sensitive to the error. More sensitive than the CGI (GI with DC) algorithm, EGI fails to recover the image information even with 5(%) error ratio, as shown in Fig. 5. This might be caused by its divergence reconstruction calculations, that is, the exponential function will largely amplify the input errors. By contrast, all other algorithms exhibit nearly linear decrease as the error ratio increases, as shown in Fig. 5.

Moreover, the error tolerance of CGI algorithm with different bucket object signal function (F(Io_i)) are studied in simulations. In Fig. 6, three cases, i.e., CGI (GI with DC), CGI (DGI) and CGI (NGI), have similar PSNR values when error ratio is 0(%). Nevertheless, the recovery efficiency of CGI (GI with DC) decreases much faster than the other two cases. Interestingly, although both CGI (GI with DC) and EGI are extremely sensitive to the error as discussed in Fig. 5, the combination of them, i.e., CGI (EGI) are more robust than the CGI (GI with DC) case. When the error ratio is greater than 10(%), the imaging quality of CGI (EGI) becomes higher than the CGI (GI with DC) case. The solid and dash lines in Fig. 6 show the DGI and EGI algorithms, respectively. Comparison manifests that both DGI and NGI have better performance than other algorithms except CGI (DGI) and CGI (NGI), when taking the error into consideration. Therefore, CGI (DGI) and CGI (NGI) are two best choices for GI reconstruction whatever error level it is.

### Optical encryption scheme based on the combination of different ghost imaging algorithms

The imaging principle of GI offered an optical encryption scheme^{9}, where the bucket object signals of target information were viewed as the ciphertext and random matrices played the role of keys. Based on this scheme, different optical encryption methods were developed, such as gray-scale and color image encryption^{37}, multiple-image encryption^{38}, metasurface-based encryption^{39}, specific phase masks encryption^{40}, symmetric-asymmetric cryptography^{41}, etc. Different from above methods, we here propose an optical encryption scheme based on the combination of different GI algorithms, where the bucket object signals of GI are re-encoded into different bucket object signal functions as the ciphertext. The combinations of different bucket object signal functions and their relevant parameters (e.g., base value of LGI and EGI) will protect the GI information against the eavesdropper.

The encryption scheme is shown in Fig. 7. Suppose Alice plans to send a baboon picture ((51times 51) pixels) to Bob. By employing the computational GI experimental setup, Alice encodes the picture into a series of numbers (F_1(Io_i)=Io_i). Using the shared dictionary, i.e., the random matrices ({ M^{mtimes n}}), Bob therefore can recover the information by using any GI algorithms, as shown in Fig. 7. Assuming there is an eavesdropper who has stolen the shared dictionary ({ M^{mtimes n}}) together with the number series (F_1(Io_i)=Io_i). Obviously, the eavesdropper can easily decode the information by using the most-efficient algorithm CGI. In order to ensure Bob be able to obtain the picture and simultaneously keep the information safe, a combination of different GI algorithms is a good option. Here, Alice can choose LGI and EGI to improve the security. As shown in Fig. 7, Alice encodes the number series into the form of (F_2(Io_i)=mathrm{{log}}_B (C cdot Io_i/X)). After receiving the message from Alice, Bob can apply (B^{B^{F_2(Io_i)}}) to the CGI algorithm to decode the picture. Without knowing the combination form of (F_2(Io_i)), the eavesdropper is unable to decrypt the information even he (or she) steals all shared dictionary and number series by using the CGI or other reconstruction algorithm, as shown in Fig. 7. Therefore, a combination of different GI algorithms can provide additional security lock to the optical encryption process.