本文整理汇总了Python中ImageUtils.ImageUtils.splitImageIntoChunks方法的典型用法代码示例。如果您正苦于以下问题:Python ImageUtils.splitImageIntoChunks方法的具体用法?Python ImageUtils.splitImageIntoChunks怎么用?Python ImageUtils.splitImageIntoChunks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageUtils.ImageUtils
的用法示例。
在下文中一共展示了ImageUtils.splitImageIntoChunks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import splitImageIntoChunks [as 别名]
class Ambilight:
def __init__(self, led_num, border):
self.NUMLED = led_num
self.BORDER = border
self.imageUtils = ImageUtils()
self.currentColors = collections.OrderedDict()
self.current_image_all = None
def run(self):
self.current_image_all = self.imageUtils.concatStripe(self.imageUtils.makeImagesOfCorners(self.BORDER))
self.currentColors = self.__calcColors()
def __save(self, im, name):
im.save(name, "PNG")
def __calcColors(self):
currentColors = collections.OrderedDict()
for i, chunk in enumerate(self.imageUtils.splitImageIntoChunks(self.current_image_all, self.NUMLED), 0):
currentColors[i] = ImageStat.Stat(chunk)._getmean()
return currentColors
示例2: ImageUtilsTest
# 需要导入模块: from ImageUtils import ImageUtils [as 别名]
# 或者: from ImageUtils.ImageUtils import splitImageIntoChunks [as 别名]
class ImageUtilsTest(unittest.TestCase):
def setUp(self):
self.image1 = Image.open('test1.png')
# test2.png Breite: 200px # Hoehe: 220px
self.image2 = Image.open('test2.png')
self.imageUtils = ImageUtils()
def test_makeImagesOfCorners_numbe_of_elements(self):
images = self.imageUtils.makeImagesOfCorners(50)
self.assertEqual(4, len(images))
def test_makeImagesOfCorners_size(self):
border = 50
top, right, bottom, left = self.imageUtils.makeImagesOfCorners(border)
self.assertEqual(top.size, (self.imageUtils.getScreenSize()[0], border))
self.assertEqual(right.size, (border, self.imageUtils.getScreenSize()[1]))
self.assertEqual(bottom.size, (self.imageUtils.getScreenSize()[0], border))
self.assertEqual(left.size, (border, self.imageUtils.getScreenSize()[1]))
def test_makeImagesOfCorners_small_border(self):
with self.assertRaises(ValueError):
self.imageUtils.makeImagesOfCorners(0)
self.imageUtils.makeImagesOfCorners(-1)
def test_concat_too_few(self):
with self.assertRaises(ValueError):
self.imageUtils.concat(())
self.imageUtils.concat((self.image1))
def test_concat_proper_size(self):
images = (self.image2, self.image2)
concated = self.imageUtils.concat(images)
width_expected = 200 + 200
height_expected = 220
width_actual, height_actual = concated.size
self.assertEqual(width_expected, width_actual)
self.assertEqual(height_expected, height_actual)
def test_concat_stripe_proper_size(self):
images = (self.image2, self.image2)
concated = self.imageUtils.concatStripe(images)
width_expected = 220 + 220
height_expected = 200
width_actual, height_actual = concated.size
# TODO:
# self.assertEqual( width_expected, width_actual )
# self.assertEqual( height_expected, height_actual )
def test_split_images_into_chunks_number_of_elements(self):
count = 4
chunks = self.imageUtils.splitImageIntoChunks(self.image2, count)
self.assertEqual(count, len(chunks))
def test_split_images_into_chunks_width(self):
count = 4
chunks = self.imageUtils.splitImageIntoChunks(self.image2, count)
expected_width_per_chunk = self.image2.size[0] / count;
[self.assertEqual(expected_width_per_chunk, image.size[0]) for image in chunks]
def test_split_images_into_chunks_width2(self):
count = 4
chunks = self.imageUtils.splitImageIntoChunks(self.image1, count)
chunks.pop(len(chunks) - 1)
expected_width_per_chunk = self.image2.size[0] / count;
[image.show() for image in chunks]
[self.assertEqual(expected_width_per_chunk, image.size[0]) for image in chunks]