Deblurring
Deblurring copied to clipboard
Tile mode?
Hi @cpuimage .
There is a need for a tiled mode of operation for unevenly blurred scans. Tile sizes are optional (default == image size).
And the blending mode: result = %a * origin + %b * deblured, where %a + %b = 1.0f;
Hi @cpuimage .
Somehow I made a tiled version:
diff -Nard Deblurring Deblurringtail > Deblurringtail.patch
diff '--color=auto' -Nard Deblurring/CMakeLists.txt Deblurringtail/CMakeLists.txt
2c2
< project(Deblurring)
---
> project(Deblurringtail)
12c12
< add_executable(Deblurring
---
> add_executable(Deblurringtail
22c22
< target_link_libraries(Deblurring -lfftw3 -lfftw3f -lm)
\ No newline at end of file
---
> target_link_libraries(Deblurringtail -lfftw3 -lfftw3f -lm)
diff '--color=auto' -Nard Deblurring/main.cpp Deblurringtail/main.cpp
167a168,169
> args::ValueFlag<int> tailSize(parser, "tailSize", "set the tail size", {"tail"}, -1);
> args::ValueFlag<flt> smooth(parser, "smooth", "smooth part origin", {"smooth"}, flt(0));
170c172
< args::Positional<std::string> out_kernel(parser, "out_kernel", "kernel output file", args::Options::Required);
---
> //args::Positional<std::string> out_kernel(parser, "out_kernel", "kernel output file", args::Options::Required);
212c214,216
< opts.out_kernel = args::get(out_kernel);
---
> opts.tailSize = args::get(tailSize);
> opts.smooth = args::get(smooth);
> //opts.out_kernel = args::get(out_kernel);
238a243
> printf("image size %dx%d\n", w, h);
247,252c252,266
< // estimate the kernel (call Algorithm 1 of the paper)
< img_t<flt> kernel;
< estimateKernel(kernel, img, opts.kernelSize, opts);
<
< // save the estimated kernel
< iio_write_image(opts.out_kernel, &kernel[0], kernel.w, kernel.h, kernel.d);
---
> int tw, th, twc, thc;
> if (opts.tailSize > 0)
> {
> tw = opts.tailSize;
> th = opts.tailSize;
> twc = (w + tw - 1) / tw;
> thc = (h + th - 1) / th;
> }
> else
> {
> tw = w;
> th = h;
> twc = 1;
> thc = 1;
> }
254d267
< // deconvolve the blurry image using the estimated kernel
256,260c269,329
< img_t<flt> tapered;
< img_t<flt> deconv;
< pad_and_taper(tapered, img, kernel);
< deconvBregman(deconv, tapered, kernel, 20, opts.finalDeconvolutionWeight);
< unpad(result, deconv, kernel);
---
> result.ensure_size(w, h, d);
> printf("smooth %f\n", opts.smooth);
> printf("tail size %dx%d\n", tw, th);
> for (int j = 0; j < thc; j++)
> {
> int y0 = j * th;
> int y1 = y0 + th;
> y1 = (y1 < h) ? y1 : h;
> int dy = y1 - y0;
> for (int k = 0; k < twc; k++)
> {
> int x0 = k * tw;
> int x1 = x0 + tw;
> x1 = (x1 < w) ? x1 : w;
> int dx = x1 - x0;
>
> img_t<flt> tail;
> tail.ensure_size(dx, dy, d);
> size_t ind, indt = 0;
> printf("tail %d,%d (%dx%d)\n", j, k, dx, dy);
> for (int y = y0; y < y1; y++)
> {
> for (int x = x0; x < x1; x++)
> {
> for (int c = 0; c < d; c++)
> {
> ind = ((y * w) + x) * d + c;
> tail[indt] = img[ind];
> indt++;
> }
> }
> }
> // estimate the kernel (call Algorithm 1 of the paper)
> img_t<flt> kernel;
> estimateKernel(kernel, tail, opts.kernelSize, opts);
>
> // save the estimated kernel
> //iio_write_image(opts.out_kernel, &kernel[0], kernel.w, kernel.h, kernel.d);
>
> // deconvolve the blurry image using the estimated kernel
> img_t<flt> tailresult;
> img_t<flt> tapered;
> img_t<flt> deconv;
> pad_and_taper(tapered, tail, kernel);
> deconvBregman(deconv, tapered, kernel, 20, opts.finalDeconvolutionWeight);
> unpad(tailresult, deconv, kernel);
> indt = 0;
> for (int y = y0; y < y1; y++)
> {
> for (int x = x0; x < x1; x++)
> {
> for (int c = 0; c < d; c++)
> {
> ind = ((y * w) + x) * d + c;
> result[ind] = opts.smooth * tail[indt] + (1.0f - opts.smooth) * tailresult[indt];
> indt++;
> }
> }
> }
> }
> }
diff '--color=auto' -Nard Deblurring/options.hpp Deblurringtail/options.hpp
11a12,13
> int tailSize;
> flt smooth;
But the kernel could no longer attach the output.