Exemplo n.º 1
0
def test_calibrate_compensate_distortion_realdata():
    ds = datasets.calibration_ipv40CCD_distortion()
    res = calibrate_distortion(ds, (7, 7))
    ds_comp = compensate_distortion(ds, *res)

    for img, comp in zip(ds, ds_comp):
        assert_equal(comp.data.mean(), img.data.mean(), 0.01 * img.data.max())
Exemplo n.º 2
0
def test_compensate_distortion_identity():
    imgs = datasets.calibration_ipv40CCD_distortion(N=2)
    mtx = np.identity(3)
    dist = np.zeros((1, 5), dtype=np.float32)
    roi = (0, 0, imgs.shape[0], imgs.shape[1])
    imgs_comp = compensate_distortion(imgs, mtx, dist, mtx, roi)

    assert (imgs_comp[0].data - imgs[0].data).sum() == 0
    assert (imgs_comp[1].data - imgs[1].data).sum() == 0
Exemplo n.º 3
0
def test_calibrate_distortion():
    ds = datasets.calibration_ipv40CCD_distortion(N=3)
    res = calibrate_distortion(ds, (7, 7))

    assert len(res) == 4
    assert res[0].shape == (3, 3)
    assert res[1].shape == (1, 5)
    assert res[2].shape == (3, 3)
    assert len(res[3]) == 4
Exemplo n.º 4
0
def test_calibration_object(tmp_path: Path):
    ff_imgs, ex_list = _prepare_ff_data()
    test_img = _prepare_ff_test_img()
    dist_imgs = datasets.calibration_ipv40CCD_distortion(N=8)

    # perform calibration
    calib = Calibration()
    calib.calibrate_flatfield(images=ff_imgs, targets=ex_list)
    calib.calibrate_distortion(images=dist_imgs, checkerboard_size=(7, 7))

    # save to disk
    calib.save(tmp_path / "calib.pck")

    # load from disk
    calib_loaded = load_calibration(tmp_path / "calib.pck")

    # perform compensation with both
    comp = calib.process(test_img)
    comp_loaded = calib_loaded.process(test_img)

    # assert both result in the same image
    assert_equal(comp.data, comp_loaded.data)