1 1 Introduction
With the rapid advancements in artificial intelligence, researchers have intensively and extensively explored the potential applications of machine learning (ML) [
1–
3] to enhance medical image analysis and optimize the allocation of medical resources [
4–
9]. ML algorithms have been successfully employed in various medical contexts, including the segmentation of pulmonary embolism using computerized tomographic (CT) angiography [
10,
11], breast cancer detection and diagnosis using mammography [
12], and the diagnosis of neurological disorders or brain tumors using magnetic resonance imaging [
13–
16]. Moreover, ML techniques have proved valuable in aiding the diagnosis of COVID-19 patients by identifying ground-glass opacities and consolidations in thoracic CT images [
17–
20], providing physicians with a reliable diagnostic reference. For these tasks, medical image recognition is an essential component, where the analysis of imaging data is paramount in assisting healthcare professionals to identify disorders, enabling early diagnosis and treatment.
Current endeavor of medical image recognition heavily relies on classical ML algorithms such as principal component analysis (PCA) to analyze and interpret complex imaging data. The classical PCA algorithm is computationally expensive, which limits its scalability when a large dataset is dealt with. Consequently, there is a growing interest in exploring quantum alternatives that can potentially overcome these limitations and provide superior performance [
21–
37]. Quantum PCA (qPCA) [
38], the quantum version of the PCA algorithm, offers an exponential speedup compared to its classical counterpart. Despite being proposed as early as in 2014, experimental realization of qPCA has been challenging due to the requirement of a significant number of data copies and implementation of the quantum phase estimation. To date, experimental realizations of qPCA have been achieved through parameterized quantum circuits [
39] and resonant algorithms [
40], both of which lack universality compared to the original qPCA algorithm.
In this work, building upon the original qPCA algorithm proposed by Lloyd
et al. [
38], we demonstrated a hardware-efficient qPCA protocol designed for medical image recognition. Our approach utilized an iterative method customized for the nuclear magnetic resonance (NMR) quantum processor [
41–
46]. Instead of requiring multiple data copies, two copies were recycled indefinitely in our design. To extract the eigenvalues and eigenvectors of the covariance matrix, the quantum scattering circuit with an ancillary qubit was introduced to encode the eigen-information, enhancing the measurement efficiency [
47–
51]. We applied our protocol to perform binary classification on CT images to identify patients affected by COVID. The results revealed that healthy and affected CT images processed by the qPCA protocol can be distinguished accurately in a two-dimensional parameter space, achieving remarkable fidelity of about 90%. Looking ahead, the continued development and optimization of qPCA techniques holds great potential for advancing the field of medical image analysis, enabling more accurate diagnoses and improved treatment strategies.
2 2 Experiment
2.1 2.1 Theoretical background
PCA is a classical ML subroutine widely used for medical image recognition. It facilitates the projection of high-dimensional vectors onto a lower-dimensional space while retaining their maximum discriminatory information, as illustrated in Fig.1(a). In the context of medical examinations, such as CT scans, each resulting image is flattened into a
-dimensional vector that encodes the pixel values, where
represents the number of pixels. Consequently, the dataset consisting of
images can be converted into a
matrix
, where each column encapsulates the pixel information of an individual image. After centralization (see Appendix A), classical PCA solves the eigenvalues of the
covariance matrix
, where the superscript T denotes the transpose operation. This covariance matrix captures the interdependencies among different components of the data, and PCA diagonalizes it as
, where
represents the eigenvector of
corresponding to the eigenvalue
. The eigenvectors associated with the largest eigenvalues are referred to as the principal components, and the dimensionality of the data
can be reduced by projecting it onto the subspace spanned by these principal components; see Fig.1(a). The computational and query complexity of the classical PCA algorithm is
[
22], leading to a quadratic increase in computation time as the dimension
increases.

