Ejemplo n.º 1
0
 def test_getitem_with_step(self):
     h, w = 5, 5
     array = _array_2d_to_RGB(np.linspace(0, 255, h * w).reshape(h, w))
     pic = novice.Picture(array=array)
     sliced_pic = pic[::2, ::2]
     assert_equal(sliced_pic._image,
                  novice.Picture(array=array[::2, ::2])._image)
Ejemplo n.º 2
0
    def test_modified_on_set_pixel(self):
        data = np.zeros(shape=(10, 5, 3), dtype=np.uint8)
        pic = novice.Picture(array=data)

        pixel = pic[0, 0]
        pixel.green = 1
        assert pic.modified
Ejemplo n.º 3
0
    def test_picture_slice(self):
        array = _array_2d_to_RGB(np.arange(0, 10)[np.newaxis, :])
        pic = novice.Picture(array=array)

        x_slice = slice(3, 8)
        subpic = pic[:, x_slice]
        assert_allclose(subpic._image, array[x_slice, :])
Ejemplo n.º 4
0
    def test_move_slice(self):
        h, w = 3, 12
        array = _array_2d_to_RGB(np.linspace(0, 255, h * w).reshape(h, w))
        array = array.astype(np.uint8)

        pic = novice.Picture(array=array)
        pic_orig = novice.Picture(array=array.copy())

        # Move left cut of image to the right side.
        cut = 5
        rest = pic.width - cut
        temp = pic[:cut, :]
        temp._image = temp._image.copy()
        pic[:rest, :] = pic[cut:, :]
        pic[rest:, :] = temp

        assert_equal(pic[rest:, :]._image, pic_orig[:cut, :]._image)
        assert_equal(pic[:rest, :]._image, pic_orig[cut:, :]._image)
Ejemplo n.º 5
0
    def test_update_on_save(self):
        pic = novice.Picture(array=np.zeros((3, 3, 3)))
        pic.size = (6, 6)
        assert pic.modified
        assert pic.path is None

        with tempfile.NamedTemporaryFile(suffix=".jpg") as tmp:
            pic.save(tmp.name)

            assert not pic.modified
            assert_equal(pic.path, os.path.abspath(tmp.name))
            assert_equal(pic.format, "jpeg")
Ejemplo n.º 6
0
 def test_modified_on_set(self):
     pic = novice.Picture(self.small_sample_path)
     pic[0, 0] = (1, 1, 1)
     assert pic.modified
     assert pic.path is None