def test_load_file(self):
     """
     Load an image from a file.
     """
     im = Image.fromarray(self.pixels, mode='RGB')
     _, filename = tempfile.mkstemp(suffix='.png')
     im.save(filename)
     im = image_utils.load(filename)
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))
 def test_load_file(self):
     """
     Load an image from a file.
     """
     im = Image.fromarray(self.pixels, mode="RGB")
     _, filename = tempfile.mkstemp(suffix=".png")
     im.save(filename)
     im = image_utils.load(filename)
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))
 def test_load_string(self):
     """
     Load an image from binary string.
     """
     im = Image.fromarray(self.pixels, mode='RGB')
     _, filename = tempfile.mkstemp(suffix='.png')
     im.save(filename)
     with open(filename) as f:
         string = f.read()
     im = image_utils.load(string)
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))
 def test_load_string(self):
     """
     Load an image from binary string.
     """
     im = Image.fromarray(self.pixels, mode="RGB")
     _, filename = tempfile.mkstemp(suffix=".png")
     im.save(filename)
     with open(filename) as f:
         string = f.read()
     im = image_utils.load(string)
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))
示例#5
0
    def _featurize(self, mol):
        """
        Generate a 2D depiction of a molecule.

        Parameters
        ----------
        mol : RDKit Mol
            Molecule.
        """
        dim = (self.size, self.size)
        if self.engine == 'obabel':
            image = ob_utils.MolImage(self.size)(mol)
        elif self.engine == 'rdkit':
            image = Draw.MolToImage(mol, dim, fitImage=True)
            image = image.convert('RGB')  # drop alpha channel
        else:
            raise NotImplementedError(self.engine)
        pixels = image_utils.get_pixels(image)
        if self.flatten:
            pixels = pixels.ravel()
        return pixels
 def test_get_pixels(self):
     """
     Read pixels from image.
     """
     im = Image.fromarray(self.pixels, mode='RGB')
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))
 def test_get_pixels(self):
     """
     Read pixels from image.
     """
     im = Image.fromarray(self.pixels, mode="RGB")
     assert np.array_equal(self.pixels, image_utils.get_pixels(im))