0% found this document useful (0 votes)
2 views

QFT_code

The document contains a Python script that implements the Quantum Fourier Transform (QFT) and applies it to image processing for detecting specific features in images, such as eyes and blood cells. It includes functions for creating the QFT matrix, applying it to quantum states, and detecting edges in images using the Canny edge detection method. The script evaluates the similarity of input images against a comparison image based on summed intensity values and prints whether the images match the expected feature.

Uploaded by

j30dawui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

QFT_code

The document contains a Python script that implements the Quantum Fourier Transform (QFT) and applies it to image processing for detecting specific features in images, such as eyes and blood cells. It includes functions for creating the QFT matrix, applying it to quantum states, and detecting edges in images using the Canny edge detection method. The script evaluates the similarity of input images against a comparison image based on summed intensity values and prints whether the images match the expected feature.

Uploaded by

j30dawui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

UQFT​=N​1​j=0∑N−1​k=0∑N−1​ωjk∣j⟩⟨k∣

# -*- coding: utf-8 -*-


"""
Created on Tue Feb 18 21:14:08 2025

@author: allda
"""
import cv2
import numpy as np
import matplotlib.pyplot as plt

def qft(N):
# Create the QFT matrix for N points
omega = np.exp(2 * np.pi * 1j / N) # N-th root of unity
qft_matrix = np.zeros((N, N), dtype=complex)

for j in range(N):
for k in range(N):
qft_matrix[j, k] = omega ** (j * k) / np.sqrt(N)

return qft_matrix

# Function to apply QFT to a given quantum state (vector or matrix)


def apply_qft(state):
N = len(state) # Number of elements in the state
qft_matrix = qft(N) # Create the QFT matrix
return np.dot(qft_matrix, state) # Apply QFT

pi = np.sqrt(22/7)

def imagedetect(input_files,img_comp,message,weight,bias=500000,margin=1e6):
# Load the image using cv2
img_list=[]
edge_list=[]
pixel_list = []
for img_file in input_files:
img = cv2.imread(img_file, cv2.IMREAD_GRAYSCALE)
edges = cv2.Canny(img, 100, 200)
qftedges = apply_qft(edges)
summed_intensity = np.sum(qftedges)
img_list.append(img)
edge_list.append(edges)
pixel_list.append(summed_intensity)
# print(summed_intensity)

average = np.average(pixel_list)*weight -bias


img_comp_data = cv2.imread(img_comp, cv2.IMREAD_GRAYSCALE)
edges_comp = cv2.Canny(img_comp_data, 100, 200)
intensity_comp = np.sum(edges_comp)
#MSE = (np.average(pixel_list)-intensity_comp)
if abs(average-intensity_comp) > margin:
print(f"Not an {message}")
#if MSE > 1e4:
# print(f"not a {message}")
else:
print(f"Is an {message}")

# print(intensity_comp)
# print(margin)
# print(average)

if __name__ == "__main__":
# print("testing for eye detection")
# input_files = ["eye12345.jpg",'eye2.jpg',"eye3.jpg",'eye4.jpg','eye5.jpg',"Screenshot
2025-02-16 193428.png","Screenshot 2025-02-16 193506.png","Screenshot 2025-02-16
193522.png","Screenshot 2025-02-16 193548.png","Screenshot 2025-02-16
193559.png","Screenshot 2025-02-16 193641.png","Screenshot 2025-02-16 193653.png"]
# img_comp = "eye2.jpg"
# message = "eye"
# margin = 0
# bias=1e5
# imagedetect(input_files, img_comp,message,margin,bias)

########################### Blood cell ######

print("testing for blood cell detection")


input_files =
["bloodsmear.jpg",'bloodsmear2.png',"bloodsmear3.png",'bloodsmear4.png','bloodsmear5.png']
img_comp = "bloodsmear5.png"
message = "blood cell image"
margin = 0-(4*1e6)
imagedetect(input_files, img_comp,message,(1/2)*(2/(3*pi)),margin)

You might also like