Beispiel #1
0
    def test_resize_crop_xx_large_size_image(self):

        self.cleanUp()

        # test cat2.jpg: size: 5100 x 2869
        imagePath = './images/cat4.jpg'
        img = Image.open(imagePath)
        x, y = tiler.getImageSize(img)
        level = tiler.getTotalLevel(x, y)
        levels = tiler.calcAllLevelsSize(x, y, level)
        outputPath = './output'

        tiler.resizeAndCropImage(img, levels, outputPath)

        # check total tiles in each level
        self.assertEqual(len(os.listdir('./output/13')), 240)
        self.assertEqual(len(os.listdir('./output/12')), 60)
        self.assertEqual(len(os.listdir('./output/11')), 15)
        self.assertEqual(len(os.listdir('./output/10')), 6)
        self.assertEqual(len(os.listdir('./output/9')), 2)
        self.assertEqual(len(os.listdir('./output/8')), 1)
        self.assertEqual(len(os.listdir('./output/0')), 1)

        # image size in level 0 should be (1, 1)
        img = Image.open('./output/0/0_0.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual((actual_x, actual_y), (1, 1))
Beispiel #2
0
    def test_resize_crop_medium_size_png_image(self):

        self.cleanUp()

        # test cat1.png, size: 987 x 660
        imagePath = './images/cat1.png'
        img = Image.open(imagePath)
        img = img.convert("RGB")
        x, y = tiler.getImageSize(img)
        level = tiler.getTotalLevel(x, y)
        levels = tiler.calcAllLevelsSize(x, y, level)
        outputPath = './output'

        tiler.resizeAndCropImage(img, levels, outputPath)

        # check total tiles in each level
        self.assertEqual(len(os.listdir('./output/10')), 12)
        self.assertEqual(len(os.listdir('./output/9')), 4)
        self.assertEqual(len(os.listdir('./output/8')), 1)
        self.assertEqual(len(os.listdir('./output/0')), 1)

        # check file size for edge ones
        # top right
        img = Image.open('./output/10/768_0.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual(actual_x, 219)
        self.assertEqual(actual_y, 256)
        # bottom right
        img = Image.open('./output/10/768_512.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual(actual_x, 219)
        self.assertEqual(actual_y, 148)
        # bottom left
        img = Image.open('./output/10/0_512.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual(actual_x, 256)
        self.assertEqual(actual_y, 148)

        # image size in level 0 should be (1, 1)
        img = Image.open('./output/0/0_0.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual((actual_x, actual_y), (1, 1))
Beispiel #3
0
    def test_resize_crop_large_size_image(self):

        self.cleanUp()

        # test cat2.jpg: size: 1920 x 1440
        imagePath = './images/cat2.jpg'
        img = Image.open(imagePath)
        x, y = tiler.getImageSize(img)
        level = tiler.getTotalLevel(x, y)
        levels = tiler.calcAllLevelsSize(x, y, level)
        outputPath = './output'

        tiler.resizeAndCropImage(img, levels, outputPath)

        # check total tiles in each level
        self.assertEqual(len(os.listdir('./output/11')), 48)
        self.assertEqual(len(os.listdir('./output/10')), 12)
        self.assertEqual(len(os.listdir('./output/9')), 4)
        self.assertEqual(len(os.listdir('./output/8')), 1)
        self.assertEqual(len(os.listdir('./output/0')), 1)

        # check file size for edge ones
        # top right
        img = Image.open('./output/11/1792_0.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual(actual_x, 128)
        self.assertEqual(actual_y, 256)
        # bottom right in level 11
        img = Image.open('./output/11/1792_1280.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual(actual_x, 128)
        self.assertEqual(actual_y, 160)
        # bottom right in level 10
        img = Image.open('./output/10/768_512.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual(actual_x, 192)
        self.assertEqual(actual_y, 208)

        # image size in level 0 should be (1, 1)
        img = Image.open('./output/0/0_0.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual((actual_x, actual_y), (1, 1))
Beispiel #4
0
    def test_tiler_tiff_image(self):

        # test cat5.tiff, size: 987 x 660
        imagePath = './images/cat5'

        tiler.parse(imagePath + '.tiff')

        # check total tiles in each level
        self.assertEqual(len(os.listdir(imagePath + '/10')), 12)
        self.assertEqual(len(os.listdir(imagePath + '/9')), 4)
        self.assertEqual(len(os.listdir(imagePath + '/8')), 1)
        self.assertEqual(len(os.listdir(imagePath + '/0')), 1)

        # check file size for edge ones
        # top right
        img = Image.open(imagePath + '/10/768_0.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual(actual_x, 219)
        self.assertEqual(actual_y, 256)
        # bottom right
        img = Image.open(imagePath + '/10/768_512.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual(actual_x, 219)
        self.assertEqual(actual_y, 148)
        # bottom left
        img = Image.open(imagePath + '/10/0_512.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual(actual_x, 256)
        self.assertEqual(actual_y, 148)

        # image size in level 0 should be (1, 1)
        img = Image.open(imagePath + '/0/0_0.jpg')
        actual_x, actual_y = tiler.getImageSize(img)
        self.assertEqual((actual_x, actual_y), (1, 1))

        # clean up
        if path.exists(imagePath):
            shutil.rmtree(imagePath)
Beispiel #5
0
    def test_get_size(self):
        img = Image.open('./images/cat1.png')
        x, y = tiler.getImageSize(img)

        self.assertEqual(x, 987)
        self.assertEqual(y, 660)