pub struct QuantumImageEncoder { /* private fields */ }Expand description
Quantum image encoder
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 78)
52fn image_encoding_demo() -> Result<()> {
53 println!(" Testing quantum image encoding methods...");
54
55 let encoding_methods = vec![
56 ("Amplitude Encoding", ImageEncodingMethod::AmplitudeEncoding),
57 (
58 "Angle Encoding",
59 ImageEncodingMethod::AngleEncoding {
60 basis: "y".to_string(),
61 },
62 ),
63 ("FRQI", ImageEncodingMethod::FRQI),
64 ("NEQR", ImageEncodingMethod::NEQR { gray_levels: 256 }),
65 ("QPIE", ImageEncodingMethod::QPIE),
66 (
67 "Hierarchical",
68 ImageEncodingMethod::HierarchicalEncoding { levels: 3 },
69 ),
70 ];
71
72 // Create test image
73 let test_image = create_test_image(1, 3, 64, 64)?;
74
75 for (name, method) in encoding_methods {
76 println!("\n --- {} ---", name);
77
78 let encoder = QuantumImageEncoder::new(method, 12)?;
79
80 // Encode image
81 let encoded = encoder.encode(&test_image)?;
82
83 println!(" Original shape: {:?}", test_image.dim());
84 println!(" Encoded shape: {:?}", encoded.dim());
85
86 // Analyze encoding properties
87 let encoding_stats = analyze_encoding(&test_image, &encoded)?;
88 println!(" Encoding statistics:");
89 println!(
90 " - Information retention: {:.2}%",
91 encoding_stats.info_retention * 100.0
92 );
93 println!(
94 " - Compression ratio: {:.2}x",
95 encoding_stats.compression_ratio
96 );
97 println!(
98 " - Quantum advantage: {:.2}x",
99 encoding_stats.quantum_advantage
100 );
101
102 // Check specific properties for each encoding
103 match name {
104 "Amplitude Encoding" => {
105 println!(" ✓ Efficient for low-resolution grayscale images");
106 }
107 "Angle Encoding" => {
108 println!(" ✓ Preserves spatial correlations");
109 }
110 "FRQI" => {
111 println!(" ✓ Flexible representation with position-color encoding");
112 }
113 "NEQR" => {
114 println!(" ✓ Enhanced representation with multi-level gray encoding");
115 }
116 "QPIE" => {
117 println!(" ✓ Probability-based encoding for quantum processing");
118 }
119 "Hierarchical" => {
120 println!(" ✓ Multi-scale encoding for feature hierarchy");
121 }
122 _ => {}
123 }
124 }
125
126 Ok(())
127}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 81)
52fn image_encoding_demo() -> Result<()> {
53 println!(" Testing quantum image encoding methods...");
54
55 let encoding_methods = vec![
56 ("Amplitude Encoding", ImageEncodingMethod::AmplitudeEncoding),
57 (
58 "Angle Encoding",
59 ImageEncodingMethod::AngleEncoding {
60 basis: "y".to_string(),
61 },
62 ),
63 ("FRQI", ImageEncodingMethod::FRQI),
64 ("NEQR", ImageEncodingMethod::NEQR { gray_levels: 256 }),
65 ("QPIE", ImageEncodingMethod::QPIE),
66 (
67 "Hierarchical",
68 ImageEncodingMethod::HierarchicalEncoding { levels: 3 },
69 ),
70 ];
71
72 // Create test image
73 let test_image = create_test_image(1, 3, 64, 64)?;
74
75 for (name, method) in encoding_methods {
76 println!("\n --- {} ---", name);
77
78 let encoder = QuantumImageEncoder::new(method, 12)?;
79
80 // Encode image
81 let encoded = encoder.encode(&test_image)?;
82
83 println!(" Original shape: {:?}", test_image.dim());
84 println!(" Encoded shape: {:?}", encoded.dim());
85
86 // Analyze encoding properties
87 let encoding_stats = analyze_encoding(&test_image, &encoded)?;
88 println!(" Encoding statistics:");
89 println!(
90 " - Information retention: {:.2}%",
91 encoding_stats.info_retention * 100.0
92 );
93 println!(
94 " - Compression ratio: {:.2}x",
95 encoding_stats.compression_ratio
96 );
97 println!(
98 " - Quantum advantage: {:.2}x",
99 encoding_stats.quantum_advantage
100 );
101
102 // Check specific properties for each encoding
103 match name {
104 "Amplitude Encoding" => {
105 println!(" ✓ Efficient for low-resolution grayscale images");
106 }
107 "Angle Encoding" => {
108 println!(" ✓ Preserves spatial correlations");
109 }
110 "FRQI" => {
111 println!(" ✓ Flexible representation with position-color encoding");
112 }
113 "NEQR" => {
114 println!(" ✓ Enhanced representation with multi-level gray encoding");
115 }
116 "QPIE" => {
117 println!(" ✓ Probability-based encoding for quantum processing");
118 }
119 "Hierarchical" => {
120 println!(" ✓ Multi-scale encoding for feature hierarchy");
121 }
122 _ => {}
123 }
124 }
125
126 Ok(())
127}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.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.