python 从 dict 中保存 image

image_outputs = model(image_inputs) # dict['est', 'gt', 'raw']
image_outputs = image_outputs['est'] # dist 1x1920x1024
image_outputs = image_outputs[0] # tensor 1x1920x1024
image_outputs = image_outputs.to("cpu").numpy().astype(np.uint8)[0] # ndarry 1920x1024
image_outputs = Image.fromarray(image_outputs) # img 1920x1024
image_outputs.save("./imgs_dir/" + str(batch_idx + 1).zfill(4) + ".png") # ./imgs_dir/0001.png
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DNA混沌加密是一种基于混沌理论和DNA序列的加密方式,其主要思想是将明文数据转化为DNA序列,然后通过混沌映射对DNA序列进行加密,最后将加密后的DNA序列转化为密文数据。下面是一个Python实现的DNA混沌加密的例子: ```python import numpy as np import matplotlib.pyplot as plt def logistic_map(x, r): return r * x * (1 - x) def dna_encryption(plaintext, r, mu, n=1000): # 将明文数据转化为DNA序列 dna_dict = {'A': [1, 0, 0], 'T': [0, 1, 0], 'C': [0, 0, 1], 'G': [1, 1, 1]} dna_sequence = [dna_dict[c] for c in plaintext] # 生成混沌序列 x = np.random.rand() chaotic_sequence = [x] for i in range(n-1): x = logistic_map(x, r) chaotic_sequence.append(x) # 对DNA序列进行加密 encrypted_sequence = [] for i in range(len(dna_sequence)): for j in range(3): dna_bit = dna_sequence[i][j] chaotic_bit = int(chaotic_sequence[3*i+j] >= mu) encrypted_bit = (dna_bit + chaotic_bit) % 2 encrypted_sequence.append(encrypted_bit) # 将加密后的DNA序列转化为密文数据 ciphertext = ''.join(['ATCG'[sum(encrypted_sequence[i:i+3])] for i in range(0, len(encrypted_sequence), 3)]) return ciphertext # 测试 plaintext = 'HELLO WORLD' r = 3.8 mu = 0.5 ciphertext = dna_encryption(plaintext, r, mu) print('明文:', plaintext) print('密文:', ciphertext) ``` 保存图像的方法有很多种,下面是一个使用Matplotlib库保存图像的例子: ```python import numpy as np import matplotlib.pyplot as plt # 生成一张随机的灰度图像 image = np.random.rand(256, 256) # 显示图像 plt.imshow(image, cmap='gray') plt.show() # 保存图像 plt.imsave('image.png', image, cmap='gray') ``` 这个例子生成了一张256x256的随机灰度图像,并将其显示在屏幕上,然后使用`imsave`函数保存为PNG格式的图像文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值