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

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<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,