MCPcopy Create free account
hub / github.com/computational-imaging/bacon / ImageFile

Class ImageFile

dataio.py:189–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187
188
189class ImageFile(Dataset):
190 def __init__(self, filename, grayscale=False, resolution=None,
191 root_path=None, crop_square=True, url=None):
192
193 super().__init__()
194
195 if not os.path.exists(filename):
196 if url is None:
197 raise FileNotFoundError(
198 errno.ENOENT, os.strerror(errno.ENOENT), filename)
199 else:
200 print('Downloading image file...')
201 os.makedirs(os.path.dirname(filename), exist_ok=True)
202 urllib.request.urlretrieve(url, filename)
203
204 self.img = Image.open(filename)
205 if grayscale:
206 self.img = self.img.convert('L')
207 else:
208 self.img = self.img.convert('RGB')
209
210 self.img_channels = len(self.img.mode)
211 self.resolution = self.img.size
212
213 if crop_square: # preserve aspect ratio
214 self.img = crop_max_square(self.img)
215
216 if resolution is not None:
217 self.resolution = resolution
218 self.img = self.img.resize(resolution, Image.ANTIALIAS)
219
220 self.img = np.array(self.img)
221 self.img = self.img.astype(np.float32)/255.
222
223 def __len__(self):
224 return 1
225
226 def __getitem__(self, idx):
227 return self.img
228
229
230def chunk_lists_from_batch_reduce_to_raysamples_fn(model_input, meta, gt, max_chunk_size):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected