示例#1
0
    def _loadToArray(self, imagePath):
        """
        Creates input array. Applies scale factor to each image.
        """
        try:
            image = PIL.Image.open(imagePath)
        except IOError as e:
            #print("Trying to open by converting to png")
            png = os.path.splitext(imagePath)[0] + '.png'
            wand.image.Image(filename=imagePath).convert('PNG').save(filename=png)
            image = PIL.Image.open(png)

        #resize
        scaleFactor = np.divide(self.imageSize, image.size)
        newSize = tuple(round(x * s) for x, s in zip(image.size, scaleFactor))
        image.thumbnail(newSize)

        #greyscale
        image = image.convert('L')

        # neurolab seems to expect 1d input, so rescale the images in the
        # input array as linear (the network does't know about shape anyway)
        imageArray = np.array(image)
        newSize = mul(*imageArray.shape)
        return imageArray.reshape(newSize)
示例#2
0
文件: utils.py 项目: Vitor-Tx/kinobot
def thumbnail_images(images):
    """
    :param images: list of PIL.Image objects
    """
    sizes = [image.size for image in images]
    for image in images:
        if image.size != min(sizes):
            image.thumbnail(min(sizes))
        yield image
示例#3
0
def _loadToArray(imagePath):
    try:
        image = PIL.Image.open(imagePath)
    except IOError as e:
        print("Trying to open by converting to png")
        png = os.path.splitext(imagePath)[0] + '.png'
        wand.image.Image(filename=imagePath).convert('PNG').save(filename=png)
        image = PIL.Image.open(png)

    #resize
    newSize = tuple(x * scaleFactor for x in image.size)
    image.thumbnail(newSize)

    #greyscale
    image = image.convert('F')

    return np.array(image)