Uncategorized

Python: Typeerror:cannot unpack non-iterable numpy.float64 object


I am trying to send coordinate of an image for point addition to another function but in the point_addition function, its unable to unpack the coordinates of point as x1 and y1

I am trying to send coordinate of an image for point addition to another function but in the point_addition function, its unable to unpack the coordinates of point as x1 and y1.
here is the code:

def point_addition(p1, p2, P):
    x1, y1 = p1
    x2, y2 = p2
    
    # Replace with the actual equation of the HEC curve
    h = lambda x: 0  # Replace with the actual polynomial h(x)
    F = lambda x: (x**5 + 1184*x**3 + 1846*x**2 + 956*x + 560) % P
    
    lam = (y2 - y1) / (x2 - x1)
    x3 = (lam**2 - x1 - x2) % P
    y3 = (lam * (x1 - x3) - y1) % P
    
    return (x3, y3)

def encrypt_image(image, P):
    # Phase mask generation and masking process
    phase_mask_1 = np.random.uniform(np.pi, 2*np.pi, size=image.shape[:-1] + (1,))
    masked_image = image * np.exp(1j * phase_mask_1)
    
    # Phase Truncated Fourier Transformation (PTFT)
    ptft_image = np.abs(np.fft.fftshift(np.fft.fft2(masked_image, axes=(0, 1))))
    
    # Scrambling using hyper elliptic curve (HEC)
    scrambled_image = ptft_image.copy()
    
    for i in range(image.shape[0]):
        for j in range(image.shape[1]):
            point_1 = scrambled_image[i, j]
            point_2 = scrambled_image[(i + 1) % image.shape[0], (j + 1) % image.shape[1]]
            image_array = np.array([point_1, point_2], dtype = np.float64)
            scrambled_image[i, j] = point_addition(image_array[0], image_array[1], P)

Error output:

error: In[1], line 73
     70 grayscale_image = np.mean(original_image, axis=-1, dtype=np.uint8)
     72 # Encrypt the grayscale image using hyperelliptic curve
---> 73 encrypted_gray_image = encrypt_image(grayscale_image, P)
     75 # Decrypt the grayscale image using hyperelliptic curve
     76 decrypted_gray_image = decrypt_image(encrypted_gray_image, P)

Cell In[1], line 37, in encrypt_image(image, P)
     35         point_2 = scrambled_image[(i + 1) % image.shape[0], (j + 1) % image.shape[1]]
     36         image_array = np.array([point_1, point_2], dtype = np.float64)
---> 37         scrambled_image[i, j] = point_addition(image_array[0], image_array[1], P)
     39 # Masking and transformation on scrambled image
     40 phase_mask_2 = np.random.uniform(np.pi, 2*np.pi, size=image.shape[:-1] + (1,))

Cell In[1], line 7, in point_addition(p1, p2, P)
      6 def point_addition(p1, p2, P):
----> 7     x1, y1 = p1
      8     x2, y2 = p2
     10     # Replace with the actual equation of the HEC curve

TypeError: cannot unpack non-iterable numpy.float64 object



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *