pub struct QuantumImageEncoder {
pub method: ImageEncodingMethod,
pub num_qubits: usize,
pub encoding_circuits: Vec<Circuit<16>>,
pub parameters: Array1<f64>,
}Expand description
Quantum image encoder
Fields§
§method: ImageEncodingMethodEncoding method
num_qubits: usizeNumber of qubits
encoding_circuits: Vec<Circuit<16>>Encoding circuits
parameters: Array1<f64>Encoding parameters
Implementations§
Source§impl QuantumImageEncoder
impl QuantumImageEncoder
Sourcepub fn new(method: ImageEncodingMethod, num_qubits: usize) -> Result<Self>
pub fn new(method: ImageEncodingMethod, num_qubits: usize) -> Result<Self>
Create new quantum image encoder
Examples found in repository?
examples/computer_vision.rs (line 89)
63fn image_encoding_demo() -> Result<()> {
64 println!(" Testing quantum image encoding methods...");
65
66 let encoding_methods = vec![
67 ("Amplitude Encoding", ImageEncodingMethod::AmplitudeEncoding),
68 (
69 "Angle Encoding",
70 ImageEncodingMethod::AngleEncoding {
71 basis: "y".to_string(),
72 },
73 ),
74 ("FRQI", ImageEncodingMethod::FRQI),
75 ("NEQR", ImageEncodingMethod::NEQR { gray_levels: 256 }),
76 ("QPIE", ImageEncodingMethod::QPIE),
77 (
78 "Hierarchical",
79 ImageEncodingMethod::HierarchicalEncoding { levels: 3 },
80 ),
81 ];
82
83 // Create test image
84 let test_image = create_test_image(1, 3, 64, 64)?;
85
86 for (name, method) in encoding_methods {
87 println!("\n --- {name} ---");
88
89 let encoder = QuantumImageEncoder::new(method, 12)?;
90
91 // Encode image
92 let encoded = encoder.encode(&test_image)?;
93
94 println!(" Original shape: {:?}", test_image.dim());
95 println!(" Encoded shape: {:?}", encoded.dim());
96
97 // Analyze encoding properties
98 let encoding_stats = analyze_encoding(&test_image, &encoded)?;
99 println!(" Encoding statistics:");
100 println!(
101 " - Information retention: {:.2}%",
102 encoding_stats.info_retention * 100.0
103 );
104 println!(
105 " - Compression ratio: {:.2}x",
106 encoding_stats.compression_ratio
107 );
108 println!(
109 " - Quantum advantage: {:.2}x",
110 encoding_stats.quantum_advantage
111 );
112
113 // Check specific properties for each encoding
114 match name {
115 "Amplitude Encoding" => {
116 println!(" ✓ Efficient for low-resolution grayscale images");
117 }
118 "Angle Encoding" => {
119 println!(" ✓ Preserves spatial correlations");
120 }
121 "FRQI" => {
122 println!(" ✓ Flexible representation with position-color encoding");
123 }
124 "NEQR" => {
125 println!(" ✓ Enhanced representation with multi-level gray encoding");
126 }
127 "QPIE" => {
128 println!(" ✓ Probability-based encoding for quantum processing");
129 }
130 "Hierarchical" => {
131 println!(" ✓ Multi-scale encoding for feature hierarchy");
132 }
133 _ => {}
134 }
135 }
136
137 Ok(())
138}Sourcepub fn encode(&self, images: &Array4<f64>) -> Result<Array4<f64>>
pub fn encode(&self, images: &Array4<f64>) -> Result<Array4<f64>>
Encode images to quantum states
Examples found in repository?
examples/computer_vision.rs (line 92)
63fn image_encoding_demo() -> Result<()> {
64 println!(" Testing quantum image encoding methods...");
65
66 let encoding_methods = vec![
67 ("Amplitude Encoding", ImageEncodingMethod::AmplitudeEncoding),
68 (
69 "Angle Encoding",
70 ImageEncodingMethod::AngleEncoding {
71 basis: "y".to_string(),
72 },
73 ),
74 ("FRQI", ImageEncodingMethod::FRQI),
75 ("NEQR", ImageEncodingMethod::NEQR { gray_levels: 256 }),
76 ("QPIE", ImageEncodingMethod::QPIE),
77 (
78 "Hierarchical",
79 ImageEncodingMethod::HierarchicalEncoding { levels: 3 },
80 ),
81 ];
82
83 // Create test image
84 let test_image = create_test_image(1, 3, 64, 64)?;
85
86 for (name, method) in encoding_methods {
87 println!("\n --- {name} ---");
88
89 let encoder = QuantumImageEncoder::new(method, 12)?;
90
91 // Encode image
92 let encoded = encoder.encode(&test_image)?;
93
94 println!(" Original shape: {:?}", test_image.dim());
95 println!(" Encoded shape: {:?}", encoded.dim());
96
97 // Analyze encoding properties
98 let encoding_stats = analyze_encoding(&test_image, &encoded)?;
99 println!(" Encoding statistics:");
100 println!(
101 " - Information retention: {:.2}%",
102 encoding_stats.info_retention * 100.0
103 );
104 println!(
105 " - Compression ratio: {:.2}x",
106 encoding_stats.compression_ratio
107 );
108 println!(
109 " - Quantum advantage: {:.2}x",
110 encoding_stats.quantum_advantage
111 );
112
113 // Check specific properties for each encoding
114 match name {
115 "Amplitude Encoding" => {
116 println!(" ✓ Efficient for low-resolution grayscale images");
117 }
118 "Angle Encoding" => {
119 println!(" ✓ Preserves spatial correlations");
120 }
121 "FRQI" => {
122 println!(" ✓ Flexible representation with position-color encoding");
123 }
124 "NEQR" => {
125 println!(" ✓ Enhanced representation with multi-level gray encoding");
126 }
127 "QPIE" => {
128 println!(" ✓ Probability-based encoding for quantum processing");
129 }
130 "Hierarchical" => {
131 println!(" ✓ Multi-scale encoding for feature hierarchy");
132 }
133 _ => {}
134 }
135 }
136
137 Ok(())
138}Trait Implementations§
Source§impl Clone for QuantumImageEncoder
impl Clone for QuantumImageEncoder
Source§fn clone(&self) -> QuantumImageEncoder
fn clone(&self) -> QuantumImageEncoder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for QuantumImageEncoder
impl !RefUnwindSafe for QuantumImageEncoder
impl Send for QuantumImageEncoder
impl Sync for QuantumImageEncoder
impl Unpin for QuantumImageEncoder
impl !UnwindSafe for QuantumImageEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.