示例#1
0
def random_neg_with_rotate(img, label):
    if lucky(0.5):
        ##50% of samples set to  negative samples
        label = label - 1
        # rotate by 180 debgress
        img_rotate = np.rot90(img)
        img = np.rot90(img_rotate)
    return img, np.array(label).astype(np.int32)
示例#2
0
 def transform(self, im, cval=255, **kw):
     """According to the parameters initialized by the class, deform the incoming image"""
     severity = self.severity
     prob = self.prob
     cval = self.convert_color(im, cval)
     if lucky(prob):
         # affine transform
         im = rgeometry(im, severity=severity, cval=cval)
     if lucky(prob):
         im = rdistort(im, severity=severity, cval=cval)
     if lucky(prob):
         im = warp_perspective(im, severity=severity, cval=cval)
     if lucky(prob):
         im = resize(im,
                     fx=kw.get('fx'),
                     fy=kw.get('fy'),
                     severity=severity)
     if lucky(prob):
         im = rotate_about_center(im, severity=severity, cval=cval)
     if lucky(prob):
         # the overall distortion of the image.
         im = whole_rdistort(im, severity=severity)
     if lucky(prob) and self.enable_crop:
         # random crop
         im = randcrop(im, severity=severity)
     return im
示例#3
0
    def add_noise(self, im):
        """randomly add noise to image"""

        severity = self.severity
        prob = self.prob

        if lucky(prob):
            im = noise_gamma(im, severity=severity)
        if lucky(prob):
            im = noise_blur(im, severity=severity)
        if lucky(prob):
            im = noise_gaussian(im, severity=severity)
        if lucky(prob):
            im = noise_salt_pepper(im, severity=severity)
        if lucky(prob):
            im = shift_color(im, severity=severity)
        if lucky(prob):
            im = gaussian_blur(im, severity=severity)
        if lucky(prob):
            im = noise_speckle(im, severity=severity)
        if lucky(prob):
            im = enhance_sharpness(im, severity=severity)
        if lucky(prob):
            im = enhance_contrast(im, severity=severity)
        if lucky(prob):
            im = enhance_brightness(im, severity=severity)
        if lucky(prob):
            im = enhance_color(im, severity=severity)
        if lucky(prob):
            im = random_contrast(im)

        return im