Example #1
0
    def get_TImage(self, tparsing_path, size, params, BigSizeFlag):
        random_drop_prob = self.opt.random_drop_prob if self.opt.isTrain else 0
        TParsing = Image.open(tparsing_path)
        TParsing_size = TParsing.size
        if TParsing_size != (1920, 1080) and BigSizeFlag:
            TParsing = TParsing.resize((1920, 1080), Image.NEAREST)
        elif not BigSizeFlag:
            TParsing = TParsing.resize((192, 256), Image.NEAREST)
        TParsing_np = np.array(TParsing)

        TParsing_new_np = np.zeros_like(TParsing_np)
        TParsing_new_np[(TParsing_np == 1) | (TParsing_np == 2)] = 1
        TParsing_new_np[(TParsing_np == 3) | (TParsing_np == 5) |
                        (TParsing_np == 6) | (TParsing_np == 7) |
                        (TParsing_np == 11)] = 2
        TParsing_new_np[(TParsing_np == 8) | (TParsing_np == 9) |
                        (TParsing_np == 12)] = 3
        TParsing_new_np[(TParsing_np == 4) | (TParsing_np == 13)] = 4
        TParsing_new_np[(TParsing_np == 14)] = 5
        TParsing_new_np[(TParsing_np == 15)] = 6
        TParsing_new_np[(TParsing_np == 16)] = 7
        TParsing_new_np[(TParsing_np == 17)] = 8
        TParsing_new_np[(TParsing_np == 10)] = 9
        TParsing_new_np[(TParsing_np == 18)] = 10
        TParsing_new_np[(TParsing_np == 19)] = 11

        TParsing_new = Image.fromarray(TParsing_new_np)
        if BigSizeFlag:
            transform_scale = get_transform(self.opt,
                                            params,
                                            normalize=False,
                                            method=Image.NEAREST)
        else:
            transform_scale = get_transform_fixed(self.opt,
                                                  params,
                                                  normalize=False,
                                                  method=Image.NEAREST)
        TParsing_scaled = transform_scale(TParsing_new) * 255.0

        if BigSizeFlag:
            transform_scale = get_transform(self.opt,
                                            params,
                                            normalize=True,
                                            method=Image.NEAREST)
        else:
            transform_scale = get_transform_fixed(self.opt,
                                                  params,
                                                  normalize=True,
                                                  method=Image.NEAREST)

        return TParsing_scaled
Example #2
0
    def get_SImage(self, sparsing_path, simg_path, size, params, BigSizeFlag):          
        SI = Image.open(simg_path).convert('RGB')
        if SI.size != (1920,1080) and BigSizeFlag:
            SI = SI.resize((1920,1080), Image.BICUBIC)
        elif not BigSizeFlag:
            SI = SI.resize((192,256), Image.BICUBIC)
        SFG_np = np.array(SI)

        random_drop_prob = self.opt.random_drop_prob if self.opt.isTrain else 0

        SParsing = Image.open(sparsing_path)
        SParsing_size = SParsing.size
        if SParsing_size != (1920,1080) and SParsing_size != (192,256) and BigSizeFlag:
            SParsing = SParsing.resize((1920,1080), Image.NEAREST)
        elif not BigSizeFlag and SParsing_size != (192,256):
            SParsing = SParsing.resize((192,256), Image.NEAREST)
        SParsing_np = np.array(SParsing)

        if SParsing_size == (192,256):
            SParsing_new_np = SParsing_np
            SParsing_new_np[(SParsing_np != 1) & (SParsing_np != 2)] = 0
        else:
            SParsing_new_np = np.zeros_like(SParsing_np)
            SParsing_new_np[(SParsing_np == 3) | (SParsing_np == 5) | (SParsing_np == 6) | (SParsing_np == 7) | (SParsing_np == 11)] = 1
            SParsing_new_np[(SParsing_np == 8) | (SParsing_np == 9) | (SParsing_np == 12)] = 2

        if BigSizeFlag:
            transform_scale = get_transform(self.opt, params, normalize=True, method=Image.NEAREST, color_aug=False)
        else:
            transform_scale = get_transform_fixed(self.opt, params, normalize=True, method=Image.NEAREST, color_aug=False)

        SParsing_new = Image.fromarray(SParsing_new_np)
        if SParsing_size != (192,256) and BigSizeFlag:
            transform_scale = get_transform(self.opt, params, normalize=False, method=Image.NEAREST, color_aug=False)
        else:
            transform_scale = get_transform_fixed(self.opt, params, normalize=False, method=Image.NEAREST, color_aug=False)
        SParsing_scaled = transform_scale(SParsing_new)*255.0

        if BigSizeFlag:
            transform_scale = get_transform(self.opt, params, normalize=True, method=Image.BICUBIC, color_aug=self.opt.color_aug)
        else:
            transform_scale = get_transform_fixed(self.opt, params, normalize=True, method=Image.BICUBIC, color_aug=self.opt.color_aug)
        SFG_full_scaled = transform_scale(Image.fromarray(SFG_np))
        SFG_np[:,:,0][(SParsing_new_np == 0)] = 0
        SFG_np[:,:,1][(SParsing_new_np == 0)] = 0
        SFG_np[:,:,2][(SParsing_new_np == 0)] = 0
        SFG_scaled = transform_scale(Image.fromarray(SFG_np))

        return SParsing_scaled, SFG_scaled, SFG_full_scaled
