示例#1
0
def test_rectangles():
    shape = (15, 26)
    roi_data = np.array(([2, 2, 6, 3], [6, 7, 8, 5], [8, 18, 5, 10]),
                        dtype=np.int64)

    all_roi_inds = roi.rectangles(roi_data, shape)

    roi_inds, pixel_list = roi.extract_label_indices(all_roi_inds)

    ty = np.zeros(shape).ravel()
    ty[pixel_list] = roi_inds
    num_pixels_m = (np.bincount(ty.astype(int)))[1:]

    re_mesh = ty.reshape(*shape)
    for i, (col_coor, row_coor, col_val, row_val) in enumerate(roi_data, 0):
        ind_co = np.column_stack(np.where(re_mesh == i + 1))

        left, right = np.max([col_coor, 0]), np.min([col_coor + col_val,
                                                     shape[0]])
        top, bottom = np.max([row_coor, 0]), np.min([row_coor + row_val,
                                                     shape[1]])
        assert_almost_equal(left, ind_co[0][0])
        assert_almost_equal(right-1, ind_co[-1][0])
        assert_almost_equal(top, ind_co[0][1])
        assert_almost_equal(bottom-1, ind_co[-1][-1])
示例#2
0
def test_xsvs():
    images = []
    for i in range(5):
        int_array = np.tril((i + 2) * np.ones(10))
        int_array[int_array == 0] = (i + 1)
        images.append(int_array)

    images_sets = [
        np.asarray(images),
    ]
    roi_data = np.array(([4, 2, 2, 2], [0, 5, 4, 4]), dtype=np.int64)
    label_array = roi.rectangles(roi_data, shape=images[0].shape)

    prob_k_all, std = xsvs.xsvs(images_sets,
                                label_array,
                                timebin_num=2,
                                number_of_img=5,
                                max_cts=6)

    assert_array_almost_equal(prob_k_all[0, 0],
                              np.array([0., 0., 0.2, 0.2, 0.4]))
    assert_array_almost_equal(prob_k_all[0, 1],
                              np.array([0., 0.2, 0.2, 0.2, 0.4]))

    imgs = []
    for i in range(6):
        int_array = np.tril((i + 2) * np.ones(10))
        int_array[int_array == 0] = (i + 1)
        imgs.append(int_array)

    # testing for bad images
    bad_list = [5]
    # convert each bad image to np.nan array
    images1 = mask.bad_to_nan_gen(imgs, bad_list)

    new_prob_k, new_std = xsvs.xsvs((images1, ),
                                    label_array,
                                    timebin_num=2,
                                    number_of_img=5,
                                    max_cts=6)

    assert_array_almost_equal(new_prob_k[0, 0],
                              np.array([0., 0., 0.2, 0.2, 0.4]))
    assert_array_almost_equal(new_prob_k[0, 1],
                              np.array([0., 0.2, 0.2, 0.2, 0.4]))
示例#3
0
def test_xsvs():
    images = []
    for i in range(5):
        int_array = np.tril((i + 2) * np.ones(10))
        int_array[int_array == 0] = (i + 1)
        images.append(int_array)

    images_sets = [np.asarray(images), ]
    roi_data = np.array(([4, 2, 2, 2], [0, 5, 4, 4]), dtype=np.int64)
    label_array = roi.rectangles(roi_data, shape=images[0].shape)

    prob_k_all, std = xsvs.xsvs(images_sets, label_array, timebin_num=2,
                                number_of_img=5, max_cts=None)

    assert_array_almost_equal(prob_k_all[0, 0],
                              np.array([0., 0., 0.2, 0.2, 0.4]))
    assert_array_almost_equal(prob_k_all[0, 1],
                              np.array([0., 0.2, 0.2, 0.2, 0.4]))
示例#4
0
def test_static_test_sets():
    images1 = []
    for i in range(10):
        int_array = np.tril(i * np.ones(50))
        int_array[int_array == 0] = i * 100
        images1.append(int_array)

    images2 = []
    for i in range(20):
        int_array = np.triu(i * np.ones(50))
        int_array[int_array == 0] = i * 100
        images2.append(int_array)

    samples = {'sample1': np.asarray(images1), 'sample2': np.asarray(images2)}

    roi_data = np.array(([2, 30, 12, 15], [40, 20, 15, 10]), dtype=np.int64)

    label_array = roi.rectangles(roi_data, shape=(50, 50))

    # get the mean intensities of image sets given as a dictionary
    roi_data = []
    for k, v in sorted(samples.items()):
        intensity, index_list = roi.mean_intensity(v, label_array)
        roi_data.append(intensity)

    return_values = [
        roi_data[0][:, 0],
        roi_data[0][:, 1],
        roi_data[1][:, 0],
        roi_data[1][:, 1],
    ]
    expected_values = [
        np.asarray([float(x) for x in range(0, 1000, 100)]),
        np.asarray([float(x) for x in range(0, 10, 1)]),
        np.asarray([float(x) for x in range(0, 20, 1)]),
        np.asarray([float(x) for x in range(0, 2000, 100)])
    ]
    err_msg = [
        'roi%s of sample%s is incorrect' % (i, j)
        for i, j in itertools.product((1, 2), (1, 2))
    ]
    for returned, expected, err in zip(return_values, expected_values,
                                       err_msg):
        assert_array_equal(returned, expected, err_msg=err, verbose=True)