Fig.1 PCA-based medical image recognition and the corresponding qPCA circuits. (a) Flowchart illustrating the application of PCA for identifying lung CT images. The information of the CT images is encoded in the covariance matrix, which captures the interdependencies among different data components. Classically, principal components are obtained using iterative eigen-algorithms, e.g., power iteration, allowing for dimension reduction by projecting the data onto the subspace spanned by these principal components. (b) Quantum circuit for extracting the eigenvalues of the data matrix . The Hadamard gate prepares the probe qubit in an equal superposition state, while the controlled- gate encodes the eigenvalues of into the phase of the probe qubit. The trial qubits are initialized to an arbitrary pure state that must have non-zero overlaps with the eigenvectors of . (c) Quantum circuit for eigenvectors extraction of . The evolution time is set as , assuming that . The single-qubit gate prepares the probe qubit in . (d) Complete circuit incorporating the realization of the controlled- gate. It requires copies of the data matrix , and the key component is the gate between the trial qubits and each copy, where is the standard swap gate and . |
Full size|PPT slide
QPCA offers a significant advantage over its classical counterpart by substantially reducing computational complexity, scaling as
in both computational and query complexity [
38]. In qPCA, the centralized classical data
is encoded into a quantum state
using
qubits, where
serves as the normalization factor [
52]. This quantum state
can be decomposed in its eigenbasis as
. By performing
combined with the quantum phase estimation algorithm, the eigenvalues
and eigenvectors
can be determined. However, the original qPCA algorithm is faced with significant experimental challenges due to the requirement of multiple copies of
for realizing
and the complex quantum circuits involved in phase estimation. To address this issue, we proposed a hardware-efficient iterative method that enables the execution of
without the need for multiple copies of
. The conventional phase estimation is replaced with a quantum scattering circuit, resulting in a substantial reduction in the number of required qubits.
2.2 2.2 Solving the eigenfunction
Assuming that , scattering quantum circuits for solving the eigenvalues and eigenvectors are shown in Fig.1(b) and (c), respectively. The circuit utilizes one probe qubit and a trial system with the same dimension as . The eigenvalues are first solved using the circuit in Fig.1(b). The probe qubit is prepared to an equal superposition state using a Hadamard gate, and the trial qubits are initialized to an arbitrary pure state . It is worth noting that the coefficients need to be non-zero, which generally holds for generic data. After applying the controlled- gate, the entire system’s final state becomes , where the partial density matrix of the probe qubit is given by
The real part of the off-diagonal elements of the probe qubit, denoted as , carries the information of the eigenvalues in the form of
This quantity can be effectively measured in various physical systems of quantum processors, such as probing the transverse magnetization in NMR. Performing a discrete Fourier analysis on allows for the extraction of all the eigenvalues .
Once the eigenvalues are accurately obtained, the identification of the eigenvectors can be achieved using the quantum circuit shown in Fig.1(c). Without loss of generality, we describe the method for determining the two eigenvectors of a simple density matrix (see Appendix C for the generalization to high-dimensional density matrices). Compared to Fig.1(b), the probe qubit in this circuit requires a preloaded phase , specifically , where assuming that . In addition, the evolution time of the controlled- gate is set to as well. For a generic trial state , the final state of the entire system becomes after implementing the circuit. As a result, the eigenvectors and can be determined from the corresponding subspace of the probe qubit. Please see Appendix C for the generalization to the cases of multiple eigenvalues.
The key ingredient of implementing the aforementioned quantum circuits lies in the realization of
for an unknown density matrix
. In the original qPCA algorithm [see Fig.1(d)] [
38],
copies of
are available, and repeated applications of
are performed between the trial state
and each copy of
(which is subsequently discarded). Here,
represents the swap operator, and
needs to be sufficiently small to maintain the Trotter−Suzuki approximation. This technique can be viewed as a continuous sequence of infinitesimal swap operations between
and
. Ultimately, the trial qubits evolve to the state
which is equivalent to the construction of . It should be noted that all the aforementioned operations are actually controlled gates conditional on the state of the probe qubit.
After performing the eigen-decomposition, the remaining steps of qPCA closely resemble its classical counterpart. The principal components obtained from the eigen-decomposition are utilized to compress the high-dimensional data into a lower-dimensional subspace for subsequent applications [see Electronic Supplementary Materials (ESM)]. However, the original qPCA algorithm requires a significant number of copies of the density matrix, which poses substantial challenges in terms of qubit resources, making the scheme nearly impractical to implement on state-of-the-art quantum processors. To overcome this limitation, we have developed a hardware-efficient approach that allows for the reset and recycling of discarded copies, enabling their reuse in multiple rounds. In the following sections, we will describe this approach in detail, along with the experimental hardware setup.
2.3 2.3 Experimental setup
We validate the effectiveness of the qPCA protocol by applying it to the identification of lung CT scans from COVID-19 patients. COVID-19 infection often leads to lung inflammation and the development of distinct fibrous lesions on CT images, which differentiate them from healthy lung scans. For our experiment, we utilize the iCTFT database, which provides an integrated collection of thoracic CT images and clinical data from patients diagnosed with COVID-19 pneumonia [
53]. The dataset consists of a total of 80 images, with 40 scans from virus-positive patients and 40 scans from virus-negative patients. These scans are divided into a training dataset and a test dataset, serving as the basis for our proof-of-principle experiment. Our qPCA protocol aims to assist in diagnosing pneumonia symptoms and involves three main steps: (i) selecting a training dataset with labeled images (positive or negative), calculating the covariance matrix, and loading it onto the quantum processor; (ii) implementing the qPCA quantum circuit on the quantum processor; and (iii) post-processing the results using the classical PCA algorithm and evaluating the performance using the test dataset.
2.4 2.4 Data loading
We randomly select a training dataset consisting of two CT images: one from a virus-positive patient and the other from a virus-negative patient. Each CT image is discretized into
grayscale pixels, as shown in Fig.2(a). We flatten each image into a column-vector of size
, resulting in a training dataset represented by a
matrix
. Prior to analysis, the dataset is centralized to remove any biases (see Appendix C). To prepare the data for the quantum circuit, we compute the covariance matrix
, which has dimensions
. Implementing this large matrix on a quantum circuit requires an efficient implementation of quantum random access memory [
52], which poses significant experimental challenges. In our work, we employ a dimension-reduction technique by computing a commuted covariance matrix
of dimension
. This reduced matrix can be encoded into a density matrix
up to normalization, and this approach, known as the “eigenface” method, has been successfully applied in face image recognition [
54]. It is a well-established data-processing technique in image classification tasks. More details regarding the data loading process can be found in the Appendix and Supplemental Information.

