Beispiel #1
0
    def test_get_data(self):
        # given
        test_data = np.random.randint(0, 2**16 -1, (512, 512))
        im = ImageModel(
            color_depth=1,
            data=test_data,
            height=test_data.shape[0],
            width=test_data.shape[1],
        )

        # when
        result = im.get_data()
        result_t = im.get_data(transpose=True)
        # then
        assert result is im.data
        assert_array_equal(result_t, np.transpose(im.data))
Beispiel #2
0
def gen_test_model_random2D():
    test_data = np.random.randint(0, 2**16 -1, (512, 512)).astype(np.int64)
    return ImageModel(
        color_depth=1,
        data=test_data,
        height=test_data.shape[0],
        width=test_data.shape[1],
    )
Beispiel #3
0
def gen_test_model_random3D_RGBA():
    # 250 512x512 images stored in RGBA ---> 250x4=1000
    # Total array size (512, 512, 1000) 
    test_data = np.random.randint(0,
                                  2**16 -1,
                                  (512, 512, 1000)).astype(np.int64)
    return ImageModel(
        color_depth=4,
        data=test_data,
        height=test_data.shape[0],
        width=test_data.shape[1],
    )
Beispiel #4
0
    def test_image_creation(self):
        # given
        test_data = np.random.randint(0, 2**16 - 1, (512, 512))

        # when
        im = ImageModel(
            color_depth=1,
            data=test_data,
            height=test_data.shape[0],
            width=test_data.shape[1],
        )
        
        # then
        assert isinstance(im.data, np.ndarray)
        assert im.height == im.data.shape[0]
        assert im.width == im.data.shape[1]
Beispiel #5
0
    def test_get_current_image(self):
        # given
        test_data = np.random.randint(0, 2**16 - 1, (512, 512, 250))
        index = random.randint(0, test_data.shape[2] - 1)
        ims = ImageStack(
            color_depth=1,
            current_image_index=0,
            data=test_data,
            depth=test_data.shape[2],
            height=test_data.shape[0],
            width=test_data.shape[1],
        )

        # when
        ims.current_image = ImageModel(
            color_depth=1,
            data=test_data[:, :, index],
            height=test_data.shape[0],
            width=test_data.shape[1],
        )

        # then
        assert_array_equal(ims.get_current_image(), ims.current_image)
Beispiel #6
0
def load_image_from_file_PIL(path):
    """ Generate ImageModel from file using PIL.Image.open()."""
    try:
        im = Image.open(path)
    except:
        # TODO fill in appropriate I/O errors
        pass
    data = np.array(im)
    # print("Loaded Data: shape - {} ndim - {}".format(data.shape, data.ndim))

    if data.ndim == 2:
        cd = 1  # greyscale
    elif data.ndim == 3 and data.shape[2] == 3:
        cd = 3  # RGB
    elif data.ndim == 3 and data.shape[2] == 4:
        cd = 4  # RGBA or ARGB
    else:
        # TODO: Handle invalid ndim
        return None
    return ImageModel(color_depth=cd,
                      data=data,
                      height=data.shape[0],
                      width=data.shape[1])