GithubHelp home page GithubHelp logo

juliadsp / deconvolution.jl Goto Github PK

View Code? Open in Web Editor NEW
48.0 8.0 11.0 2.32 MB

A Julia package for deconvolution of digital signals

Home Page: https://juliadsp.github.io/Deconvolution.jl/stable/

License: Other

Julia 100.00%

deconvolution.jl's Introduction

Deconvolution.jl

Documentation Build Status Code Coverage
Build Status

Introduction

This package provides a set of functions to deconvolve digital signals, like images or time series. This is written in Julia, a modern high-level, high-performance dynamic programming language designed for technical computing.

Installation

The latest version of Deconvolution.jl is available for Julia 1.0 and later versions, and can be installed with Julia built-in package manager. In a Julia session, after entering the package manager mode with ], run the command

pkg> add Deconvolution

Older versions are also available for Julia 0.4-0.7.

Documentation

The complete manual of Deconvolution.jl is available at the documentation page. It has more detailed explanation of the methods used and the examples are complemented with pictures.

Usage

Currently Deconvolution.jl provides only two methods, but others will come in the future.

wiener

wiener(input, signal, noise[, blurring])

The Wiener deconvolution attempts at reducing the noise in a digital signal by suppressing frequencies with low signal-to-noise ratio. The signal is assumed to be degraded by additive noise and a shift-invariant blurring function.

The wiener function can be used to apply the Wiener deconvolution method to a digital signal. The arguments are:

  • input: the digital signal
  • signal: the original signal (or a signal with a luckily similar power spectrum)
  • noise: the noise of the signal (or a noise with a luckily similar power spectrum)
  • blurring (optional argument): the blurring kernel

All arguments must be arrays, all with the same size, and all of them in the time/space domain (they will be converted to the frequency domain internally using fft function). Argument noise can be also a real number, in which case a constant noise with that value will be assumed (this is a good approximation in the case of white noise).

lucy

lucy(observed, psf[, iterations])

The Richardson-Lucy deconvolution is an iterative method based on Bayesian inference for restoration of signal that is convolved with a point spread function.

The lucy function can be used to apply the Richardson-Lucy deconvolution method to a digital signal. The arguments are:

  • observed: the observed blurred signal
  • psf: the point spread function (the blurring kernel)
  • iterations (optional argument): the number of iterations

First two arguments must be arrays, all with the same size, and all of them in the time/space domain (they will be converted to the frequency domain internally using fft function). Argument iterations is an integer number. The more iterations is specified the better result should be if the solution converges and it is going to converge if PSF is estimated well.

Examples

Wiener deconvolution

Here is an example of use of wiener function to perform the Wiener deconvolution of an image, degraded with a blurring function and an additive noise.

using Images, TestImages, Deconvolution, FFTW, ImageView

