Beispiel #1
0
 def rgb_processing(self, rgb_img, center, scale, rot, flip, pn, is_train):
     rgb_img = crop(rgb_img.copy(), center, scale, [constants.IMG_RES, constants.IMG_RES], rot=rot)
     if is_train:
         if flip:
             rgb_img = flip_img(rgb_img)
     rgb_img = np.transpose(rgb_img.astype('float32'),(2,0,1))/255.0
     return rgb_img
Beispiel #2
0
    def rgb_processing(self, rgb_img, center, scale, rot, flip, pn, img_size):
        """Process rgb image and do augmentation."""
        if self.is_rotate:
            rgb_img = crop_v2(rgb_img, center, scale,
                              [constants.IMG_RES, constants.IMG_RES], rot=rot)

        # flip the image
        if flip:
            rgb_img = flip_img(rgb_img)
        # in the rgb image we add pixel noise in a channel-wise manner
        rgb_img[:, :, 0] = np.minimum(255.0, np.maximum(0.0, rgb_img[:, :, 0] * pn[0]))
        rgb_img[:, :, 1] = np.minimum(255.0, np.maximum(0.0, rgb_img[:, :, 1] * pn[1]))
        rgb_img[:, :, 2] = np.minimum(255.0, np.maximum(0.0, rgb_img[:, :, 2] * pn[2]))

        if img_size == 224:
            rgb_img_up = rgb_img.copy()
            # add color jitter
            if self.is_train:
                rgb_img_up = color_jitter(rgb_img_up, brightness=0.4, contrast=0.4, saturation=0.4, prob=0.5)
            rgb_img_up = rgb_img_up.clip(0, 255)
        else:
            shape = rgb_img.shape
            rgb_img_lr = scipy.misc.imresize(rgb_img, (img_size, img_size), interp='bicubic')
            rgb_img_lr = rgb_img_lr.clip(0, 255)
            rgb_img_up = scipy.misc.imresize(rgb_img_lr, (shape[0], shape[1]), interp='bicubic')  # naive upsampling
            # add color jitter
            if self.is_train:
                rgb_img_up = color_jitter(rgb_img_up, brightness=0.4, contrast=0.4, saturation=0.4, prob=0.5)
                rgb_img_up = rgb_img_up.clip(0, 255)

        rgb_img_up = np.transpose(rgb_img_up.astype('float32'), (2, 0, 1)) / 255.0
        return rgb_img_up
Beispiel #3
0
 def rgb_processing(self, rgb_img, center, scale, rot, flip, pn):
     """Process rgb image and do augmentation."""
     rgb_img = crop(rgb_img, center, scale, 
                   [constants.IMG_RES, constants.IMG_RES], rot=rot)
     # flip the image 
     if flip:
         rgb_img = flip_img(rgb_img)
     # in the rgb image we add pixel noise in a channel-wise manner
     rgb_img[:,:,0] = np.minimum(255.0, np.maximum(0.0, rgb_img[:,:,0]*pn[0]))
     rgb_img[:,:,1] = np.minimum(255.0, np.maximum(0.0, rgb_img[:,:,1]*pn[1]))
     rgb_img[:,:,2] = np.minimum(255.0, np.maximum(0.0, rgb_img[:,:,2]*pn[2]))
     # (3,224,224),float,[0,1]
     rgb_img = np.transpose(rgb_img.astype('float32'),(2,0,1))/255.0
     return rgb_img
Beispiel #4
0
 def rgb_processing(self, rgb_img, center, scale, rot, flip, pn):
     """Process rgb image and do augmentation."""
     # crop and rotate the image
     if self.use_augmentation_rot:
         rgb_img = crop(rgb_img, center, scale, 
                       [self.options.img_res, self.options.img_res], rot=rot)
     else:
         rgb_img = crop(rgb_img, center, scale, 
                       [self.options.img_res, self.options.img_res], rot=0)
     # flip the image 
     if flip:
         rgb_img = flip_img(rgb_img)
     # in the rgb image we add pixel noise in a channel-wise manner
     if self.use_augmentation_rgb:
         rgb_img[:,:,0] = np.minimum(255.0, np.maximum(0.0, rgb_img[:,:,0]*pn[0]))
         rgb_img[:,:,1] = np.minimum(255.0, np.maximum(0.0, rgb_img[:,:,1]*pn[1]))
         rgb_img[:,:,2] = np.minimum(255.0, np.maximum(0.0, rgb_img[:,:,2]*pn[2]))
         
     # (3,224,224),float,[0,1]
     rgb_img = np.transpose(rgb_img.astype('float32'),(2,0,1))/255.0
     return rgb_img