示例#1
0
 def create_lut(self):
     for op in ('corner', 'dilation4', 'dilation8', 'erosion4', 'erosion8',
                'edge'):
         lb = ImageMorph.LutBuilder(op_name=op)
         lut = lb.build_lut()
         with open('Tests/images/%s.lut' % op, 'wb') as f:
             f.write(lut)
示例#2
0
    def test_lut(self):
        for op in ('corner', 'dilation4', 'dilation8', 'erosion4', 'erosion8',
                   'edge'):
            lb = ImageMorph.LutBuilder(op_name=op)
            self.assertIsNone(lb.get_lut())

            lut = lb.build_lut()
            with open('Tests/images/%s.lut' % op, 'rb') as f:
                self.assertEqual(lut, bytearray(f.read()))
示例#3
0
    def test_set_lut(self):
        # Arrange
        lb = ImageMorph.LutBuilder(op_name='corner')
        lut = lb.build_lut()
        mop = ImageMorph.MorphOp()

        # Act
        mop.set_lut(lut)

        # Assert
        self.assertEqual(mop.lut, lut)
示例#4
0
    def test_pattern_syntax_error(self):
        # Arrange
        lb = ImageMorph.LutBuilder(op_name='corner')
        new_patterns = ['a pattern with a syntax error']
        lb.add_patterns(new_patterns)

        # Act / Assert
        with self.assertRaises(Exception) as e:
            lb.build_lut()
        self.assertEqual(
            str(e.exception),
            'Syntax error in pattern "a pattern with a syntax error"')
示例#5
0
    def test_add_patterns(self):
        # Arrange
        lb = ImageMorph.LutBuilder(op_name='corner')
        self.assertEqual(lb.patterns,
                         ['1:(... ... ...)->0', '4:(00. 01. ...)->1'])
        new_patterns = ['M:(00. 01. ...)->1', 'N:(00. 01. ...)->1']

        # Act
        lb.add_patterns(new_patterns)

        # Assert
        self.assertEqual(lb.patterns, [
            '1:(... ... ...)->0', '4:(00. 01. ...)->1', 'M:(00. 01. ...)->1',
            'N:(00. 01. ...)->1'
        ])
示例#6
0
    def test_wrong_mode(self):
        lut = ImageMorph.LutBuilder(op_name='corner').build_lut()
        imrgb = Image.new('RGB', (10, 10))
        iml = Image.new('L', (10, 10))

        with self.assertRaises(RuntimeError):
            _imagingmorph.apply(bytes(lut), imrgb.im.id, iml.im.id)

        with self.assertRaises(RuntimeError):
            _imagingmorph.apply(bytes(lut), iml.im.id, imrgb.im.id)

        with self.assertRaises(RuntimeError):
            _imagingmorph.match(bytes(lut), imrgb.im.id)

        # Should not raise
        _imagingmorph.match(bytes(lut), iml.im.id)