Giter VIP home page Giter VIP logo

gpumedianfiltering's Introduction

Median filtering

The median filter is a non-linear digital filtering technique, often used to remove noise from an image or signal. Such noise reduction is a typical pre-processing step to improve the results of later processing (for example, edge detection on an image). Median filtering is very widely used in digital image processing because, under certain conditions, it preserves edges while removing noise (but see the discussion below), also having applications in signal processing. (1)

Technologies

  • C#
  • .NET
  • BenchmarkDotNet
  • managedCUDA (library for CUDA usage from C#)
  • CUDA

Algorithm conception

Optimalization of median filtering is using Divide-And-Conquer technique.

Device Description
CPU We are dividing photo on N parts (N is amount of used threads)
GPU We are using shared memory from device to get access to read all colors values and calculate one pixel per thread.

Colors:

We are calculating median for each of ARGB value per pixel and deciding which one should be at output image.

Results

Input Result
lenna_original lenna_result

Benchmarking

Computer data: CPU: AMD Ryzen 5 4800H ( 8 cores, 16 threads) 2.9Ghz to 4.2Ghz RAM: 16GB 2300Mhz GPU: NVidia RTX2060 6GB

Lenna (512x512)

Device Threads Mean Error StdDev
CPU 1 342.28 ms 6.261 ms 5.856 ms
CPU 4 99.40 ms 1.981 ms 4.348 ms
CPU 8 100.43 ms 1.999 ms 4.303 ms
CPU 16 46.23 ms 0.899 ms 0.883 ms
CPU 32 48.67 ms 0.968 ms 0.905 ms
GPU N/A 0.833024 ms N/A N/A
Agriculture and forestry – Altötting, Germany ( 9052 x 4965) (2)
Method Threads Mean
CPU 1 60.653 s
CPU 4 17.720 s
CPU 8 16.438 s
CPU 16 7.858 s
CPU 32 8.161 s
GPU N/A 0.08512009 s
Mining (11846 x 9945) (2)
Method Threads Mean
CPU 1 139.89 s
CPU 4 40.80 s
CPU 8 43.31 s
CPU 16 19.19 s
CPU 32 19.40 s
GPU N/A 0.1454972 s

As we can see switching calculations to GPU gives us a lot of improvement.

Usage of library

using(var image = Image(path)
{
    using(var filter = BasicMedianFilter(image))
    {
        //CPU
	    filter.CalculateOnCPU(numberOfThreads);
	    //GPU
		filter.PrepareForGPU(); // this would allocate memory on our GPU and transfer the data
		var timeOfExcecution = filter.CalculateOnGpu();
		calculator.FinalizeGpu(); //transfer the data from device to host
    }
}
References
  1. Median filter - Wikipedia

  2. Free High-Resolution Satellite Images Samples | EffigisI've decided not to test on 1 thread because it's taking too much time to complete the task.

gpumedianfiltering's People

Contributors

mattaszyk avatar

Watchers

 avatar

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.