QuantumImageEncoder

Struct QuantumImageEncoder 

Source
pub struct QuantumImageEncoder { /* private fields */ }
Expand description

Quantum image encoder

Implementations§

Source§

impl QuantumImageEncoder

Source

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}
Source

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

Source§

fn clone(&self) -> QuantumImageEncoder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QuantumImageEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

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 SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Ungil for T
where T: Send,