How to increase buffer size while type casting a array in numpy.ndarray?

36 Views Asked by At

I am trying to embed cipher text into a image using dwt. But are some problem occuring while embedding the cipher data.

def embed_ciphertext_into_image(ciphertext, image_path, output_path):
    # Read the image
    image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
    
    # Flatten image into 1D array
    image_flatten = image.flatten()
    
    # Embed ciphertext into image using DWT
    (cA, cD) = pywt.dwt(image_flatten, 'haar')

    cA = ciphertext[:len(cA)]  # Embed ciphertext into approximation coefficients


    mod_cA = np.ndarray(len(cA),np.float64,cA)


    haar_wavelet = pywt.Wavelet('haar')
    modified_image_flatten = pywt.idwt(mod_cA, cD, haar_wavelet)
    
    # Reshape the flattened array back to image shape
    modified_image = modified_image_flatten.reshape(image.shape)
    
    # Save the modified imge with ciphertext embedded
    cv2.imwrite(output_path, modified_image)

Trying to convert the cA to numpy.ndarray(mod_cA) but it is giving an error.

mod_cA = np.ndarray(len(cA),np.float64,cA)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: buffer is too small for requested array
0

There are 0 best solutions below