예제 #1
0
 def forward(self, data, state):
     im = Image.fromarray(data)
     width, height = im.size
     displacement = int(self.level / 10 * height / 3 * random.choice([1.0, -1.0]))
     im = im.transform((width, height),
                       ImageTransform.AffineTransform((1.0, 0.0, 0.0, 0.0, 1.0, displacement)),
                       resample=Image.BICUBIC)
     return np.copy(np.asarray(im))
예제 #2
0
 def _apply_translatex(data: np.ndarray, factor: float) -> np.ndarray:
     im = Image.fromarray(data)
     width, height = im.size
     displacement = factor * width
     im = im.transform((width, height),
                       ImageTransform.AffineTransform(
                           (1.0, 0.0, displacement, 0.0, 1.0, 0.0)),
                       resample=Image.BICUBIC)
     return np.array(im)
예제 #3
0
def test_sanity():
    transform = ImageTransform.AffineTransform(seq[:6])
    assert_no_exception(lambda: im.transform((100, 100), transform))
    transform = ImageTransform.ExtentTransform(seq[:4])
    assert_no_exception(lambda: im.transform((100, 100), transform))
    transform = ImageTransform.QuadTransform(seq[:8])
    assert_no_exception(lambda: im.transform((100, 100), transform))
    transform = ImageTransform.MeshTransform([(seq[:4], seq[:8])])
    assert_no_exception(lambda: im.transform((100, 100), transform))
예제 #4
0
 def _apply_translatex(self, data: np.ndarray) -> np.ndarray:
     im = Image.fromarray(data)
     width, height = im.size
     displacement = random.uniform(self.shift_limit[0] * width,
                                   self.shift_limit[1] * width)
     im = im.transform((width, height),
                       ImageTransform.AffineTransform(
                           (1.0, 0.0, displacement, 0.0, 1.0, 0.0)),
                       resample=Image.BICUBIC)
     return np.array(im)
예제 #5
0
 def _apply_sheary(data: np.ndarray, shear_coeff: float) -> np.ndarray:
     im = Image.fromarray(data)
     width, height = im.size
     yshift = round(abs(shear_coeff) * height)
     newheight = height + yshift
     im = im.transform((width, newheight),
                       ImageTransform.AffineTransform(
                           (1.0, 0.0, 0.0, shear_coeff, 1.0,
                            -yshift if shear_coeff > 0 else 0.0)),
                       resample=Image.BICUBIC)
     im = im.resize((width, height))
     return np.array(im)
예제 #6
0
    def test_sanity(self):
        im = Image.new("L", (100, 100))

        seq = tuple(range(10))

        transform = ImageTransform.AffineTransform(seq[:6])
        im.transform((100, 100), transform)
        transform = ImageTransform.ExtentTransform(seq[:4])
        im.transform((100, 100), transform)
        transform = ImageTransform.QuadTransform(seq[:8])
        im.transform((100, 100), transform)
        transform = ImageTransform.MeshTransform([(seq[:4], seq[:8])])
        im.transform((100, 100), transform)
예제 #7
0
 def forward(self, data, state):
     im = Image.fromarray(data)
     shear_coeff = self.shear_coef * random.choice([1.0, -1.0])
     width, height = im.size
     yshift = int(round(self.shear_coef * height))
     newheight = height + yshift
     im = im.transform((width, newheight),
                       ImageTransform.AffineTransform(
                           (1.0, 0.0, 0.0, shear_coeff, 1.0, -yshift if shear_coeff > 0 else 0.0)),
                       resample=Image.BICUBIC)
     if self.shear_coef > 0:
         im = im.resize((width, height))
     return np.copy(np.asarray(im))
예제 #8
0
 def _apply_shearx(self, data: np.ndarray) -> np.ndarray:
     im = Image.fromarray(data)
     shear_coeff = random.uniform(self.shear_coef[0], self.shear_coef[1])
     width, height = im.size
     xshift = round(abs(shear_coeff) * width)
     new_width = width + xshift
     im = im.transform(
         (new_width, height),
         ImageTransform.AffineTransform(
             (1.0, shear_coeff, -xshift if shear_coeff > 0 else 0.0, 0.0,
              1.0, 0.0)),
         resample=Image.BICUBIC)
     im = im.resize((width, height))
     return np.array(im)