Пример #1
0
    def transform(self, pil, mode="sketch"):
        def show(mode, pil_numpy):
            print(mode, ",".join([str(i) for i in pil_numpy.flatten() if i != 0]))
        pil_numpy = np.array(pil)
        
        if len(pil_numpy.shape) == 2:
            if self.edge_map and mode == "image":
                pil_numpy = cv2.Canny(pil_numpy, 100, 200)
            #show("edge",pil_numpy)
            pil_numpy = to_rgb(pil_numpy)
            #pil_numpy = np.tile(pil_numpy,3).reshape(pil_numpy.shape+(-1,))
        elif pil_numpy.shape[2] == 4:

            #show("sketch",pil_numpy[:,:,3])
            pil_numpy = to_rgb(pil_numpy[:,:,3])
            #pil_numpy = np.tile(pil_numpy[:,:,3],3).reshape(pil_numpy.shape[0:2]+(-1,))
            #pil_numpy[:,:,2] = 0
        if self.opt.image_type == 'EDGE':
            gray_pil = Image.fromarray(pil_numpy)
            pil_numpy = np.array(gray_pil.convert('L'))
            pil_numpy = to_rgb(pil_numpy)
        pil_numpy = cv2.resize(pil_numpy,(self.opt.scale_size,self.opt.scale_size))
        if self.transform_fun is not None:
            pil_numpy = self.transform_fun(pil_numpy)
        #data_info.write(",".join([str(i) for i in pil_numpy.numpy().flatten() if i != 0])+"\n")
        return pil_numpy
Пример #2
0
 def transform(self, pil):
     pil = pil.convert('RGB')
     pil_numpy = np.array(pil)
     if len(pil_numpy.shape) == 2:
         pil_numpy = to_rgb(pil_numpy)
     elif pil_numpy.shape[2] == 4:
         pil_numpy = to_rgb(pil_numpy[:,:,3])
     pil_numpy = cv2.resize(pil_numpy,(self.opt.scale_size, self.opt.scale_size))
     if self.transform_fun is not None:
         pil = Image.fromarray(pil_numpy)
         pil_numpy = self.transform_fun(pil)
     return pil_numpy
Пример #3
0
    def load_image(self, pil):
        def show(mode, pil_numpy):
            print(
                mode,
                len(",".join([str(i) for i in pil_numpy.flatten() if i != 0])))

        if self.opt.image_type == 'RGB':
            pil = pil.convert('RGB')
            pil_numpy = np.array(pil)
        elif self.opt.image_type == 'GRAY':
            pil = pil.convert('L')
            pil_numpy = np.array(pil)
        elif self.opt.image_type == 'EDGE':
            pil = pil.convert('L')
            pil_numpy = np.array(pil)
            #show('edge', pil_numpy)
            pil_numpy = cv2.Canny(pil_numpy, 0, 200)

        if 'densenet' in self.opt.feature_model and not self.opt.image_type == 'RGB':
            pil_numpy = to_rgb(pil_numpy)
        #print('image{}'.format(pil_numpy.shape))
        #if self.opt.image_type == 'GRAY' or self.opt.image_type == 'EDGE':
        #    pil_numpy = pil_numpy.reshape(pil_numpy.shape + (1,))
        #pil_numpy = cv2.resize(pil_numpy, (self.opt.scale_size, self.opt.scale_size))
        #if self.opt.sketch_type == 'GRAY' or self.opt.image_type == 'EDGE':
        #    pil_numpy = pil_numpy.reshape(pil_numpy.shape[:2])
        transform_fun = self.transform_fun if self.mode == 'train' else self.test_transform_fun
        if transform_fun is not None:
            pil = Image.fromarray(pil_numpy)
            pil_numpy = transform_fun(pil)
        return pil_numpy
Пример #4
0
    def transform(self, pil):
        pil = pil.convert('RGB')
        pil_numpy = np.array(pil)
        if len(pil_numpy.shape) == 2:
            pil_numpy = to_rgb(pil_numpy)
            #pil_numpy = np.tile(pil_numpy,3).reshape(pil_numpy.shape+(-1,))
        elif pil_numpy.shape[2] == 4:
            pil_numpy = to_rgb(pil_numpy[:, :, 3])
            #pil_numpy = np.tile(pil_numpy[:,:,3],3).reshape(pil_numpy.shape[0:2]+(-1,))
            #pil_numpy[:,:,2] = 0
        pil_numpy = cv2.resize(pil_numpy,
                               (self.opt.scale_size, self.opt.scale_size))

        if self.transform_fun is not None:
            pil = Image.fromarray(pil_numpy)
            pil_numpy = self.transform_fun(pil)
        #data_info.write(",".join([str(i) for i in pil_numpy.numpy().flatten() if i != 0])+"\n")
        return pil_numpy
Пример #5
0
    def load_sketch(self, pil):
        def show(mode, pil_numpy):
            print(mode, len(",".join([str(i) for i in pil_numpy.flatten() if i != 0])))
        pil = pil.convert('L')
        pil_numpy = np.array(pil)

        if self.opt.sketch_type == 'RGB' or 'densenet' in self.opt.feature_model:
            pil_numpy = to_rgb(pil_numpy)

        transform_fun = self.transform_fun if self.mode == 'train' else self.test_transform_fun
        if transform_fun is not None:
            pil = Image.fromarray(pil_numpy)
            pil_numpy = transform_fun(pil)

        return pil_numpy
Пример #6
0
    def load_image(self, pil):
        def show(mode, pil_numpy):
            print(mode, len(",".join([str(i) for i in pil_numpy.flatten() if i != 0])))

        if self.opt.image_type == 'RGB':
            pil = pil.convert('RGB')
            pil_numpy = np.array(pil)
        elif self.opt.image_type == 'GRAY':
            pil = pil.convert('L')
            pil_numpy = np.array(pil)
        elif self.opt.image_type == 'EDGE':
            pil = pil.convert('L')
            pil_numpy = np.array(pil)
            #show('edge', pil_numpy)
            pil_numpy = cv2.Canny(pil_numpy, 0, 200)

        if 'densenet' in self.opt.feature_model and not self.opt.image_type == 'RGB':
            pil_numpy = to_rgb(pil_numpy)

        transform_fun = self.transform_fun if self.mode == 'train' else self.test_transform_fun
        if transform_fun is not None :
            pil = Image.fromarray(pil_numpy)
            pil_numpy = transform_fun(pil)
        return pil_numpy