Fig.2 Data loading and the experimental quantum circuit in the 4-qubit NMR system. (a) Training dataset comprises one positive and one negative CT image from the iCTFT database. Each image is flattened into a vector based on grayscale values, resulting in a training dataset represented by a matrix . After centering the data, instead of the covariance matrix , we compute the commuted covariance matrix and load it into the quantum register, denoted as . (b) Experimental quantum circuit for performing the iterative qPCA algorithm on the 4-qubit NMR quantum processor. We prepare two copies of and implement the controlled- operation in steps, where each step consists of two controlled- gates applied between the trial qubit () and the data qubits ( or ). In each step, the probe and trial qubits are reinitialized to their final state from the previous iteration using single- and two-qubit gates determined by the state of the previous iteration. Gradient-field pulses are applied to destroy instantaneous quantum coherence, serving as non-unitary operations. |
Full size|PPT slide
The experiment was conducted using a NMR system on a Bruker MHz spectrometer. The quantum processor consists of four nuclear spins of in the crotonic acid molecule dissolved in aceton, which serve as the 4-qubit system. The experimental setup is depicted in Fig.2(b). The data matrix to be processed, denoted as , can be encoded into a single qubit. In our 4-qubit processor, the qubits are labeled as to , and each qubit has a specific role. serves as the probe qubit for the scattering quantum circuit [cf. Fig.1(b) and (c)], acts as the trial qubit, initially prepared in the state , while and provide two copies of . Therefore, the 4-qubit system is initialized as follows:
This initialization is performed at the beginning of the experiment [see Fig.2(b)]. For the parameters of the quantum processor and experimental details, see Methods and Supplemental Information.
2.5 2.5 QPCA implementation
As mentioned earlier, the original qPCA algorithm requires a large number of copies of , which is currently beyond the capabilities of state-of-the-art quantum technologies. In this work, we employ an iterative approach to implement the controlled- operation in steps, where each step consists of two controlled- gates applied between the trial qubit () and the data qubits ( or ). In the experiment, the chosen parameters are , , and . It is important to note that, due to the normalization of , the time scale used here may appear large. However, the actual experimental time required to perform the quantum circuit is orders of magnitude shorter. This experimental time is ensured to be much shorter than the relaxation time of the processor. Specifically, the two controlled- gates are implemented using an optimized pulse with a duration of 2 ms, achieving a fidelity of over 0.999. Subsequently, quantum state tomography is performed on the probe and trial qubits to obtain the state of this subsystem.
The iteration process is as follows: After measuring the probe and trial qubits, the entire processor undergoes a resetting operation, consisting of a fast-relaxation technique for less than 2 s [
55] and a subsequent spatial averaging operation [
44,
45,
56–
58] to create the
state. Next, taking the
-th iteration as an example, the probe and trial qubits are reinitialized to their final state from the previous
-th iteration, denoted as
, while the data qubits
and
are reset to
. Since
is generally a mixed state, we apply 1 ms gradient-field pulses to destroy the instantaneous quantum coherence, which are served as non-unitary operations. The forms of the single- and two-qubit gates depend on the information of
, which can be efficiently calculated and experimentally realized in our NMR quantum processor, as described in Methods. Following the reinitialization, the two controlled-
gates are sequentially applied to the entire system. In the absence of decoherence errors, this quantum circuit is equivalent to the original qPCA algorithm but requires fewer copies of
and is hardware-efficient for resetting the system in each iteration. It is important to note that in our experiment, we choose two copies to reduce the total number of iterations. However, the number of copies and iterations can be adjusted based on the hardware characteristics, specifically the tradeoff between the number of controllable qubits and the decoherence time.
In our implementation, the two eigenvalues and of are encoded in the transverse magnetization of the probe qubit, , as shown in Eq. (2). In each iteration, we measure the component of and subsequently apply a discrete Fourier transformation to obtain the experimental results of the two eigenvalues. To determine the eigenvectors, we employ the scheme depicted in Fig.1(c). This circuit differs from the one in Fig.2(b) in the following ways: Firstly, the probe qubit is preloaded with a phase factor , where and and are the experimentally obtained eigenvalues. Secondly, the evolution time of the controlled- gate is set to as well.
2.6 2.6 Experimental results
To validate the effectiveness and stability of the protocol, we perform four groups of experiments, each with a different training dataset and corresponding . In the main text, we present the experimental results from two groups (other groups in ESM), labeled as Group 1 and Group 2. The original training images for these groups are displayed in Fig.3(a) and (d).

