示例#1
0
 def test_grayscale_to_bits(self):
     images = np.array([[range(10)]*10]*100)
     patches = utils.extract_patches(images, (2, 2), patches_nr=15)
     patches = utils.grayscale_to_bits(patches)
     for patch in patches:
         self.assertIsInstance(patch, np.ndarray)
         self.assertEqual(patch.dtype, np.bool)
示例#2
0
 def test_extract_patches(self):
     images = np.array([[range(10)]*10]*100)
     patches = utils.extract_patches(images, (2, 2), patches_nr=15)
     for patch in patches:
         patch_in_image = False
         for image in images:
             for y, row in enumerate(image[:-1]):
                 for x, _ in enumerate(row[:-1]):
                     if (patch == image[y:y+2, x:x+2]).all():
                         patch_in_image = True
                         break
                 if patch_in_image:
                     # patch found, stop iterating over rows
                     break
             if patch_in_image:
                 # patch found, stop iterating over images
                 break
         self.assertTrue(patch_in_image)
示例#3
0
 def test_rebuild_imgs_from_patches(self):
     images = np.random.randint(0, 256, 3 * 256**2).reshape((3, 256, 256))
     patches = utils.extract_patches(images, (16, 16), 3 * 256, False)
     rec_imgs = utils.rebuild_imgs_from_patches(patches, (256, 256))
     self.assertListEqual(images.tolist(), rec_imgs.tolist())