将numpy
数组转换回图像时,出现以下错误:
ValueError:以10为底的int()的无效文字:
import cv2
import numpy
import matplotlib
from PIL import Image
import elgamal
img = Image.open('C:/Users/hp/Desktop/QuadTree/output.jpg').convert('LA')
img.save('Grayscale.png')
img1 = cv2.imread('Grayscale.png',0)
imgar = numpy.array(img1)
imgStr = numpy.array2string(imgar)
print(img1)
print('Image before Encryption')
keyDict = elgamal.generate_keys()
cipher = elgamal.encrypt(keyDict['publicKey'],imgStr)
print('encrypted value')
print(cipher)
#returns a string
decryptedImgar = elgamal.decrypt(keyDict['privateKey'], cipher)
print('Decrypted value')
print(decryptedImgar)
imgar2 = numpy.array(decryptedImgar)
a = numpy.asarray(imgar2, numpy.uint8)
print(a.shape)
b = abs(numpy.fft.rfft2(a,axes=(0,1)))
b = numpy.uint8(b)
j = Image.fromarray(b)
j.save('img2.png')