本文整理汇总了Python中imageio.imwrite方法的典型用法代码示例。如果您正苦于以下问题:Python imageio.imwrite方法的具体用法?Python imageio.imwrite怎么用?Python imageio.imwrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块imageio的用法示例。
在下文中一共展示了imageio.imwrite方法的23个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: save_image
点赞 6
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imwrite [as 别名]
def save_image(data, epoch, image_size, batch_size, output_dir, padding=2):
""" save image """
data = data.asnumpy().transpose((0, 2, 3, 1))
datanp = np.clip(
(data - np.min(data))*(255.0/(np.max(data) - np.min(data))), 0, 255).astype(np.uint8)
x_dim = min(8, batch_size)
y_dim = int(math.ceil(float(batch_size) / x_dim))
height, width = int(image_size + padding), int(image_size + padding)
grid = np.zeros((height * y_dim + 1 + padding // 2, width *
x_dim + 1 + padding // 2, 3), dtype=np.uint8)
k = 0
for y in range(y_dim):
for x in range(x_dim):
if k >= batch_size:
break
start_y = y * height + 1 + padding // 2
end_y = start_y + height - padding
start_x = x * width + 1 + padding // 2
end_x = start_x + width - padding
np.copyto(grid[start_y:end_y, start_x:end_x, :], datanp[k])
k += 1
imageio.imwrite(
'{}/fake_samples_epoch_{}.png'.format(output_dir, epoch), grid)
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:25,
示例2: begin_background
点赞 6
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imwrite [as 别名]
def begin_background(self):
self.queue = Queue()
def bg_target(queue):
while True:
if not queue.empty():
filename, tensor = queue.get()
if filename is None: break
imageio.imwrite(filename, tensor.numpy())
self.process = [
Process(target=bg_target, args=(self.queue,)) \
for _ in range(self.n_processes)
]
for p in self.process: p.start()
开发者ID:HolmesShuan,项目名称:OISR-PyTorch,代码行数:18,
示例3: _generate_samples
点赞 6
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imwrite [as 别名]
def _generate_samples(self, samples_path, cover, epoch):
cover = cover.to(self.device)
generated, payload, decoded = self._encode_decode(cover)
samples = generated.size(0)
for sample in range(samples):
cover_path = os.path.join(samples_path, '{}.cover.png'.format(sample))
sample_name = '{}.generated-{:2d}.png'.format(sample, epoch)
sample_path = os.path.join(samples_path, sample_name)
image = (cover[sample].permute(1, 2, 0).detach().cpu().numpy() + 1.0) / 2.0
imageio.imwrite(cover_path, (255.0 * image).astype('uint8'))
sampled = generated[sample].clamp(-1.0, 1.0).permute(1, 2, 0)
sampled = sampled.detach().cpu().numpy() + 1.0
image = sampled / 2.0
imageio.imwrite(sample_path, (255.0 * image).astype('uint8'))
开发者ID:DAI-Lab,项目名称:SteganoGAN,代码行数:19,
示例4: encode
点赞 6
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imwrite [as 别名]
def encode(self, cover, output, text):
"""Encode an image.
Args:
cover (str): Path to the image to be used as cover.
output (str): Path where the generated image will be saved.
text (str): Message to hide inside the image.
"""
cover = imread(cover, pilmode='RGB') / 127.5 - 1.0
cover = torch.FloatTensor(cover).permute(2, 1, 0).unsqueeze(0)
cover_size = cover.size()
# _, _, height, width = cover.size()
payload = self._make_payload(cover_size[3], cover_size[2], self.data_depth, text)
cover = cover.to(self.device)
payload = payload.to(self.device)
generated = self.encoder(cover, payload)[0].clamp(-1.0, 1.0)
generated = (generated.permute(2, 1, 0).detach().cpu().numpy() + 1.0) * 127.5
imwrite(output, generated.astype('uint8'))
if self.verbose:
print('Encoding completed.')
开发者ID:DAI-Lab,项目名称:SteganoGAN,代码行数:25,
示例5: predict_