Exemplo n.º 1
0
    def __init__(self, 
        data,
        pathnameback=None,
        ext='jpg',
        count=None,
        num_channels=3,
        generate='image_and_mask',
        iluminate=True, angle=45, translation=0.3, warp=0.1, factor=0.2,
        transform_image=None,
        transform_data=None,
        ):
        """Initialization           
        """            
              
        self.data = data
        self.bbackimage = pathnameback != None
        self.databack = None

        if count is None:
            count = len(data)
        
        if self.bbackimage: 
            pathnameback  = os.path.expanduser( pathnameback )
            self.databack = imutl.imageProvide( pathnameback, ext=ext ) 
        
        self.num_classes=data.numclass
        self.labels = data.labels
        self.num_channels = num_channels
        self.generate = generate
        self.ren = Generator( iluminate, angle, translation, warp, factor )        
        self.count=count
        
        self.transform_image = transform_image 
        self.transform_data = transform_data 
Exemplo n.º 2
0
def test_dataset_generator():

    data = FactoryDataset.factory(pathname=os.path.expanduser('~/.datasets/'),
                                  name=FactoryDataset.ck,
                                  subset=FactoryDataset.training,
                                  download=True)

    ren = Generator()
    img, y = data[np.random.randint(len(data))]
    img = np.stack((img, img, img), axis=2)

    idx = 1
    pathname = os.path.expanduser('~/.datasets/coco')
    data_back = imutl.imageProvide(pathname, ext='jpg')
    back = data_back[(idx) % len(data_back)]
    back = F.resize_image(back,
                          640,
                          1024,
                          resize_mode='crop',
                          interpolate_mode=cv2.INTER_LINEAR)
    #back = back[:,:,0]
    #back = np.random.randint(255, size=(640, 1024) )

    print(img.shape, img.max())
    print(back.shape, back.max())

    image, image_ilu, mask, h = ren.generate(img, back)
    print(image.shape, image.max())
    print(mask.shape, mask.max())
Exemplo n.º 3
0
    def __init__(
        self,
        data,
        pathnameback=None,
        ext='jpg',
        count=None,
        num_channels=3,
        generate='image_and_mask',
        iluminate=True,
        angle=45,
        translation=0.3,
        warp=0.1,
        factor=0.2,
        transform_image=None,
        transform_data=None,
    ):
        """Initialization
        :params
            pathnameback: when it is none, background is white
            count: trainiteration/testiteration, to generate more images with different background

        """
        # Assign all self variables for later.
        self.data = data
        self.bbackimage = pathnameback != None
        self.databack = None

        if count is None:
            count = len(data)

        # If the user gives us a place to save these images, do so.
        if self.bbackimage:
            pathnameback = os.path.expanduser(pathnameback)
            self.databack = imutl.imageProvide(pathnameback, ext=ext)

        self.num_classes = data.numclass
        self.labels = data.labels
        self.num_channels = num_channels
        self.generate = generate
        self.ren = Generator(iluminate, angle, translation, warp, factor)
        self.count = count

        self.transform_image = transform_image
        self.transform_data = transform_data
def test_dataset_generator():

    data = FactoryDataset.factory(pathname='~/.datasets/',
                                  name=FactoryDataset.bu3dfe,
                                  subset=FactoryDataset.training,
                                  download=True)

    ren = Generator()
    img, y = data[np.random.randint(len(data))]
    img = np.stack((img, img, img), axis=2)

    idx = 1
    pathname = os.path.expanduser('~/.datasets/photo')
    data_back = imutl.imageProvide(pathname, ext='jpg')
    back = data_back[(idx) % len(data_back)]
    back = F.resize_image(back,
                          640,
                          1024,
                          resize_mode='crop',
                          interpolate_mode=cv2.INTER_LINEAR)
    #back = back[:,:,0]
    #back = np.random.randint(255, size=(640, 1024) )

    print(img.shape, img.max())
    print(back.shape, back.max())

    image, mask = ren.generate(img, back)
    print(image.shape, image.max())
    print(mask.shape, mask.max())

    plt.figure()
    plt.subplot(121)
    plt.imshow(image.mean(axis=2), cmap='gray')
    plt.subplot(122)
    plt.imshow(mask[:, :, 0])
    plt.show()
Exemplo n.º 5
0
 def __init__(self, pathname, ext, num_channels=1, transform=None ):       
     self.data = imageProvide(pathname, ext )        
     self.transform = transform   
     self.num_channels = num_channels