示例#5
0
def test_static_test_sets():
    images1 = []
    for i in range(10):
        int_array = np.tril(i*np.ones(50))
        int_array[int_array == 0] = i*100
        images1.append(int_array)

    images2 = []
    for i in range(20):
        int_array = np.triu(i*np.ones(50))
        int_array[int_array == 0] = i*100
        images2.append(int_array)

    samples = {'sample1': np.asarray(images1), 'sample2': np.asarray(images2)}

    roi_data = np.array(([2, 30, 12, 15], [40, 20, 15, 10]), dtype=np.int64)

    label_array = roi.rectangles(roi_data, shape=(50, 50))

    # get the mean intensities of image sets given as a dictionary
    roi_data = []
    for k, v in sorted(samples.items()):
        intensity, index_list = roi.mean_intensity(v, label_array)
        roi_data.append(intensity)

    return_values = [roi_data[0][:, 0], roi_data[0][:, 1],
                     roi_data[1][:, 0], roi_data[1][:, 1], ]
    expected_values = [
        np.asarray([float(x) for x in range(0, 1000, 100)]),
        np.asarray([float(x) for x in range(0, 10, 1)]),
        np.asarray([float(x) for x in range(0, 20, 1)]),
        np.asarray([float(x) for x in range(0, 2000, 100)])
    ]
    err_msg = ['roi%s of sample%s is incorrect' % (i, j)
               for i, j in itertools.product((1, 2), (1, 2))]
    for returned, expected, err in zip(return_values,
                                       expected_values, err_msg):
        assert_array_equal(returned, expected,
                           err_msg=err, verbose=True)
示例#6
0
def test_xsvs():
    images = []
    for i in range(5):
        int_array = np.tril((i + 2) * np.ones(10))
        int_array[int_array == 0] = (i + 1)
        images.append(int_array)

    images_sets = [np.asarray(images), ]
    roi_data = np.array(([4, 2, 2, 2], [0, 5, 4, 4]), dtype=np.int64)
    label_array = roi.rectangles(roi_data, shape=images[0].shape)

    prob_k_all, std = xsvs.xsvs(images_sets, label_array, timebin_num=2,
                                number_of_img=5, max_cts=6)

    assert_array_almost_equal(prob_k_all[0, 0],
                              np.array([0., 0., 0.2, 0.2, 0.4]))
    assert_array_almost_equal(prob_k_all[0, 1],
                              np.array([0., 0.2, 0.2, 0.2, 0.4]))

    imgs = []
    for i in range(6):
        int_array = np.tril((i + 2) * np.ones(10))
        int_array[int_array == 0] = (i + 1)
        imgs.append(int_array)

    # testing for bad images
    bad_list = [5]
    # convert each bad image to np.nan array
    images1 = mask.bad_to_nan_gen(imgs, bad_list)

    new_prob_k, new_std = xsvs.xsvs((images1, ), label_array,
                                    timebin_num=2, number_of_img=5,
                                    max_cts=6)

    assert_array_almost_equal(new_prob_k[0, 0],
                              np.array([0., 0., 0.2, 0.2, 0.4]))
    assert_array_almost_equal(new_prob_k[0, 1],
                              np.array([0., 0.2, 0.2, 0.2, 0.4]))
示例#7
0
def test_rectangles():
    shape = (15, 26)
    roi_data = np.array(([2, 2, 6, 3], [6, 7, 8, 5], [8, 18, 5, 10]),
                        dtype=np.int64)

    all_roi_inds = roi.rectangles(roi_data, shape)

    roi_inds, pixel_list = roi.extract_label_indices(all_roi_inds)

    ty = np.zeros(shape).ravel()
    ty[pixel_list] = roi_inds

    re_mesh = ty.reshape(*shape)
    for i, (col_coor, row_coor, col_val, row_val) in enumerate(roi_data, 0):
        ind_co = np.column_stack(np.where(re_mesh == i + 1))

        left, right = np.max([col_coor,
                              0]), np.min([col_coor + col_val, shape[0]])
        top, bottom = np.max([row_coor,
                              0]), np.min([row_coor + row_val, shape[1]])
        assert_almost_equal(left, ind_co[0][0])
        assert_almost_equal(right - 1, ind_co[-1][0])
        assert_almost_equal(top, ind_co[0][1])
        assert_almost_equal(bottom - 1, ind_co[-1][-1])