def _filter_compressed_images(self, raw_images): """ Find all compressed images that do not have a raw image, and remove them! """ raw_images_fn_to_p = {os.path.splitext(os.path.basename(p))[0] for p in raw_images.ps} missing = set() for p in self.compressed_images.ps: if Compressor.filename_without_bpp(p) not in raw_images_fn_to_p: missing.add(p) if missing: print(f'*** Missing {len(missing)} files that are in compressed but not in raw.') self.compressed_images.ps = [p for p in self.compressed_images.ps if p not in missing]
def _compressed_to_raw(compressed_images: Images, raw_images: Images): """ Create mapping compressed_image -> raw_image. Can be many to one! """ raw_images_fn_to_p = {os.path.splitext(os.path.basename(p))[0]: p for p in raw_images.ps} compressed_to_raw_map = {} errors = [] for p in compressed_images.ps: try: fn = Compressor.filename_without_bpp(p) compressed_to_raw_map[os.path.basename(p)] = raw_images_fn_to_p[fn] except KeyError as e: errors.append(e) if len(errors) > 100: break continue if errors: raise ValueError(f'Missing >={len(errors)} keys:', errors[:10], f'\n{len(compressed_images.ps)} vs {len(raw_images.ps)}') return compressed_to_raw_map
def get_filename(self, idx): return Compressor.filename_without_bpp(self.compressed_images.ps[idx])