Example #3
0
    def get_TImage(self, tparsing_path, timg_path, size, params, BigSizeFlag):          
        random_drop_prob = self.opt.random_drop_prob if self.opt.isTrain else 0
        TI = Image.open(timg_path).convert('RGB')

        if TI.size != (1920,1080) and BigSizeFlag:
            TI = TI.resize((1920,1080), Image.BICUBIC)
        elif not BigSizeFlag:
            TI = TI.resize((192,256), Image.BICUBIC)
        TFG_np = np.array(TI)        

        TParsing = Image.open(tparsing_path)
        TParsing_size = TParsing.size

        if TParsing_size != (1920,1080) and TParsing_size != (192,256) and BigSizeFlag:
            TParsing = TParsing.resize((1920,1080), Image.NEAREST)
        elif not BigSizeFlag and TParsing_size != (192,256):
            TParsing = TParsing.resize((192,256), Image.NEAREST)
        TParsing_np = np.array(TParsing)

        TParsing_new_np = np.zeros_like(TParsing_np)

        TParsing_new_np[(TParsing_np == 3) | (TParsing_np == 5) | (TParsing_np == 6) | (TParsing_np == 7) | (TParsing_np == 11)] = 1
        TParsing_new_np[(TParsing_np == 8) | (TParsing_np == 9) | (TParsing_np == 12)] = 2

        TParsing_new = Image.fromarray(TParsing_new_np)
        if TParsing_size != (192,256) and BigSizeFlag:
            transform_scale = get_transform(self.opt, params, normalize=False, method=Image.NEAREST, color_aug=False)
        else:
            transform_scale = get_transform_fixed(self.opt, params, normalize=False, method=Image.NEAREST, color_aug=False)
        TParsing_scaled = transform_scale(TParsing_new)*255.0

        if BigSizeFlag:
            transform_scale = get_transform(self.opt, params, normalize=True, method=Image.NEAREST, color_aug=False)
        else:
            transform_scale = get_transform_fixed(self.opt, params, normalize=True, method=Image.NEAREST, color_aug=False)

        if BigSizeFlag:
            transform_scale = get_transform(self.opt, params, normalize=True, method=Image.BICUBIC, color_aug=self.opt.color_aug)
        else:
            transform_scale = get_transform_fixed(self.opt, params, normalize=True, method=Image.BICUBIC, color_aug=self.opt.color_aug)
        TFG_np[:,:,0][(TParsing_new_np == 0)] = 0
        TFG_np[:,:,1][(TParsing_new_np == 0)] = 0
        TFG_np[:,:,2][(TParsing_new_np == 0)] = 0
        TFG_scaled = transform_scale(Image.fromarray(TFG_np))

        return TParsing_scaled, TFG_scaled
Example #4
0
 def get_bg_image(self, bg_path, size, params, BigSizeFlag):
     if os.path.exists(bg_path):
         BG = Image.open(bg_path).convert('RGB')
         if BigSizeFlag:
             transform_scale = get_transform(self.opt,
                                             params,
                                             normalize=True,
                                             method=Image.BICUBIC)
         else:
             transform_scale = get_transform_fixed(self.opt,
                                                   params,
                                                   normalize=True,
                                                   method=Image.BICUBIC)
         BG_scaled = transform_scale(BG)
         if BigSizeFlag:
             BG_scaled = self.crop(BG_scaled)
         BG_flag = True
     else:
         print('No available background input found in: ' + bg_path)
         BG_scaled = -torch.ones(3, 256, 192)
         BG_flag = False
     return BG_scaled, BG_flag
