Non local means python

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Non-local means implementation (Image Processing coursework)

benmoose/nlm

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Image Processing Coursework

Note: Docker is the preferred way to run the program, since it doesn’t require you to manually download requirements.

The source code of my implementation can be found in the src/ directory. The algorithm is written in Cython ( .pyx ) which allows performance critical parts of the model (e.g. nested for loops) to be written in C.

The img/in/ directory is where the algorithm looks for input images and writes output images. Be sure to select an image that is in this directory, otherwise the program will fail. You can put your own images in here and run the algorithm on them.

The output images are written to img/out/.jpg where is the hexadecimal id printed to the console once the program has finished.

The purpose of the id is to allow you to quickly identify the generated image, and to prevent the overwriting of other images in that directory.

  • Unzip the project
  • Navigate to the project root
  • Create a virtual environment by running python3 -m venv venv
  • Activate the virtual environment with source ./venv/bin/activate
  • Install the project requirements pip3 install -r requirements.txt
  • Compile Cython and run the algorithm with ./run.sh

All commands should be executed from the project root.

./run.sh or docker-compose run py gives permission denied

In this case do one of the following, remembering to prepend docker-compose run py to the command if using docker:

  • either run chmod +x ./run.sh
  • or run python3 setup.py build_ext —inplace followed by python3 .
Читайте также:  Role tag in html

The algorithm crashes at the end with a FileNotFoundError

Make sure that there is an out/ folder in the img/ directory. If not then run mkdir img/out

I’m getting ModuleNotFoundError: No module named ‘src.model’

Make sure the src/ dir only contains

and no other files (e.g. .c or .so files). Then try running the algorithm again.

About

Non-local means implementation (Image Processing coursework)

Источник

Non-local means denoising for preserving textures#

In this example, we denoise a detail of the astronaut image using the non-local means filter. The non-local means algorithm replaces the value of a pixel by an average of a selection of other pixels values: small patches centered on the other pixels are compared to the patch centered on the pixel of interest, and the average is performed only for pixels that have patches close to the current patch. As a result, this algorithm can restore well textures, that would be blurred by other denoising algorithm.

When the fast_mode argument is False , a spatial Gaussian weighting is applied to the patches when computing patch distances. When fast_mode is True a faster algorithm employing uniform spatial weighting on the patches is applied.

For either of these cases, if the noise standard deviation, sigma , is provided, the expected noise variance is subtracted out when computing patch distances. This can lead to a modest improvement in image quality.

The estimate_sigma function can provide a good starting point for setting the h (and optionally, sigma ) parameters for the non-local means algorithm. h is a constant that controls the decay in patch weights as a function of the distance between patches. Larger h allows more smoothing between disimilar patches.

In this demo, h , was hand-tuned to give the approximate best-case performance of each variant.

noisy, non-local means (slow), non-local means (slow, using $\sigma_</p data-lazy-src=

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Python implementation of the Non Local Means algorithm for image denoising.

praveenVnktsh/Non-Local-Means

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

  • Clone the repository.
  • Keep the relevant images under data/ . Name the images as Image.png
  • Create the following directories:
OUTPUT/GFILTER/ OUTPUT/GT/ OUTPUT/LOGS/ OUTPUT/NLMFILTER/ OUTPUT/NOISED/ 
  • Run the main.py script from the terminal (make sure the cwd is the extracted folder)
    • This will save all images to the folders that were created in the previous step
    • A log file will also be generated in the OUTPUT/LOGS/ folder.
    • This will collect the data from the logs generated by main.py and store in a file called RESULTS.csv that can be later read via excel.

    • We notice that the PSNR is improved considerably compared to the noisy image.
    • We can clearly see that the NLM denoising method is superior for salt and pepper noise, where it outperforms the Gaussian filter in all images. The high localized noise in the S&P noise is combated by the NLM filter as it takes the weighted mean colour of neighbourhood windows.
    • Even though the metrics sometimes indicate that the Gaussian Filter is working well, we notice that the visual quality of the Gaussian Filter is not up to the mark compared to the NLM filter. This is because the gaussian filter simply smoothes out the noise instead of trying to remove them, whereas the NLM denoising method tries to identify similar patches around noise, and tries to eliminate them.
    • In conclusion, we can say that the NLM method is superior to the Gaussian filter for salt and pepper noise, whereas both filters work reasonably well for gaussian noise.

    Here are a few visual results obtained after running the algorithm.

    Ground Truth Ground Truth
    Gaussian Noise Salt and Pepper Noise
    Gaussian Filter, Gaussian Noise Gaussian Filter, Salt Noise
    NLM Filter, Gaussian Noise NLM Filter, Salt Noise
    Ground Truth Ground Truth
    Gaussian Noise Salt and Pepper Noise
    Gaussian Filter, Gaussian Noise Gaussian Filter, Salt Noise
    NLM Filter, Gaussian Noise NLM Filter, Salt Noise
    Ground Truth Ground Truth
    Gaussian Noise Salt and Pepper Noise
    Gaussian Filter, Gaussian Noise Gaussian Filter, Salt Noise
    NLM Filter, Gaussian Noise NLM Filter, Salt Noise
    Ground Truth Ground Truth
    Gaussian Noise Salt and Pepper Noise
    Gaussian Filter, Gaussian Noise Gaussian Filter, Salt Noise
    NLM Filter, Gaussian Noise NLM Filter, Salt Noise
    Ground Truth Ground Truth
    Gaussian Noise Salt and Pepper Noise
    Gaussian Filter, Gaussian Noise Gaussian Filter, Salt Noise
    NLM Filter, Gaussian Noise NLM Filter, Salt Noise
    • As we can see from the above images, the results are vastly improved in the case of the NLM filter, where most of the noise is removed.
    • The NLM filter works particularly well in cases where there are large patches of the image with a similar colour. As a consequence, the algorithm works better when the image is scaled up.
    • We also notice that the remaining noise in the image is sharper near edges where there is a transition between surfaces since there is a high variance between the colours.
    • All images were scaled up by a factor of 2 before performing computations for showing the difference between NLM and Gaussian Filter.
    • The results depend on the amount of noise in the image. In some cases where the noise is very high, it is not possible to improve image quality beyond a certain limit as there is not sufficient information to find the missing pixels accurately.
    • When taking the weighted pixels, the weights were divided by h instead of h x h. This is done from an experimentation point of view as this gives slightly more control over the tunable parameter as the exponential function decays slower for the same increase in h. The functioning of the algorithm will however remain the same since the order of h will simply change to obtain the same level of filtering.
    • The tunable parameters of the NLM filter are the values of the window sizes, and the value of h. To obtain the previous results, fixed values were used for all images.
    • An additional image apart from the one given in the dataset was added. This image is the classic Lena image used widely in image processing!
    [1] A. Buades, B. Coll and J. -. Morel, «A non-local algorithm for image denoising,» 2005 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR’05), San Diego, CA, USA, 2005, pp. 60-65 vol. 2, doi: 10.1109/CVPR.2005.38 [2] Palou, G. (2015, July 07). An approach to Non-Local-Means denoising. Retrieved November 16, 2020, from http://dsvision.github.io/an-approach-to-non-local-means-denoising.html

    About

    Python implementation of the Non Local Means algorithm for image denoising.

    Источник

Оцените статью