Python imageio.imread() Examples
The following are 30
code examples of imageio.imread().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
imageio
, or try the search function
.
Example #1
Source File: attacks.py From aletheia with MIT License | 6 votes |
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()
Example #2
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #3
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #4
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #5
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #6
Source File: cityscapes_loader.py From SfmLearner-Pytorch with MIT License | 6 votes |
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
Example #7
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #8
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #9
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #10
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #11
Source File: attacks.py From aletheia with MIT License | 6 votes |
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()
Example #12
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #13
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #14
Source File: cli.py From pygriffinlim with GNU General Public License v3.0 | 6 votes |
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)
Example #15
Source File: models.py From SteganoGAN with MIT License | 6 votes |
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.')
Example #16
Source File: graph_animator.py From lookml-tools with Apache License 2.0 | 6 votes |
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)
Example #17
Source File: collected_dataset.py From UnsupervisedGeometryAwareRepresentationLearning with GNU General Public License v3.0 | 6 votes |
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)
Example #18
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #19
Source File: srdata.py From OISR-PyTorch with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #20
Source File: datasets.py From supair with MIT License | 6 votes |
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
Example #21
Source File: Gif_Maker.py From qxf2-page-object-model with MIT License | 6 votes |
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
Example #22
Source File: visualizer.py From ethshardingpoc with MIT License | 6 votes |
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()
Example #23
Source File: viz.py From pyAFQ with BSD 2-Clause "Simplified" License | 6 votes |
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)
Example #24
Source File: project_multiview_features.py From Pointnet2.ScanNet with MIT License | 5 votes |
def load_depth(file, image_dims): depth_image = imread(file) # preprocess depth_image = resize_crop_image(depth_image, image_dims) depth_image = depth_image.astype(np.float32) / 1000.0 return depth_image
Example #25
Source File: compute_multiview_projection.py From Pointnet2.ScanNet with MIT License | 5 votes |
def load_image(file, image_dims): image = imread(file) # preprocess image = resize_crop_image(image, image_dims) if len(image.shape) == 3: # color image image = np.transpose(image, [2, 0, 1]) # move feature to front image = transforms.Normalize(mean=[0.496342, 0.466664, 0.440796], std=[0.277856, 0.28623, 0.291129])(torch.Tensor(image.astype(np.float32) / 255.0)) elif len(image.shape) == 2: # label image image = np.expand_dims(image, 0) else: raise ValueError return image
Example #26
Source File: __main__.py From anishot with MIT License | 5 votes |
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)))
Example #27
Source File: stegosim.py From aletheia with MIT License | 5 votes |
def lsbm(path, payload): X = imread(path) sign=[1, -1] for j in range(X.shape[0]): for i in range(X.shape[1]): if random.randint(0,99)>int(float(payload)*100): continue if len(X.shape)==2: k=sign[random.randint(0, 1)] if X[i, j]==0: k=1 if X[i, j]==255: k=-1 if X[i, j]%2!=random.randint(0,1): # message X[i, j]+=k else: kr=sign[random.randint(0, 1)] kg=sign[random.randint(0, 1)] kb=sign[random.randint(0, 1)] if X[i, j][0]==0: kr=1 if X[i, j][1]==0: kg=1 if X[i, j][2]==0: kb=1 if X[i, j][0]==255: kr=-1 if X[i, j][1]==255: kg=-1 if X[i, j][2]==255: kb=-1 # message if X[i, j][0]%2==random.randint(0,1): kr=0 if X[i, j][1]%2==random.randint(0,1): kg=0 if X[i, j][2]%2==random.randint(0,1): kb=0 X[i, j]=(X[i,j][0]+kr, X[i,j][1]+kg, X[i,j][2]+kb) return X # }}} # {{{ lsbr()
Example #28
Source File: models.py From SteganoGAN with MIT License | 5 votes |
def decode(self, image): if not os.path.exists(image): raise ValueError('Unable to read %s.' % image) # extract a bit vector image = imread(image, pilmode='RGB') / 255.0 image = torch.FloatTensor(image).permute(2, 1, 0).unsqueeze(0) image = image.to(self.device) image = self.decoder(image).view(-1) > 0 # split and decode messages candidates = Counter() bits = image.data.cpu().numpy().tolist() for candidate in bits_to_bytearray(bits).split(b'\x00\x00\x00\x00'): candidate = bytearray_to_text(bytearray(candidate)) if candidate: candidates[candidate] += 1 # choose most common message if len(candidates) == 0: raise ValueError('Failed to find message.') candidate, count = candidates.most_common(1)[0] return candidate
Example #29
Source File: __init__.py From pyimagevideo with GNU General Public License v3.0 | 5 votes |
def png2tiff(ofn: Path, pat: str, indir: Path = None): """ convert series of PNG, which may not be exactly the same shape, to a multipage TIFF (in the same directory) alternatives: use ImageMagick from command line, or Wand. however, since the files are grouped in a specific weird way, the histfeas program worked best to have this perhaps ImageMagick duplicative functionality in Python/imageio/skimage. """ if resize is None: raise ImportError('pip install scikit-image') ofn = Path(ofn).expanduser() indir = ofn.parent if indir is None else Path(indir).expanduser() # %% convert these sets of images to multipage image flist = sorted(indir.glob(pat)) # yes, sorted() if not flist: raise FileNotFoundError('found no files with {pat} in {ofn}') im0 = imageio.imread(flist[0]) # priming read images = np.empty((len(flist), *im0.shape), dtype=im0.dtype) for i, f in enumerate(flist): im = imageio.imread(f) images[i, ...] = resize(im, im0.shape, mode='edge') # they are all of slightly different shape imageio.mimwrite(ofn, images)
Example #30
Source File: project_multiview_features.py From Pointnet2.ScanNet with MIT License | 5 votes |
def load_image(file, image_dims): image = imread(file) # preprocess image = resize_crop_image(image, image_dims) if len(image.shape) == 3: # color image image = np.transpose(image, [2, 0, 1]) # move feature to front image = transforms.Normalize(mean=[0.496342, 0.466664, 0.440796], std=[0.277856, 0.28623, 0.291129])(torch.Tensor(image.astype(np.float32) / 255.0)) elif len(image.shape) == 2: # label image # image = np.expand_dims(image, 0) pass else: raise return image