Example #1
0
def test_calibrate_flatfield_linear():
    img0 = np.random.random((10, 10)) / 10
    img1 = (-np.random.random((10, 10)) / 10) + 1.0
    coeff = 1 / (img1 - img0)
    coeff *= np.mean(img1)

    coeff_result = _calibrate_flatfield([img0, img1], [0, 1.0], order=1)
    assert_equal(coeff_result[1], coeff)
    assert_equal(coeff_result[0], -coeff * img0)
Example #2
0
def test_calibrate_flatfield_least_squares_linear():
    img0 = np.random.random((10, 10)) / 10
    img2 = (-np.random.random((10, 10)) / 10) + 1.0
    coeff = 1 / (img2 - img0)
    img1 = (np.full_like(img0, 0.5) + img0) / coeff
    coeff *= np.mean(img2)
    coeff_result = _calibrate_flatfield([img0, img1, img2], [0, 0.5, 1.0],
                                        order=1)

    assert_equal(coeff_result[1], coeff, 0.1)
    assert_equal(coeff_result[0], -coeff * img0, 0.1)
Example #3
0
def test_calibrate_and_compensate_flatfield():
    img0 = np.random.random((10, 10)) / 10
    img1 = np.random.random((10, 10)) / 10 + 0.5 - 0.05
    img2 = (-np.random.random((10, 10)) / 10) + 1.0
    mean = np.mean(img2)

    coeff = _calibrate_flatfield([img0, img1, img2], [0, 0.5, 1.0], order=2)
    compensated = _compensate_flatfield(_make_image_seq([img0, img1, img2]),
                                        coeff)
    assert_equal(np.zeros_like(img0), compensated[0].data)
    assert_equal(np.full_like(img1, 0.5 * mean), compensated[1].data)
    assert_equal(np.full_like(img1, 1.0 * mean), compensated[2].data)
Example #4
0
def test_calibrate_flatfield_quadratic():
    img0 = np.random.random((10, 10)) / 10
    img1 = np.random.random((10, 10)) / 10 + 0.5 - 0.05
    img2 = (-np.random.random((10, 10)) / 10) + 1.0
    mean = np.mean(img2)

    def compensate(img, coeff):
        return coeff[2] * img**2 + coeff[1] * img + coeff[0]

    coeff = _calibrate_flatfield([img0, img1, img2], [0, 0.5, 1.0], order=2)
    assert_equal(np.zeros_like(img0), compensate(img0, coeff))
    assert_equal(np.full_like(img1, 0.5 * mean), compensate(img1, coeff))
    assert_equal(np.full_like(img1, 1.0 * mean), compensate(img2, coeff))