Example #5
0
 def get_bg_image(self, bg_path, size, params, BigSizeFlag):
     if os.path.exists(bg_path):
         BG = Image.open(bg_path).convert('RGB')
         if BigSizeFlag:
             transform_scale = get_transform(self.opt,
                                             params,
                                             normalize=True,
                                             method=Image.BICUBIC,
                                             color_aug=self.opt.color_aug)
         else:
             transform_scale = get_transform_fixed(
                 self.opt,
                 params,
                 normalize=True,
                 method=Image.BICUBIC,
                 color_aug=self.opt.color_aug)
         BG_scaled = transform_scale(BG)
         BG_scaled = self.crop(BG_scaled)
         BG_flag = True
     else:
         BG_scaled = -torch.ones(3, 256, 192)
         BG_flag = False
     return BG_scaled, BG_flag
Example #6
0
    def get_SImage(self, spose_path, sparsing_path, sfg_path, simg_path, size,
                   params, BigSizeFlag):
        SI = Image.open(simg_path).convert('RGB')
        if SI.size != (1920, 1080) and BigSizeFlag:
            SI = SI.resize((1920, 1080), Image.BICUBIC)
        elif not BigSizeFlag:
            SI = SI.resize((192, 256), Image.BICUBIC)
        SFG_np = np.array(SI)
        SFG_full_np = np.array(SI)

        random_drop_prob = self.opt.random_drop_prob if self.opt.isTrain else 0
        SPose_array, _ = read_keypoints(spose_path, size, random_drop_prob,
                                        self.opt.remove_face_labels,
                                        self.opt.basic_point_only)
        SPose = Image.fromarray(SPose_array)
        if SPose.size != (1920, 1080) and BigSizeFlag:
            SPose = SPose.resize((1920, 1080), Image.NEAREST)
        elif not BigSizeFlag:
            SPose = SPose.resize((192, 256), Image.NEAREST)
        SPose_np = np.array(SPose)

        SParsing = Image.open(sparsing_path)
        SParsing_size = SParsing.size
        if SParsing_size != (1920, 1080) and SParsing_size != (
                192, 256) and BigSizeFlag:
            SParsing = SParsing.resize((1920, 1080), Image.NEAREST)
        elif not BigSizeFlag and SParsing_size != (192, 256):
            SParsing = SParsing.resize((192, 256), Image.NEAREST)
        SParsing_np = np.array(SParsing)

        if SParsing_size == (192, 256):
            SParsing_new_np = SParsing_np
        else:
            SParsing_new_np = np.zeros_like(SParsing_np)
            SParsing_new_np[(SParsing_np == 3) | (SParsing_np == 5) |
                            (SParsing_np == 6) | (SParsing_np == 7) |
                            (SParsing_np == 11)] = 1
            SParsing_new_np[(SParsing_np == 8) | (SParsing_np == 9) |
                            (SParsing_np == 12)] = 2
            SParsing_new_np[(SParsing_np == 1) | (SParsing_np == 2)] = 3
            SParsing_new_np[(SParsing_np == 4) | (SParsing_np == 13)] = 4
            SParsing_new_np[(SParsing_np == 14)] = 5
            SParsing_new_np[(SParsing_np == 15)] = 6
            SParsing_new_np[(SParsing_np == 16)] = 7
            SParsing_new_np[(SParsing_np == 17)] = 8
            SParsing_new_np[(SParsing_np == 10)] = 9
            SParsing_new_np[(SParsing_np == 18)] = 10
            SParsing_new_np[(SParsing_np == 19)] = 11

        if BigSizeFlag:
            transform_scale = get_transform(self.opt,
                                            params,
                                            normalize=True,
                                            method=Image.NEAREST,
                                            color_aug=False)
        else:
            transform_scale = get_transform_fixed(self.opt,
                                                  params,
                                                  normalize=True,
                                                  method=Image.NEAREST,
                                                  color_aug=False)

        SPose_scaled = transform_scale(Image.fromarray(SPose_np))

        SParsing_new = Image.fromarray(SParsing_new_np)
        if SParsing_size != (192, 256) and BigSizeFlag:
            transform_scale = get_transform(self.opt,
                                            params,
                                            normalize=False,
                                            method=Image.NEAREST,
                                            color_aug=False)
        else:
            transform_scale = get_transform_fixed(self.opt,
                                                  params,
                                                  normalize=False,
                                                  method=Image.NEAREST,
                                                  color_aug=False)
        SParsing_scaled = transform_scale(SParsing_new) * 255.0

        if BigSizeFlag:
            transform_scale = get_transform(self.opt,
                                            params,
                                            normalize=True,
                                            method=Image.BICUBIC,
                                            color_aug=self.opt.color_aug)
        else:
            transform_scale = get_transform_fixed(self.opt,
                                                  params,
                                                  normalize=True,
                                                  method=Image.BICUBIC,
                                                  color_aug=self.opt.color_aug)
        SI_scaled = transform_scale(SI)
        SFG_full_np[(SParsing_new_np == 0)] = 0
        SFG_full_scaled = transform_scale(Image.fromarray(SFG_full_np))

        if SI.size != (192, 256) and BigSizeFlag:
            transform_scale = get_transform(self.opt,
                                            params,
                                            normalize=True,
                                            method=Image.BICUBIC,
                                            color_aug=self.opt.color_aug)
        else:
            transform_scale = get_transform_fixed(self.opt,
                                                  params,
                                                  normalize=True,
                                                  method=Image.BICUBIC,
                                                  color_aug=self.opt.color_aug)

        if SI.size != (192, 256):
            SFG_np[(SParsing_new_np != 1) & (SParsing_new_np != 2) &
                   (SParsing_new_np != 3)] = 0
        SFG_scaled = transform_scale(Image.fromarray(SFG_np))

        return SPose_scaled, SParsing_scaled, SFG_scaled, SFG_full_scaled, SI_scaled
