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