def test_open_source(): data = gopen.open_source("testdata/sample.tgz") sample = next(data) assert isinstance(sample["png"], np.ndarray) data = gopen.open_source("testdata/sample.tgz", decode=False) sample = next(data) assert isinstance(sample["png"], (bytes, str)), sample["png"]
weights = rand(4) mask = ndi.gaussian_filter(page, blur) mask /= amax(mask) bg = make_random(page.shape, (0.0, 0.5 - sep), scales, weights) fg = make_random(page.shape, (0.5 + sep, 1.0), scales, weights) degraded = mask * bg + (1.0 - mask) * fg lo, hi = 0.2 * rand(), 0.8 + 0.2 * rand() params = dict(blur=blur, sep=sep, clip=(lo, hi), scales=scales, weights=weights) clipped = clip(degraded, lo, hi) clipped -= amin(clipped) clipped /= amax(clipped) shifted = clipped return array(shifted, "f"), params data = gopen.open_source(args.input) sink = gopen.open_sink(args.output) for sample in data: utils.print_sample(sample) page = sample["framed.png"] trs, _ = random_trs() page = trs(page) degraded, params = make_all_random(page) if args.display: suptitle(repr(params)) subplot(121) imshow(degraded, vmin=0, vmax=1) subplot(122) imshow(degraded[1500:2000, 1500:2000], vmin=0, vmax=1) ginput(1, 0.001)