Example #7
0
    def get_TImage(self, tpose_path, tparsing_path, timg_path, size, params,
                   BigSizeFlag):
        random_drop_prob = self.opt.random_drop_prob if self.opt.isTrain else 0
        TPose_array, translation = read_keypoints(tpose_path, size,
                                                  random_drop_prob,
                                                  self.opt.remove_face_labels,
                                                  self.opt.basic_point_only)
        TPose = Image.fromarray(TPose_array)
        if TPose.size != (1920, 1080) and BigSizeFlag:
            TPose = TPose.resize((1920, 1080), Image.NEAREST)
        elif not BigSizeFlag:
            TPose = TPose.resize((192, 256), Image.NEAREST)
        TPose_uncloth_tmp_np = np.array(TPose)
        TPose_cloth_tmp_np = np.array(TPose)

        TI = Image.open(timg_path).convert('RGB')
        if TI.size != (1920, 1080) and BigSizeFlag:
            TI = TI.resize((1920, 1080), Image.BICUBIC)
        elif not BigSizeFlag:
            TI = TI.resize((192, 256), Image.BICUBIC)
        TFG_tmp_np = np.array(TI)
        TFG_uncloth_tmp_np = np.array(TI)
        TFG_cloth_tmp_np = np.array(TI)

        TParsing = Image.open(tparsing_path)
        TParsing_size = TParsing.size
        if TParsing_size != (1920, 1080) and TParsing_size != (
                192, 256) and BigSizeFlag:
            TParsing = TParsing.resize((1920, 1080), Image.NEAREST)
        elif not BigSizeFlag and TParsing_size != (192, 256):
            TParsing = TParsing.resize((192, 256), Image.NEAREST)
        TParsing_np = np.array(TParsing)

        TParsing_new_np = np.zeros_like(TParsing_np)
        TParsing_new_np[(TParsing_np == 1) | (TParsing_np == 2)] = 1
        TParsing_new_np[(TParsing_np == 3) | (TParsing_np == 5) |
                        (TParsing_np == 6) | (TParsing_np == 7) |
                        (TParsing_np == 11)] = 2
        TParsing_new_np[(TParsing_np == 8) | (TParsing_np == 9) |
                        (TParsing_np == 12)] = 3
        TParsing_new_np[(TParsing_np == 4) | (TParsing_np == 13)] = 4
        TParsing_new_np[(TParsing_np == 14)] = 5
        TParsing_new_np[(TParsing_np == 15)] = 6
        TParsing_new_np[(TParsing_np == 16)] = 7
        TParsing_new_np[(TParsing_np == 17)] = 8
        TParsing_new_np[(TParsing_np == 10)] = 9
        TParsing_new_np[(TParsing_np == 18)] = 10
        TParsing_new_np[(TParsing_np == 19)] = 11

        TParsing_uncloth_np = np.zeros_like(TParsing_np)
        TParsing_uncloth_np[(TParsing_np == 1) | (TParsing_np == 2)] = 1
        TParsing_uncloth_np[(TParsing_np == 4) | (TParsing_np == 13)] = 2
        TParsing_uncloth_np[(TParsing_np == 14)] = 3
        TParsing_uncloth_np[(TParsing_np == 15)] = 4
        TParsing_uncloth_np[(TParsing_np == 16)] = 5
        TParsing_uncloth_np[(TParsing_np == 17)] = 6
        TParsing_uncloth_np[(TParsing_np == 10)] = 7
        TParsing_uncloth_np[(TParsing_np == 18)] = 8
        TParsing_uncloth_np[(TParsing_np == 19)] = 9

        TParsing_cloth_np = np.zeros_like(TParsing_new_np)
        TParsing_cloth_np[(TParsing_new_np == 2) | (TParsing_new_np == 3)] = \
        TParsing_new_np[(TParsing_new_np == 2) | (TParsing_new_np == 3)] - 1

        TParsing_new = Image.fromarray(TParsing_new_np)
        TParsing_uncloth = Image.fromarray(TParsing_uncloth_np)
        TParsing_cloth = Image.fromarray(TParsing_cloth_np)
        if TParsing_size != (192, 256) and BigSizeFlag:
            transform_scale = get_transform(self.opt,
                                            params,
                                            normalize=False,
                                            method=Image.NEAREST)
        else:
            transform_scale = get_transform_fixed(self.opt,
                                                  params,
                                                  normalize=False,
                                                  method=Image.NEAREST)
        TParsing_uncloth_scaled = transform_scale(TParsing_uncloth) * 255.0
        TParsing_cloth_scaled = transform_scale(TParsing_cloth) * 255.0
        TParsing_scaled = transform_scale(TParsing_new) * 255.0

        if BigSizeFlag:
            transform_scale = get_transform(self.opt,
                                            params,
                                            normalize=True,
                                            method=Image.NEAREST)
        else:
            transform_scale = get_transform_fixed(self.opt,
                                                  params,
                                                  normalize=True,
                                                  method=Image.NEAREST)

        TPose_scaled = transform_scale(TPose)

        TPose_uncloth_tmp_np[:, :, 0][(TParsing_uncloth_np == 0)] = 0
        TPose_uncloth_tmp_np[:, :, 1][(TParsing_uncloth_np == 0)] = 0
        TPose_uncloth_tmp_np[:, :, 2][(TParsing_uncloth_np == 0)] = 0
        TPose_uncloth_scaled = transform_scale(
            Image.fromarray(TPose_uncloth_tmp_np))

        TPose_cloth_tmp_np[:, :, 0][(TParsing_cloth_np == 0)] = 0
        TPose_cloth_tmp_np[:, :, 1][(TParsing_cloth_np == 0)] = 0
        TPose_cloth_tmp_np[:, :, 2][(TParsing_cloth_np == 0)] = 0
        TPose_cloth_scaled = transform_scale(
            Image.fromarray(TPose_cloth_tmp_np))

        if BigSizeFlag:
            transform_scale = get_transform(self.opt,
                                            params,
                                            normalize=True,
                                            method=Image.BICUBIC)
        else:
            transform_scale = get_transform_fixed(self.opt,
                                                  params,
                                                  normalize=True,
                                                  method=Image.BICUBIC)

        TFG_tmp_np[:, :, 0][(TParsing_new_np == 0)] = 0
        TFG_tmp_np[:, :, 1][(TParsing_new_np == 0)] = 0
        TFG_tmp_np[:, :, 2][(TParsing_new_np == 0)] = 0
        TFG_scaled = transform_scale(Image.fromarray(TFG_tmp_np))

        TFG_uncloth_tmp_np[:, :, 0][(TParsing_uncloth_np == 0)] = 0
        TFG_uncloth_tmp_np[:, :, 1][(TParsing_uncloth_np == 0)] = 0
        TFG_uncloth_tmp_np[:, :, 2][(TParsing_uncloth_np == 0)] = 0
        TFG_uncloth_scaled = transform_scale(
            Image.fromarray(TFG_uncloth_tmp_np))

        TFG_cloth_tmp_np[:, :, 0][(TParsing_cloth_np == 0)] = 0
        TFG_cloth_tmp_np[:, :, 1][(TParsing_cloth_np == 0)] = 0
        TFG_cloth_tmp_np[:, :, 2][(TParsing_cloth_np == 0)] = 0
        TFG_cloth_scaled = transform_scale(Image.fromarray(TFG_cloth_tmp_np))

        return TPose_scaled, TParsing_scaled, TFG_scaled, TPose_uncloth_scaled, TParsing_uncloth_scaled, TFG_uncloth_scaled, TPose_cloth_scaled, TParsing_cloth_scaled, TFG_cloth_scaled