示例#1
0
    def crop(img, illumination):
        if img is None:
            return None
        img = img[start_x:start_x + s, start_y:start_y + s]
        img = rotate_and_crop(img, angle)
        img = cv2.resize(img, (FLAGS.img_size, FLAGS.img_size))
        if FLAGS.AUGMENTATION_FLIP_LEFTRIGHT and flip_lr:
            img = img[:, ::-1]
        if FLAGS.AUGMENTATION_FLIP_TOPDOWN and flip_td:
            img = img[::-1, :]

        img = img.astype(np.float32)
        new_illum = np.zeros_like(illumination)
        # RGB -> BGR
        illumination = illumination[::-1]
        for i in range(3):
            for j in range(3):
                new_illum[i] += illumination[j] * color_aug[i, j]
        if FLAGS.AUGMENTATION_COLOR_OFFDIAG > 0:
            # Matrix mul, slower
            new_image = np.zeros_like(img)
            for i in range(3):
                for j in range(3):
                    new_image[:, :, i] += img[:, :, j] * color_aug[i, j]
        else:
            img *= np.array(
                [[[color_aug[0][0], color_aug[1][1], color_aug[2][2]]]],
                dtype=np.float32)
            new_image = img
        new_image = np.clip(new_image, 0, 65535)

        def apply_nonlinearity(image):
            if FLAGS.AUGMENTATION_GAMMA != 0 or FLAGS.USE_CURVE:
                res = 1024
                image = np.clip(image * (res * 1.0 / 65536), 0, res - 1)
                gamma = 1.0 + (random.random() -
                               0.5) * FLAGS.AUGMENTATION_GAMMA
                if USE_CURVE:
                    curve = get_random_curve()
                else:
                    curve = lambda x: x
                mapping = create_lut(lambda x: curve(x)**gamma * 65535.0, res)
                return mapping(image)
            else:
                return image

        if FLAGS.SPATIALLY_VARIANT:
            split = new_image.shape[1] / 2
            new_image[:, :split] = apply_nonlinearity(new_image[:, :split])
            new_image[:, split:] = apply_nonlinearity(new_image[:, split:])
        else:
            new_image = apply_nonlinearity(new_image)

        new_illum = np.clip(new_illum, 0.01, 100)

        return new_image, new_illum[::-1]
 def crop(img):
     if img is None:
         return None
     img = img[start_x:start_x + s, start_y:start_y + s]
     img = rotate_and_crop(img, angle)
     img = cv2.resize(img, (self.input_size[1], self.input_size[0]))
     img = img.astype(np.float32)
     new_image = img
     new_image = np.clip(new_image, 0, 255.0)
     #plt.imshow(new_image);plt.show()
     return new_image
示例#3
0
文件: dataset.py 项目: yhlscut/C4
        def crop(img, illumination):
            if img is None:
                return None
            img = img[start_x:start_x + s, start_y:start_y + s]
            img = rotate_and_crop(img, angle)
            img = cv2.resize(img, (FCN_INPUT_SIZE, FCN_INPUT_SIZE))
            if flip_lr:
                img = img[:, ::-1]
            img = img.astype(np.float32)
            new_illum = np.zeros_like(illumination)
            # RGB -> BGR
            illumination = illumination[::-1]
            for i in range(3):
                for j in range(3):
                    new_illum[i] += illumination[j] * color_aug[i, j]

            img *= np.array(
                [[[color_aug[0][0], color_aug[1][1], color_aug[2][2]]]],
                dtype=np.float32)
            new_image = img
            new_image = np.clip(new_image, 0, 65535)
            new_illum = np.clip(new_illum, 0.01, 100)
            return new_image, new_illum[::-1]