Пример #1
0
 def test_show_list(self, mk_show):
     """
     Test show calls _show method in Image just once with the right args.
     Test with a list of images as input.
     """
     a = matrix2img(gray2rgb(np.array([[0, 0.5, 0.8], [1, 0.3, 0.7]])))
     b = matrix2img(np.array([[0, 0.5, 0.8], [1, 0.3, 0.7], [1, 0.3, 0.7]]))
     c = matrix2img(gray2rgb(np.array([[0.5, 0.8], [0.3, 0.7], [0.3,
                                                                0.7]])))
     show([a, b, c])
     expected = [
         mock.call(a, command=None, title=None),
         mock.call(b, command=None, title=None),
         mock.call(c, command=None, title=None)
     ]
     mk_show.assert_has_calls(expected)
Пример #2
0
 def test_show_single_float(self, mk_show):
     """
     Test show calls _show method in Image just once with the right args.
     Test with a single float64 image as input.
     """
     a = np.array([[0, 0.5, 0.8], [1, 0.3, 0.7]])
     a = matrix2img(gray2rgb(a))
     show(a)
     mk_show.assert_called_once_with(a, command=None, title=None)
Пример #3
0
    def test_save_list_img(self):
        """
        Test save calls the save() method of each input images with the realtive
        paths.
        """
        a = matrix2img(gray2rgb(np.array([[0, 0.5, 0.8], [1, 0.3, 0.7]])))
        b = matrix2img(np.array([[0, 0.5, 0.8], [1, 0.3, 0.7], [1, 0.3, 0.7]]))
        c = matrix2img(gray2rgb(np.array([[0.5, 0.8], [0.3, 0.7], [0.3,
                                                                   0.7]])))
        a_path = 'custom/path/a.jpg'
        b_path = 'custom/path/b.jpg'
        c_path = 'custom/path/c.jpg'

        with mock.patch.object(a, 'save') as mka:
            with mock.patch.object(b, 'save') as mkb:
                with mock.patch.object(c, 'save') as mkc:
                    save([a, b, c], [a_path, b_path, c_path])
                    mka.assert_called_once_with(a_path)
                    mkb.assert_called_once_with(b_path)
                    mkc.assert_called_once_with(c_path)
Пример #4
0
    def test_save_single_img(self):
        """
        Test save calls the save() method of the input image once and with the
        given path.
        """
        a = matrix2img(gray2rgb(np.array([[0, 0.5, 0.8], [1, 0.3, 0.7]])))
        path = 'custom/path'

        with mock.patch.object(a, 'save') as mk_save:
            save(a, path)
            mk_save.assert_called_once_with(path)
Пример #5
0
 def test_img2matrix_2Dimg(self):
     """
     Test img2matrix with a gray image as input.
     """
     matrix = np.asarray([[0., 1., .2, .3, .4], [.5, .8, .7, .8, .9],
                          [1., .0, .2, .3, .4], [.5, .7, .9, .9, .8]])
     img = matrix2img(matrix)
     result = img2matrix(img)
     # type
     self.assertTrue(isinstance(result, np.ndarray))
     # dimensions
     assert_array_equal(matrix.shape, result.shape)
     # values
     assert_array_equal(matrix, np.around(result, decimals=1))
Пример #6
0
 def test_matrix2img_3Dimg(self):
     """
     Test matrix2img with an RGB image as input.
     """
     matrix = np.asarray([[0., 1., .2, .3, .4], [.5, .8, .7, .8, .9],
                          [1., .0, .2, .3, .4], [.5, .7, .9, .9, .8]])
     img = Image.fromarray(gray2rgb(matrix), 'RGB')
     result = matrix2img(img)
     # type
     self.assertTrue(isinstance(result, Image.Image))
     # dimensions
     assert_array_equal(img.size, result.size)
     # values
     assert_array_equal(img, result)
Пример #7
0
 def test_matrix2img_2Dmatrix(self):
     """
     Test matrix2img with a 2d matrix as input.
     """
     matrix = np.asarray([[0., 1., .2, .3, .4], [.5, .8, .7, .8, .9],
                          [1., .0, .2, .3, .4], [.5, .7, .9, .9, .8]])
     result = matrix2img(matrix)
     # type
     self.assertTrue(isinstance(result, Image.Image))
     # dimensions
     assert_array_equal(matrix.shape[::-1], result.size)
     # values
     expected = np.uint8(matrix * 255)
     assert_array_equal(expected, np.asarray(result))