o
odin.langpkg.dev
packages / library / Blind_Image_Deconvolution_for_linear_motion_blur_in_Odin

Blind_Image_Deconvolution_for_linear_motion_blur_in_Odin

7762145library

A contrainned linear case that simplifies graittly this mathematical inverse problem of finding the deconvolution kernel.

No license · updated 7 months ago

Blind Image Deconvolution for linear motion blur in Odin

A contrainned linear case that simplifies graittly this mathematical inverse problem of finding the deconvolution kernel.

Description:

This is a blind image deconvolution but because bling deconvolutions are hill posed mathematical problems all there good and generic solutions have a very complex implementation. It's a inverse mathematical problem. I have been told that one of the best blind deconvolution softwares is one from ZEISS, but in here, we are doing something very simple. For this we introduce a prior to the problem, that is a constrain. That the motion in the motion blur is Linear ( a line ) with some length and a direction angle. And for this simplified case we can use a blind heuristic kernel deconvolution, determined automatically from the motion blur image.

Linear Motion Blur, we can be very effective by exploiting two statistical properties of natural images:

  • Angle Detection ( The "Smoothest" Direction ) Motion blur acts like a "smear." If you look along the direction of the blur, the pixel variance ( difference between neighbors ) is minimized. We can check angles from 0º to 180º to find which one has the lowest Total Variation. We will use derivatives with bicubic upscalling to increase the percision.

  • Motion Line Length Detection ( The "Ghost" Signature ) The derivative of a motion blur kernel is a positive spike at the start and a negative spike at the end. If we look at the autocorrelation of the image gradients along the detected angle, we will find a strong negative peak at the distance corresponding to the blur length.

The deconvolution uses the iterative method of Richardson Lucy.
All the calculations are made in f64, because in blind deconvolution small errors compound.

Images

Original image

./images/1_books.png

Linear motion blured image

./images/2_books_motion_blur.png

Reconstructed image from linear motion blured image

./images/3_books_reconstructed.png

Terminal output

(base) joaocarvalho@soundofsilence:~/proj/blind_deconvolution> make opti
odin build . -out:linear_blind_deconvolution.exe -o:speed -no-bounds-check

(base) joaocarvalho@soundofsilence:~/proj/blind_deconvolution>
time ./linear_blind_deconvolution.exe 


Begin Blind Deconvolution for Linear Motion Blur in Odin...


True parameters:
  Length : 55 pixels
  Angle  : 45.0000 degrees

Saved : 1_original.ppm

Applying Motion Blur...

Saved : 2_motion_blur.ppm

==> Starting High-Precision Blind Detection
Pass 1 ( Coarse ) Best: 45.00 degrees 
Pass 2 ( Fine )   Best: 46.00 degrees
Pass 3 ( Micro )  Best: 46.20 degrees
Estimated Angle  : 46.2000 degrees
Estimated Length : 56 pixels


==> Kernel Comparison
Mean Squared Error between kernels : 0.000003627
Result : Excellent Match

Parameter Error:
  Length Error : 1 pixels
  Angle Error  : 1.2000 degrees

Starting Restoration ( 25 steps )...
  Step 1 / 25
  Step 2 / 25
  Step 3 / 25
  Step 4 / 25
  Step 5 / 25
  Step 6 / 25
  Step 7 / 25
  Step 8 / 25
  Step 9 / 25
  Step 10 / 25
  Step 11 / 25
  Step 12 / 25
  Step 13 / 25
  Step 14 / 25
  Step 15 / 25
  Step 16 / 25
  Step 17 / 25
  Step 18 / 25
  Step 19 / 25
  Step 20 / 25
  Step 21 / 25
  Step 22 / 25
  Step 23 / 25
  Step 24 / 25
  Step 25 / 25

Restoration Complete.
Saved : 3_blind_heuristic_restored.ppm


...end Blind Deconvolution for Linear Motion Blur in Odin.



real	10m26,486s
user	10m23,453s
sys	0m2,294s

License

MIT Open Source license

Have fun

Best regards,
Joao Carvalho