def __getitem__(self, ind):
    ind = (ind % len(self.perm))
    if (ind == 0):
        random.shuffle(self.perm)
    if (self.phase == 'TRAIN'):
        scale = np.random.random()
        imCropWidth = int(np.round((((self.imWidthMax - self.imWidthMin) * scale) + self.imWidthMin)))
        imCropHeight = int(((float(self.imHeight) / float(self.imWidth)) * imCropWidth))
        rs = int(np.round(((480 - imCropHeight) * np.random.random())))
        re = (rs + imCropHeight)
        cs = int(np.round(((640 - imCropWidth) * np.random.random())))
        ce = (cs + imCropWidth)
    elif (self.phase == 'TEST'):
        imCropWidth = self.imWidth
        imCropHeight = self.imHeight
        (rs, re, cs, ce) = (0, 480, 0, 640)
    segNormal = (0.5 * (self.loadImage(self.segList[self.perm[ind]], rs, re, cs, ce) + 1)[0:1, :, :])
    im = (0.5 * (self.loadImage(self.imList[self.perm[ind]], rs, re, cs, ce, isGama=True) + 1))
    normal = self.loadImage(self.normalList[self.perm[ind]], rs, re, cs, ce)
    normal = (normal / np.sqrt(np.maximum(np.sum((normal * normal), axis=0), 1e-05))[np.newaxis, :])
    depth = self.loadDepth(self.depthList[self.perm[ind]], rs, re, cs, ce)
    if ((imCropHeight != self.imHeight) or (imCropWidth != self.imWidth)):
        depth = np.squeeze(depth, axis=0)
        depth = cv2.resize(depth, (self.imWidth, self.imHeight), interpolation=cv2.INTER_LINEAR)
        depth = depth[np.newaxis, :, :]
    segDepth = np.logical_and((depth > 1), (depth < 10)).astype(np.float32)
    if ((imCropHeight != self.imHeight) or (imCropWidth != self.imWidth)):
        normal = normal.transpose([1, 2, 0])
        normal = cv2.resize(normal, (self.imWidth, self.imHeight), interpolation=cv2.INTER_LINEAR)
        normal = normal.transpose([2, 0, 1])
    normal = (normal / np.maximum(np.sqrt(np.sum((normal * normal), axis=0)[np.newaxis, :, :]), 1e-05))
    if ((imCropHeight != self.imHeight) or (imCropWidth != self.imWidth)):
        segNormal = np.squeeze(segNormal, axis=0)
        segNormal = cv2.resize(segNormal, (self.imWidth, self.imHeight), interpolation=cv2.INTER_LINEAR)
        segNormal = segNormal[np.newaxis, :, :]
        im = im.transpose([1, 2, 0])
        im = cv2.resize(im, (self.imWidth, self.imHeight), interpolation=cv2.INTER_LINEAR)
        im = im.transpose([2, 0, 1])
    if (self.phase == 'TRAIN'):
        if (np.random.random() > 0.5):
            normal = np.ascontiguousarray(normal[:, :, ::(- 1)])
            normal[0, :, :] = (- normal[0, :, :])
            depth = np.ascontiguousarray(depth[:, :, ::(- 1)])
            segNormal = np.ascontiguousarray(segNormal[:, :, ::(- 1)])
            segDepth = np.ascontiguousarray(segDepth[:, :, ::(- 1)])
            im = np.ascontiguousarray(im[:, :, ::(- 1)])
        scale = (1 + ((np.random.random(3) * 0.4) - 0.2))
        scale = scale.reshape([3, 1, 1])
        im = (im * scale)
    batchDict = {'normal': normal, 'depth': depth, 'segNormal': segNormal, 'segDepth': segDepth, 'im': im.astype(np.float32), 'name': self.imList[self.perm[ind]]}
    return batchDict
def __getitem__(self, ind):
    ind = (ind % len(self.perm))
    if (ind == 0):
        random.shuffle(self.perm)
    if (self.phase == 'TRAIN'):
        scale = np.random.random()
        imCropWidth = int(np.round((((self.imWidthMax - self.imWidthMin) * scale) + self.imWidthMin)))
        imCropHeight = int(((float(self.imHeight) / float(self.imWidth)) * imCropWidth))
        rs = int(np.round(((480 - imCropHeight) * np.random.random())))
        re = (rs + imCropHeight)
        cs = int(np.round(((640 - imCropWidth) * np.random.random())))
        ce = (cs + imCropWidth)
    elif (self.phase == 'TEST'):
        imCropWidth = self.imWidth
        imCropHeight = self.imHeight
        (rs, re, cs, ce) = (0, 480, 0, 640)
    segNormal = (0.5 * (self.loadImage(self.segList[self.perm[ind]], rs, re, cs, ce) + 1)[0:1, :, :])
    im = (0.5 * (self.loadImage(self.imList[self.perm[ind]], rs, re, cs, ce, isGama=True) + 1))
    normal = self.loadImage(self.normalList[self.perm[ind]], rs, re, cs, ce)
    normal = (normal / np.sqrt(np.maximum(np.sum((normal * normal), axis=0), 1e-05))[np.newaxis, :])
    depth = self.loadDepth(self.depthList[self.perm[ind]], rs, re, cs, ce)
    if ((imCropHeight != self.imHeight) or (imCropWidth != self.imWidth)):
        depth = np.squeeze(depth, axis=0)
        depth = cv2.resize(depth, (self.imWidth, self.imHeight), interpolation=cv2.INTER_LINEAR)
        depth = depth[np.newaxis, :, :]
    segDepth = np.logical_and((depth > 1), (depth < 10)).astype(np.float32)
    if ((imCropHeight != self.imHeight) or (imCropWidth != self.imWidth)):
        normal = normal.transpose([1, 2, 0])
        normal = cv2.resize(normal, (self.imWidth, self.imHeight), interpolation=cv2.INTER_LINEAR)
        normal = normal.transpose([2, 0, 1])
    normal = (normal / np.maximum(np.sqrt(np.sum((normal * normal), axis=0)[np.newaxis, :, :]), 1e-05))
    if ((imCropHeight != self.imHeight) or (imCropWidth != self.imWidth)):
        segNormal = np.squeeze(segNormal, axis=0)
        segNormal = cv2.resize(segNormal, (self.imWidth, self.imHeight), interpolation=cv2.INTER_LINEAR)
        segNormal = segNormal[np.newaxis, :, :]
        im = im.transpose([1, 2, 0])
        im = cv2.resize(im, (self.imWidth, self.imHeight), interpolation=cv2.INTER_LINEAR)
        im = im.transpose([2, 0, 1])
    if (self.phase == 'TRAIN'):
        if (np.random.random() > 0.5):
            normal = np.ascontiguousarray(normal[:, :, ::(- 1)])
            normal[0, :, :] = (- normal[0, :, :])
            depth = np.ascontiguousarray(depth[:, :, ::(- 1)])
            segNormal = np.ascontiguousarray(segNormal[:, :, ::(- 1)])
            segDepth = np.ascontiguousarray(segDepth[:, :, ::(- 1)])
            im = np.ascontiguousarray(im[:, :, ::(- 1)])
        scale = (1 + ((np.random.random(3) * 0.4) - 0.2))
        scale = scale.reshape([3, 1, 1])
        im = (im * scale)
    batchDict = {'normal': normal, 'depth': depth, 'segNormal': segNormal, 'segDepth': segDepth, 'im': im.astype(np.float32), 'name': self.imList[self.perm[ind]]}
    return batchDict