コード例 #1
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
    def test_resize_invalid_interpolation(self):
        """.resize() should raise ValueError when interpolation is invalid"""
        file = str(SAMPLE_IMAGES[0])
        img = Image.from_file(file)

        with pytest.raises(ValueError):
            img.resize((224, 224), interpolation="NOT_EXIST")
コード例 #2
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
    def test_resize_bw(self):
        """Test bw image resize, it should keep original name"""
        file = str(IMAGE_BW)
        img = Image.from_file(file)
        assert not img.is_color
        assert img.shape != (100, 400)

        resize = img.resize((100, 400))
        assert img.name == resize.name
        assert resize.shape == (100, 400)
コード例 #3
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
    def test_save_to_file(self, tmp_path: pathlib.Path, sample):
        file = str(sample)
        img = Image.from_file(file)

        file_name = "test_save_file.png"
        file = tmp_path.joinpath(file_name)
        img.save(str(file))

        assert file.is_file()
        cv2_read = cv2.imread(str(file), flags=cv2.IMREAD_UNCHANGED)
        assert np.allclose(cv2_read, img)

        # save to same file should return error
        file2 = str(sample)
        img = Image.from_file(file2)

        with pytest.raises(ValueError):
            img.save(str(file), overwrite=False)

        img.save(str(file), overwrite=True)
コード例 #4
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
    def test_properties(self):
        """Image name, h, w and shape properties should match that of .numpy()"""
        file = SAMPLE_IMAGES[0]
        img = Image.from_file(str(file))
        assert img.name == file.stem

        assert img.h == 260
        assert img.w == 260
        assert len(img.shape) == 3
        assert img.ndim == 3
        assert img.c == 3
コード例 #5
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
    def test_color_conversion(self):
        """Convert to same color space return original ref, otherwise return the converted"""
        color = Image.from_file(SAMPLE_IMAGES[0])
        assert color.is_color

        color_to_color = color.to_color()
        assert color_to_color.is_color
        assert id(color_to_color) == id(color)

        color_to_gray = color.to_gray()
        assert not color_to_gray.is_color
        assert id(color_to_gray) != id(color)

        gray = Image.from_file(IMAGE_BW)
        gray_to_color = gray.to_color()
        assert gray_to_color.is_color
        assert id(gray_to_color) != id(gray)

        gray_to_gray = gray.to_gray()
        assert not gray_to_gray.is_color
        assert id(gray_to_gray) == id(gray)
コード例 #6
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
    def test_resize_invalid_shape(self):
        """.resize() should raise ValueError when shape is invalid"""
        file = str(SAMPLE_IMAGES[0])
        img = Image.from_file(file)

        with pytest.raises(ValueError):
            img.resize((224, ))

        with pytest.raises(ValueError):
            img.resize((224, -1))

        with pytest.raises(ValueError):
            img.resize((113.6, 3.1415))
コード例 #7
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
    def test_resize_color(self):
        """Test color image resize, it should keep original name"""
        file = str(SAMPLE_IMAGES[0])
        img = Image.from_file(file)
        assert img.is_color

        resize = img.resize((100, 400))
        assert img.name == resize.name
        assert resize.shape == (100, 400, 3)

        resize = img.resize((100, 400), interpolation="INTER_LINEAR")
        assert img.name == resize.name
        assert resize.shape == (100, 400, 3)

        resize = img.resize((400, 200), interpolation="INTER_CUBIC")
        assert img.name == resize.name
        assert resize.shape == (400, 200, 3)
コード例 #8
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
 def test_from_file_blackwhite(self):
     """Image object can and should be loaded from black white image"""
     img = Image.from_file(IMAGE_BW)
     assert img.name == IMAGE_BW.stem
     assert not img.is_color
コード例 #9
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
 def test_from_file_color(self):
     """Image object can and should be loaded from color image file"""
     for file in SAMPLE_IMAGES:
         img = Image.from_file(str(file))
         assert img.name == file.stem
         assert img.is_color
コード例 #10
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
 def test_from_invalid_file_uncaught(self, sample):
     """There images are broken, but Image object won't detect"""
     with pytest.raises(ValueError):
         img = Image.from_file(sample)
コード例 #11
0
ファイル: test_image_object.py プロジェクト: MingRuey/imgbox
 def test_from_invalid_file(self, sample):
     """Create Image object from invalid files should raise ValueError"""
     with pytest.raises(ValueError):
         img = Image.from_file(sample)
コード例 #12
0
ファイル: test_operations.py プロジェクト: MingRuey/imgbox
 def test_laplacian(self, file):
     """Laplacian should work on both color and gray image"""
     img = Image.from_file(file)
     op = Laplacian()
     laplace = op.on(img)
     assert laplace.is_color == img.is_color
コード例 #13
0
ファイル: test_operations.py プロジェクト: MingRuey/imgbox
 def test_canny(self, file):
     """Canny should work on both color and gray image"""
     img = Image.from_file(file)
     op = Canny()
     canny = op.on(img)
     assert not canny.is_color