我正在尝试使用RSA算法对图像进行加密和解密。为此,我需要将图像读取为灰度,然后应用按键并将uint16类型数组保存为png或支持16位数据的任何图像格式。然后,我需要读取16位数据,将其转换为数组并进行解密。现在,以前我尝试将图像另存为.tif并在读取时
img = sk.imread('image.tiff', plugin = 'tifffile')
Run Code Online (Sandbox Code Playgroud)
它将图像视为RGB,这不是我想要的。现在,我想将uint16类型的数组保存到16位png图像中,该图像将采用0到65536之间的值,然后再次将其作为uint16类型的数据读取。我尝试使用以下方式将值保存到16位png文件中
img16 = img.astype(np.uint16)
imgOut = Image.fromarray(img16)
imgOut.save('en.png')
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误: OSError: cannot write mode I;16 as PNG
我也试过了imgOut = Image.fromarray(img16, 'I')
但是这个产量not enough image data
请帮助我将16位数据保存为.png图像。谢谢。