# Open the test image
img = channelview(testimage("cameraman"))
# Create the blurring kernel in frequency domain
x = hcat(ntuple(x -> collect((1:512) .- 257), 512)...)
k = 0.001
blurring_ft = @. exp(-k*(x ^ 2 + x ^ 2)^(5//6))
# Create additive noise
noise = rand(Float64, size(img))
# Fourier transform of the blurred image, with additive noise
blurred_img_ft = fftshift(blurring_ft) .* fft(img) .+ fft(noise)
# Get the blurred image from its Fourier transform
blurred_img = real(ifft(blurred_img_ft))
# Get the blurring kernel in the space domain
blurring = ifft(fftshift(blurring_ft))
# Polish the image with Deconvolution deconvolution
polished = wiener(blurred_img, img, noise, blurring)

# Wiener deconvolution works also when you don't have the real image and noise,
# that is the most common and useful case.  This happens because the Wiener
# filter only cares about the power spectrum of the signal and the noise, so you
# don't need to have the exact signal and noise but something with a similar
# power spectrum.
img2 = channelview(testimage("livingroom")) # Load another image
noise2 = rand(Float64, size(img)) # Create another additive noise
# Polish the image with Deconvolution deconvolution
polished2 = wiener(blurred_img, img2, noise2, blurring)

# # Compare...
# imshow(img) # ...the original image
# imshow(blurred_img) # ...the blurred image
# imshow(polished) # ...the polished image
# imshow(polished2) # ...the second polished image

Richardson-Lucy deconvolution

Here is an example of use of lucy function to perform the Richardson-Lucy deconvolution of an image blurred by kernel that models spherical lens aberration.

using Images, TestImages, Deconvolution, FFTW, ZernikePolynomials, ImageView

img = channelview(testimage("cameraman"))

# model of lens aberration
blurring = evaluateZernike(LinRange(-16,16,512), [12, 4, 0], [1.0, -1.0, 2.0], index=:OSA)
blurring = fftshift(blurring)
blurring = blurring ./ sum(blurring)

blurred_img = fft(img) .* fft(blurring) |> ifft |> real

@time restored_img = lucy(blurred_img, blurring, iterations=1000)

imshow(img)
imshow(blurring)
imshow(blurred_img)
imshow(restored_img)

Development

The package is developed at https://github.com/JuliaDSP/Deconvolution.jl. There you can submit bug reports, propose new deconvolution methods with pull requests, and make suggestions. If you would like to take over maintainership of the package in order to further improve it, please open an issue.

History

The ChangeLog of the package is available in NEWS.md file in top directory.

License

The Deconvolution.jl package is licensed under the MIT "Expat" License. The original author is Mosè Giordano.

deconvolution.jl's People

Contributors

abhishalya avatar femtocleaner[bot] avatar giordano avatar jakubwro avatar juliatagbot avatar roflmaostc avatar staticfloat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deconvolution.jl's Issues

ERROR: UndefVarError: lucy not defined

I am using Julia 1.4.2

I am trying to run the example mentioned for the Richardson-Lucy deconvolution. When running the command @time restored_img = lucy(blurred_img, blurring, iterations=1000), I see the error above. The previous lines execute without any problem.

using Images, TestImages, Deconvolution, FFTW, ZernikePolynomials, ImageView

img = channelview(testimage("cameraman"))

# model of lens aberration
blurring = evaluateZernike(LinRange(-16,16,512), [12, 4, 0], [1.0, -1.0, 2.0], index=:OSA)
blurring = fftshift(blurring)
blurring = blurring ./ sum(blurring)

blurred_img = fft(img) .* fft(blurring) |> ifft |> real
julia> @time restored_img = lucy(blurred_img, blurring, iterations=1000)
ERROR: UndefVarError: lucy not defined
Stacktrace:
 [1] top-level scope at .\util.jl:175

I also tried creating a .jl file and executing it from julia shell. Gave me the same issue.

julia> include("lucydeconvolution.jl")
ERROR: LoadError: UndefVarError: lucy not defined
Stacktrace:


 [1] top-level scope at .\util.jl:175 [inlined]
 [2] top-level scope at C:\Julia\lucydeconvolution.jl:0
 [3] include(::String) at .\client.jl:439
 [4] top-level scope at REPL[9]:1
in expression starting at C:\Julia\lucydeconvolution.jl:12

I should mention that weiner deconvolution example worked fine. It did not give any errors.

Can you suggest how to resolve this problem?

Deconvolution using Number Theoretic Transforms

Hi,

I am a complete n00b to Julia and I am not a mathematician. While researching about deconvolution I stumbled upon these papers:

The advantages of these methods are speed and deterministic behaviour (because they use only integer arithmetic). I don't think I can learn Julia and implement them at the same time in Julia.

Would you be interested in implementing them?

thanks,
HRJ

New release of the package

Hey,

recent functionality like lucy is not in the latest published package.

Could you maybe publish a new one with the recent code?

Thanks

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.