Пример #1
0
def test_imagestack_save_full(fileext, testimgpng):
    stack = ImageStack([testimgpng, testimgpng])
    stack.save(TESTDATA_DIR + "test_image" + fileext)
    load_stack = Image.load(TESTDATA_DIR + "test_image" + fileext)
    os.remove(TESTDATA_DIR + "test_image" + fileext)
    assert len(stack) == len(load_stack)
    assert all([(img1.image == img2.image).all
                for img1, img2 in zip(stack, load_stack)])
Пример #2
0
 def apply(self, obj: do.Image, return_array: bool = False) -> Union[do.Image,np.ndarray]:
     """Apply the MaskLike to a Dataobject and either return the masked
     DataObject or the raw masked data."""
     full_mask = self.pad_to(*obj.image.shape).astype(bool)
     if return_array:
         return np.ma.masked_array(obj.image, mask=~full_mask)
     result = obj.copy()
     result.image = np.ma.masked_array(result.image, mask=~full_mask)
     return result
Пример #3
0
def testimgpng():
    return Image(TESTDATA_DIR + TESTIMAGE_NAME + ".png")
Пример #4
0
def test_image_save(testimgpng, fileext):
    testimgpng.save(TESTDATA_DIR + "test_image" + fileext)
    img = Image(TESTDATA_DIR + "test_image" + fileext)
    os.remove(TESTDATA_DIR + "test_image" + fileext)
    assert (img.image == testimgpng.image).all()
Пример #5
0
def test_image_save_json(testimgpng):
    testimgpng.save(TESTDATA_DIR + "test_image.json")
    img = Image.load(TESTDATA_DIR + "test_image.json")
    os.remove(TESTDATA_DIR + "test_image.json")
    assert (img.image == TESTIMAGE).all()
Пример #6
0
def test_image_compression(testimgpng):
    testimgpng.save(TESTDATA_DIR + "test_image.pickle.bz2")
    img = Image.load(TESTDATA_DIR + "test_image.pickle.bz2")
    os.remove(TESTDATA_DIR + "test_image.pickle.bz2")
    assert (img.image == TESTIMAGE).all()
Пример #7
0
def test_image_pickling(testimgpng):
    testimgpng.save(TESTDATA_DIR + "test_image.pickle")
    img = Image.load(TESTDATA_DIR + "test_image.pickle")
    os.remove(TESTDATA_DIR + "test_image.pickle")
    assert (img.image == TESTIMAGE).all()
Пример #8
0
def test_image_generation_from_numpy_array(source):
    array = source
    img = Image(array)
    assert (img.image == array).all()
    assert img.width, img.height == source.shape
    assert img.source is None
Пример #9
0
def test_image_generation_from_common_filetypes(fileending):
    img = Image(TESTDATA_DIR + TESTIMAGE_NAME + fileending)
    # pylint: disable = no-member
    assert (img.image == TESTIMAGE).all()
    assert (img.width, img.height) == TESTIMAGE.shape
Пример #10
0
    for obj, source in zip(comb_stack, comb_sources):
        assert obj == MinimalObject(source)

    with pytest.raises(TypeError):
        comb_stack = stack - stack_add


# Further Tests have to be done with a Stack of a Class that implements calc itself


# @pytest.mark.parametrize("x", [Image(TESTDATA_DIR + TESTIMAGE_NAME + ".png"), 10, 10.0])
# @pytest.mark.parametrize(
#    "virtual", [False, pytest.param(True, marks=pytest.mark.xfail(raises=ValueError))]
# )
@pytest.mark.parametrize(
    "x", [Image(TESTDATA_DIR + TESTIMAGE_NAME + ".png"), 10, 10.0])
@pytest.mark.parametrize("virtual", [False, True])
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
@pytest.mark.filterwarnings("ignore::UserWarning")
def test_stack_calc_imgNumber(x, virtual, testimgpng):
    sources = [testimgpng * i for i in range(1, 3)]
    if virtual:
        with pytest.warns(UserWarning):
            stack = ImageStack(sources, virtual=virtual)
    else:
        stack = ImageStack(sources, virtual=virtual)
    stack_calc = stack + x

    for index, img in enumerate(stack_calc):
        assert img == sources[index] + x