本文整理汇总了Python中imageio.imread方法的典型用法代码示例。如果您正苦于以下问题:Python imageio.imread方法的具体用法?Python imageio.imread怎么用?Python imageio.imread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imageio
的用法示例。
在下文中一共展示了imageio.imread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getitem__
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def __getitem__(self, index):
cam, seq, frame = self.getLocalIndices(index)
def getImageName(key):
return self.data_folder + '/seq_{:03d}/cam_{:02d}/{}_{:06d}.png'.format(seq, cam, key, frame)
def loadImage(name):
# if not os.path.exists(name):
# raise Exception('Image not available ({})'.format(name))
return np.array(self.transform_in(imageio.imread(name)), dtype='float32')
def loadData(types):
new_dict = {}
for key in types:
if key in ['img_crop','bg_crop']:
new_dict[key] = loadImage(getImageName(key)) #np.array(self.transform_in(imageio.imread(getImageName(key))), dtype='float32')
else:
new_dict[key] = np.array(self.label_dict[key][index], dtype='float32')
return new_dict
return loadData(self.input_types), loadData(self.label_types)
开发者ID:hrhodin,项目名称:UnsupervisedGeometryAwareRepresentationLearning,代码行数:19,代码来源:collected_dataset.py
示例2: main
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def main():
args = parser.parse_args()
spectrogram_im = imread(args.input_file)
algo = {
"gla": gla,
"fgla": fgla
}[args.algorithm]
signal = algo(
spectrogram_im,
args.n_iterations,
stft_kwargs={
"n_fft": args.n_fft,
"hop_length": args.hop_length
},
istft_kwargs={
"hop_length": args.hop_length
},
)
write_wav(args.output_file, signal, args.sample_rate)
示例3: _check_and_load
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def _check_and_load(self, ext, l, f, verbose=True, load=True):
if os.path.isfile(f) and ext.find('reset') < 0:
if load:
if verbose: print('Loading {}...'.format(f))
with open(f, 'rb') as _f: ret = pickle.load(_f)
return ret
else:
return None
else:
if verbose:
if ext.find('reset') >= 0:
print('Making a new binary: {}'.format(f))
else:
print('{} does not exist. Now making binary...'.format(f))
b = [{
'name': os.path.splitext(os.path.basename(_l))[0],
'image': imageio.imread(_l)
} for _l in l]
with open(f, 'wb') as _f: pickle.dump(b, _f)
return b
示例4: _load_file
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def _load_file(self, idx):
idx = self._get_index(idx)
f_hr = self.images_hr[idx]
f_lr = self.images_lr[self.idx_scale][idx]
if self.args.ext.find('bin') >= 0:
filename = f_hr['name']
hr = f_hr['image']
lr = f_lr['image']
else:
filename, _ = os.path.splitext(os.path.basename(f_hr))
if self.args.ext == 'img' or self.benchmark:
hr = imageio.imread(f_hr)
lr = imageio.imread(f_lr)
elif self.args.ext.find('sep') >= 0:
with open(f_hr, 'rb') as _f: hr = pickle.load(_f)[0]['image']
with open(f_lr, 'rb') as _f: lr = pickle.load(_f)[0]['image']
return lr, hr, filename
示例5: load_intrinsics
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def load_intrinsics(self, city, scene_id):
city_name = city.basename()
camera_folder = self.dataset_dir/'camera'/self.split/city_name
camera_file = camera_folder.files('{}_*_{}_camera.json'.format(city_name, scene_id))[0]
frame_id = camera_file.split('_')[1]
frame_path = city/'{}_{}_{}_leftImg8bit.png'.format(city_name, frame_id, scene_id)
with open(camera_file, 'r') as f:
camera = json.load(f)
fx = camera['intrinsic']['fx']
fy = camera['intrinsic']['fy']
u0 = camera['intrinsic']['u0']
v0 = camera['intrinsic']['v0']
intrinsics = np.array([[fx, 0, u0],
[0, fy, v0],
[0, 0, 1]])
img = imread(frame_path)
h,w,_ = img.shape
zoom_y = self.img_height/h
zoom_x = self.img_width/w
intrinsics[0] *= zoom_x
intrinsics[1] *= zoom_y
return intrinsics
示例6: load_omniglot
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def load_omniglot(path):
images = []
for dirname, dirnames, filenames in os.walk(path):
for filename in filenames:
if len(filename) > 4 and filename[-4:] == '.png':
fullname = dirname + '/' + filename
image = imageio.imread(fullname)
image = scipy.misc.imresize(image, (50, 50))
images.append(image)
images = np.stack(images, axis=0)
images = np.expand_dims(images, -1)
images = images.astype(np.float32) / 255.0
np.random.seed(42)
np.random.shuffle(images)
print(np.min(images), np.max(images))
print(images.shape)
return images
示例7: generate_gif
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def generate_gif(self, filenames, gif_filename):
'''create an animated GIF given a list of images
Args:
filenames (list): list of image filenames, ordered in required sequence
gif_filename (str): filepath of final GIF file
Returns:
nothing. Side effect is to save a GIF file at gif_filename
'''
images = []
for filename in filenames:
if os.path.exists(filename):
logging.info("Adding to gif: image " + filename)
images.append(imageio.imread(filename))
logging.info("Creating GIF. This can take some time...")
imageio.mimsave(gif_filename, images)
logging.info("Gif generated at " + gif_filename)
示例8: encode
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [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.')
示例9: make_gif
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def make_gif(self, frame_count_limit=IMAGE_LIMIT, gif_name="mygif.gif", frame_duration=0.4):
"""Make a GIF visualization of view graph."""
self.make_thumbnails(frame_count_limit=frame_count_limit)
file_names = sorted([file_name for file_name in os.listdir(self.thumbnail_path)
if file_name.endswith('thumbnail.png')])
images = []
for file_name in file_names:
images.append(Image.open(self.thumbnail_path + file_name))
destination_filename = self.graph_path + gif_name
iterator = 0
with io.get_writer(destination_filename, mode='I', duration=frame_duration) as writer:
for file_name in file_names:
image = io.imread(self.thumbnail_path + file_name)
writer.append_data(image)
iterator += 1
writer.close()
示例10: high_pass_filter
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def high_pass_filter(input_image, output_image):
I = imread(input_image)
if len(I.shape)==3:
kernel = np.array([[[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]],
[[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]],
[[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]]])
else:
kernel = np.array([[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]])
If = ndimage.convolve(I, kernel)
imsave(output_image, If)
# }}}
# {{{ low_pass_filter()
示例11: low_pass_filter
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def low_pass_filter(input_image, output_image):
I = imread(input_image)
if len(I.shape)==3:
kernel = np.array([[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]],
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]],
[[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]])
else:
kernel = np.array([[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])
kernel = kernel.astype('float32')/9
If = ndimage.convolve(I, kernel)
imsave(output_image, If)
# }}}
# {{{ imgdiff()
示例12: make_gif
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def make_gif(screenshot_dir_path,name = "test_recap",suffix=".gif",duration=2):
"Creates gif of the screenshots"
gif_name = None
images = []
if "/" in name:
name=name.split("/")[-1]
filenames = os.listdir(screenshot_dir_path)
if len(filenames) != 0:
gif_name = os.path.join(screenshot_dir_path, name + suffix)
for files in sorted(filenames):
images.append(imageio.imread(os.path.join(screenshot_dir_path, files)))
imageio.mimwrite(gif_name, images, duration=duration)
return gif_name
示例13: create_gif
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def create_gif(scene, file_name, n_frames=60, size=(600, 600)):
tdir = tempfile.gettempdir()
window.record(scene, az_ang=360.0 / n_frames, n_frames=n_frames,
path_numbering=True, out_path=tdir + '/tgif',
size=size)
angles = []
for i in range(n_frames):
if i < 10:
angle_fname = f"tgif00000{i}.png"
elif i < 100:
angle_fname = f"tgif0000{i}.png"
else:
angle_fname = f"tgif000{i}.png"
angles.append(io.imread(os.path.join(tdir, angle_fname)))
io.mimsave(file_name, angles)
示例14: dynamic_download_and_Synthesizing
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def dynamic_download_and_Synthesizing(illust_id, title=None, prefix=None):
tag = 'Dynamic_Download_And_Synthesizing'
d_json_data = 'https://www.pixiv.net/ajax/illust/' + str(illust_id) + '/ugoira_meta'
d_json_decoded = json.loads(get_text_from_url(d_json_data))['body']
src_zip_url = d_json_decoded['originalSrc']
src_mime_type = d_json_decoded['mime_type']
src_img_delay = int(d_json_decoded['frames'][0]['delay']) / 1000
src_saved_path = save_path + 'TEMP' + global_symbol + str(illust_id) + global_symbol + \
src_zip_url.split('/')[-1]
src_saved_dir = save_path + 'TEMP' + global_symbol + str(illust_id) + global_symbol
src_final_dir = save_path + 'Dynamic' + global_symbol
download_thread(src_zip_url, save_path, None, 'TEMP' + global_symbol + str(illust_id))
while not os.path.exists(src_saved_path + '.done'):
time.sleep(1)
print_with_tag(tag, 'Waiting for complete...')
print_with_tag(tag, ['Zip target downloaded:', src_saved_path])
with zipfile.ZipFile(src_saved_path, 'r') as zip_file:
zip_file.extractall(path=src_saved_dir)
# get each frame
sort_by_num = []
frames = []
for root, dirs, files in os.walk(src_saved_dir):
for file in files:
if file.endswith('jpg') or file.endswith('png'):
sort_by_num.append(src_saved_dir + global_symbol + file)
sort_by_num.sort()
print_with_tag(tag, 'Reading each frame..')
for each_frame in sort_by_num:
frames.append(imageio.imread(each_frame))
gif_save_dir = save_path + str(prefix) + global_symbol + year_month + str(
day) + global_symbol + 'D-' + str(illust_id) + global_symbol
gif_name_format = re.sub('[\/:*?"<>|]', '_', str(title)) + '-' + str(illust_id) + '.gif'
if not os.path.exists(gif_save_dir):
os.makedirs(gif_save_dir)
print_with_tag(tag, 'Synthesizing dynamic images..')
try:
imageio.mimsave(gif_save_dir + gif_name_format, frames, duration=src_img_delay)
except Exception as e:
print_with_tag(tag, [gif_save_dir + gif_name_format])
print_with_tag(tag, e)
exit()
示例15: make_anishot
# 需要导入模块: import imageio [as 别名]
# 或者: from imageio import imread [as 别名]
def make_anishot():
image = Image.fromarray(imageio.imread(ARGS.input.name))
frames = []
if ARGS.zoom_steps:
make_zoomin(image, frames)
make_scroll(image, frames)
imageio.mimwrite(ARGS.output,
map(lambda f: numpy.array(f[0]), frames),
duration=list(map(lambda f: f[1], frames)))