Esempio n. 1
0
 def test_plain(self):
     img = array([
         [
             [1],
             [1],
             [1],
             [1],
             [1],
         ],
         [
             [1],
             [1],
             [0],
             [1],
             [1],
         ],
         [
             [1],
             [0],
             [0],
             [0],
             [1],
         ],
         [
             [1],
             [1],
             [1],
             [1],
             [1],
         ],
         [
             [1],
             [1],
             [1],
             [1],
             [1],
         ],
     ])
     result = image.crop_background(img, bg_intensity=1)
     expected = array([
         [
             [1],
             [0],
             [1],
         ],
         [
             [0],
             [0],
             [0],
         ],
     ])
     self.assertEqual(expected.tolist(), result.tolist())
Esempio n. 2
0
 def test_multichannel(self):
     img = array([
         [
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
         ],
         [
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [0.01, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
         ],
         [
             [1, 0.5, 0.3],
             [0, 0.5, 0.31],
             [0, 0.51, 0.31],
             [0, 0.5, 0.29],
             [1, 0.5, 0.3],
         ],
         [
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
         ],
         [
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
             [1, 0.5, 0.3],
         ],
     ])
     result = image.crop_background(img, bg_intensity=[1, 0.5, 0.3])
     expected = array([
         [
             [1, 0.5, 0.3],
             [0.01, 0.5, 0.3],
             [1, 0.5, 0.3],
         ],
         [
             [0, 0.5, 0.31],
             [0, 0.51, 0.31],
             [0, 0.5, 0.29],
         ],
     ])
     self.assertEqual(expected.tolist(), result.tolist())
Esempio n. 3
0
 def test_edge_intensity(self):
     img = array([
         [
             [1.01],
             [1.01],
             [1.01],
             [1.01],
             [1.01],
         ],
         [
             [0.99],
             [0.96],
             [0.02],
             [0.96],
             [0.99],
         ],
         [
             [0.96],
             [0.05],
             [0.01],
             [0.06],
             [0.96],
         ],
         [
             [0.99],
             [0.97],
             [0.97],
             [0.97],
             [0.99],
         ],
         [
             [0.99],
             [0.99],
             [0.99],
             [0.99],
             [0.99],
         ],
     ])
     result = image.crop_background(img, bg_intensity=1, sim_threshold=0.1)
     expected = array([
         [
             [0.96],
             [0.02],
             [0.96],
         ],
         [
             [0.05],
             [0.01],
             [0.06],
         ],
     ])
     self.assertEqual(expected.tolist(), result.tolist())
Esempio n. 4
0
 def test_no_background(self):
     img = array([
         [
             [0],
             [0],
             [0],
             [0],
             [0],
         ],
         [
             [0],
             [0],
             [0],
             [0],
             [0],
         ],
         [
             [0],
             [0],
             [0],
             [0],
             [0],
         ],
         [
             [0],
             [0],
             [0],
             [0],
             [0],
         ],
         [
             [0],
             [0],
             [0],
             [0],
             [0],
         ],
     ])
     result = image.crop_background(img, bg_intensity=1)
     self.assertEqual(img.tolist(), result.tolist())