Fig.3 Experimental eigenvalues obtained by the hardware-efficient qPCA approach. (a) Training set images for Group 1 experiment. The left and right images are randomly sampled from lung CT images of negative and positive patients, respectively. Clear textures are observed in the healthy lung CT image, while the diseased lung CT image exhibits a hazy shadow. (b) Magnitude of the probe qubit’s component [cf. Eq. (2)] for Group 1 at different time instants. (c) Discrete Fourier analysis of in Group 1. The spectral lines of different colors represent the Fourier analysis of at every 200 iterations. (d−f) Results for Group 2. (g) Two eigenvalues obtained from the Fourier analysis every 50 iterations in Group 1 and Group 2. As the number of iterations increases, the eigenvalues tend to converge towards the theoretical values. (h) Precision of eigenvalue measurement is quantified by the half-widths of the two peaks, denoted as . The values in both groups gradually decrease as the number of iterations increases. |
Full size|PPT slide
In Group 1, we observe the time-dependent transverse magnetization , as depicted in Fig.3(b). It is evident that exhibits oscillations with two distinct frequencies, corresponding to the eigenvalues of , as time progresses. However, the oscillation amplitude gradually decreases due to the decoherence effect in the NMR processor. We perform a discrete Fourier transformation to the first 200, 400, 600, 800, and the complete set of 1000 of experimental , with results plotted in Fig.3(c). We also analyzed the changes of the two eigenvalues every 50 iterations, as shown in Fig.3(g). As the number of iterations increases, the two eigenvalues tend to approach their corresponding theoretical values . Although the estimated eigenvalues at different iteration numbers show minor variations, the peaks corresponding to the eigenvalues become sharper. We quantify the measurement precision using the half-widths of the peaks, denoted as . The results clearly demonstrate that the experimental eigenvalues and closely match their respective theoretical predictions after the iterative qPCA process. Moreover, the uncertainties gradually decrease as the number of iterations increases [see Fig.3(h)].
Once the eigenvalues are obtained, the corresponding eigenvectors can be determined by preparing the probe qubit in the state and modifying the controlled gate to controlled-. Here, s. Compared to the eigenvalue computation ( s), the controlled evolution required for extracting the eigenvectors is significantly shorter, spanning only 65 iterations. The experimental results of the eigenvectors are shown in Fig.4(a). We separately plot the two components of the eigenvectors, and , and compare the experimental results with the theoretical ones using a bar figure. The fidelities of the experimental eigenvectors, and , are 0.9998 and 0.9999, respectively.
Fig.4 Experimental eigenvectors and the iterative process. (a) Experimental results of the eigenvectors for Group 1 (left panel) and Group 2 (right panel). The coefficients of and , represented in the computational basis, are illustrated. Both theoretical (green bars) and experimental (yellow bars) coefficients are shown for comparison, and the fidelities of the experimental eigenvectors exceed 0.9998. (b) Change in state fidelity (probe and trial qubits) as a function of the number of iterations. The fidelity is plotted at every 50 iterations for better visualization, while the solid line represents the fitting result. As a reference, we display the density matrices of the probe and trial qubits at the 200th and 800th iterations, as shown in the insets. |
Full size|PPT slide
To evaluate the performance of the iterative qPCA, we perform state tomography on the probe and trial qubits every 50 iterations in Group 1. The state fidelity, defined as , is computed and plotted against the number of iterations, as shown in Fig.4(b). The fidelity demonstrates a decreasing trend as the number of iterations increases, primarily due to the effects of decoherence and imperfections in the quantum gates during each iteration. These factors contribute to imperfections in the state of the probe and trial qubits, subsequently affecting the fidelity of the next iteration. Nevertheless, the fidelity consistently remains above a high level (), indicating the robustness of the protocol against such errors.
Moving on to Group 2, the experimental eigenvalues and eigenvectors are depicted in Fig.3(d)−(h) and Fig.4(a). Despite the different training dataset used in this group, the experimental results exhibit high precision, further validating the stability and effectiveness of our iterative protocol. It is important to note that the experimental results for the remaining groups can be found in the Electronic Supplementary Materials, providing a comprehensive analysis of the protocol’s performance across multiple datasets.
2.7 2.7 Image classification
After obtaining the two eigenvalues
and corresponding eigenvectors
through the iterative qPCA process, the remaining tasks can be efficiently performed on classical computers. It is shown by Turk
et al. [
54] that
and
are two principal components of the covariance matrix
, which can be referred to as the “eigen-features” of the training dataset. Consequently, we can compress the information of all training images
and test images
(after centralization) into a two-dimensional space spanned by these two principal components. Specifically, we define
and
as 2-dimensional weight vectors, which can be computed with polynomial complexity. To classify a CT image in the test dataset, we use the nearest-neighbor method with distance defined by the 2-norm
. Further details can be found in the Methods and Supplemental Information.
We present a visualization of the two weight vectors and all 80 weight vectors from the test dataset on a 2-dimensional plane in Fig.5. The positive images, as labeled in the iCTFT database, are colored in red, while the negative images are shown in blue. The weight vectors corresponding to the training images are marked with circles, and the decision boundary is represented by a dashed line. The weight vectors associated with the test images are denoted by crosses. It can be observed that most of the test images have been successfully classified using the iterative qPCA process for either Group 1 or Group 2. Among the 78 test CT images included in Group 1, 72 were successfully recognized, leading to an accuracy rate of 92.31%. Conversely, out of the 78 test images in Group 2, 68 were correctly classified, resulting in an achievement rate of 87.17%.
Fig.5 Classification of lung CT images after qPCA. (a) Classification results for Group 1. After performing qPCA, each CT image in the dataset is projected onto a two-dimensional space spanned by the two experimental eigenvectors and . The two training images are denoted by circles, while the test images are represented by crosses. The test dataset consists of 39 virus-negative images (blue) and 39 virus-positive images (red). The decision boundary is depicted by the dashed line. Out of the 78 test images, 72 are correctly identified, resulting in a success rate of 92.31%. (b) Classification results for Group 2. Among the 78 test images, 68 are accurately classified, yielding a success rate of 87.17%. |
Full size|PPT slide
In this case where only two samples were used as the training set, PCA attempts to utilize the available information to capture the overall structure within the dataset. The dissimilarity between the two samples in the training set becomes the primary direction sought by PCA. Consequently, the two samples from the training set will be distributed along the principal component direction in the reduced-dimension space, with a relatively large distance between them, reflecting the differences present in the original data. When applying PCA to the test dataset, the samples within the test dataset are projected according to the principal components learned from the training data. As the test data were not involved in the training process, their projected positions may be closer to each other, as shown in Fig.5. It is important to note that the occurrence of this phenomenon depends on the similarity between the training and test datasets and the data distribution. However, with only two training samples, this phenomenon is more likely due to limited information availability.
3 3 Discussion
There are two issues regarding the experimental qPCA. First, loading the classical data into quantum states is generally difficult. Currently, no efficient method for loading classical data has been realized in any experiment. It is crucial to explore and develop efficient implementations of quantum RAM architectures, such as the “bucket brigade” approach or other alternatives. Despite this limitation, qPCA can still be employed to address problems involving quantum states, such as dimension reduction, process tomography, and state discrimination. Second, the multiple state copies and iterative approach can be combined as demonstrated in this experiment (two copies and 1000 iterations). For a real quantum processor, the number of allowable state copies is limited by the availability of controllable qubits, while the number of iterations is limited by the relaxation time. In most cases, it is necessary to combine these two techniques to perform the qPCA circuit with higher precision.
Classical PCA, a popular tool in many machine learning tasks, suffers from a severe scaling problem when computing the eigenvalues and eigenvectors of the covariance matrix. In this work, instead of using the original qPCA algorithm that requires multiple copies of quantum states and implementation of quantum phase estimations, we proposed a hardware-efficient qPCA approach to circumvent this problem. We demonstrated that a hardware-efficient iterative method could effectively reset the probe and trial qubits in the NMR quantum processor, and the eigenvalues and eigenvectors (principal components) could be efficiently determined using the quantum scattering circuit. As a practical application of PCA, we focused on the classification of lung CT images from COVID-19 patients, and demonstrated high accuracy in classifying these images using the NMR system. Our experiment marks the first implementation of the qPCA algorithm in a modified form and highlights the potential of near-term quantum devices to accelerate quantum machine learning algorithms, which opens up new avenues for practical applications of large-scale quantum computers.
{{custom_sec.title}}
{{custom_sec.title}}
{{custom_sec.content}}