serious test for kernel filters

This commit is contained in:
Alexander 2017-08-12 23:22:59 +03:00
parent 5f5ac09158
commit 847dd67a41
4 changed files with 25 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -94,6 +94,28 @@ class TestImageFilter(PillowTestCase):
self.assertEqual(rankfilter.size, 1)
self.assertEqual(rankfilter.rank, 2)
def test_consistency_3x3(self):
im = Image.open("Tests/images/hopper.bmp")
emboss = im.filter(ImageFilter.Kernel((3, 3),
(-1, -1, 0,
-1, 0, 1,
0, 1, 1), .3))
self.assert_image_equal(
emboss, Image.open("Tests/images/hopper_emboss.bmp"))
def test_consistency_5x5(self):
im = Image.open("Tests/images/hopper.bmp")
emboss = im.filter(ImageFilter.Kernel((5, 5),
(-1, -1, -1, -1, 0,
-1, -1, -1, 0, 1,
-1, -1, 0, 1, 1,
-1, 0, 1, 1, 1,
0, 1, 1, 1, 1), 0.3))
self.assert_image_equal(
emboss, Image.open("Tests/images/hopper_emboss_more.bmp"))
if __name__ == '__main__':
unittest.main()

View File

@ -92,6 +92,9 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
if (!imOut)
return NULL;
// Add one time for rounding
offset += 0.5;
/* brute force kernel implementations */
#define KERNEL3x3(image, kernel, d) ( \
(int) image[y+1][x-d] * kernel[0] + \