in data/dryice1.py [0:0]
def __getitem__(self, idx):
frame, cam = self.framecamlist[idx]
result = {}
validinput = True
# fixed camera images
if "fixedcamimage" in self.keyfilter:
ninput = len(self.fixedcameras)
fixedcamimage = np.zeros((3 * ninput, 512, 334), dtype=np.float32)
for i in range(ninput):
imagepath = (
"experiments/dryice1/data/cam{}/image{:04}.jpg"
.format(self.fixedcameras[i], int(frame)))
image = np.asarray(Image.open(imagepath), dtype=np.uint8)[::2, ::2, :].transpose((2, 0, 1)).astype(np.float32)
if np.sum(image) == 0:
validinput = False
fixedcamimage[i*3:(i+1)*3, :, :] = image
fixedcamimage[:] -= self.imagemean
fixedcamimage[:] /= self.imagestd
result["fixedcamimage"] = fixedcamimage
result["validinput"] = np.float32(1.0 if validinput else 0.0)
# image data
if cam is not None:
if "camera" in self.keyfilter:
# camera data
result["camrot"] = np.dot(self.transf[:3, :3].T, self.camrot[cam].T).T
result["campos"] = np.dot(self.transf[:3, :3].T, self.campos[cam] - self.transf[:3, 3])
result["focal"] = self.focal[cam]
result["princpt"] = self.princpt[cam]
result["camindex"] = self.allcameras.index(cam)
if "image" in self.keyfilter:
# image
imagepath = (
"experiments/dryice1/data/cam{}/image{:04}.jpg"
.format(cam, int(frame)))
image = np.asarray(Image.open(imagepath), dtype=np.uint8).transpose((2, 0, 1)).astype(np.float32)
height, width = image.shape[1:3]
valid = np.float32(1.0) if np.sum(image) != 0 else np.float32(0.)
result["image"] = image
result["imagevalid"] = valid
if "pixelcoords" in self.keyfilter:
if self.subsampletype == "patch":
indx = np.random.randint(0, width - self.subsamplesize + 1)
indy = np.random.randint(0, height - self.subsamplesize + 1)
px, py = np.meshgrid(
np.arange(indx, indx + self.subsamplesize).astype(np.float32),
np.arange(indy, indy + self.subsamplesize).astype(np.float32))
elif self.subsampletype == "random":
px = np.random.randint(0, width, size=(self.subsamplesize, self.subsamplesize)).astype(np.float32)
py = np.random.randint(0, height, size=(self.subsamplesize, self.subsamplesize)).astype(np.float32)
elif self.subsampletype == "random2":
px = np.random.uniform(0, width - 1e-5, size=(self.subsamplesize, self.subsamplesize)).astype(np.float32)
py = np.random.uniform(0, height - 1e-5, size=(self.subsamplesize, self.subsamplesize)).astype(np.float32)
else:
px, py = np.meshgrid(np.arange(width).astype(np.float32), np.arange(height).astype(np.float32))
result["pixelcoords"] = np.stack((px, py), axis=-1)
return result