lundi 25 mars 2019

redCV and image denoising

RedCV can be used for image denoising. A lot of functions are included for helping image restoration. Basically a 3x3 kernel is used to calculate the pixel value of neighbors and to replace the pixel value in the image by the result. Of course, kernel size can be changed. According to the noise included in image you can use different parametric filters. 
When noise is simple such as pepper and salt noise a simple median filter will be efficient: Central pixel value is replaced by the median value of neighbors by rcvMedianFilter function.

But when the image is really noisy, median filter is not sufficiently efficient:
In this case *rcvMinFilter* function can be used: Central pixel value is replaced by the minimum value of neighbors and the result is pretty good. 
You can also use *rcvMaxFilter* (max value of neighbors) or *rcvMidPointFilter* (central pixel value is replaced by minimum+ maximum values of neighbors divided by 2 ) according to the noise contained in the image.
RedCV also includes a *rcvMeanFilter* function, which can be used for image smoothing. 

Code sample

As usual with Red and redCV, code is very clear and simple.
Red [
    Title: "Smoothing filters for image "
    Author: "Francois Jouen"
    File:    %smoothing.red
    Needs:   'View
]
#include %../../libs/redcv.red ; for redCV functions
kSize: 3x3
src: make image! 512x512
dst: make image! 512x512
isFile: false

loadImage: does [
    isFile: false
    canvas2/image: none
    tmp: request-file
    if not none? tmp [
        src: load tmp   
        dst: make image! src/size
        canvas1/image: src
        isFile: true
    ]
]
view win: layout [
    title "Red Smoothing Filters"
    origin 10x10 space 10x10
    button "Load"               [loadImage]
    text "Filter Size"
    field "3x3"                 [if error? try [kSize: to-pair face/text] [kSize: 3x3]]
    button "Median"             [if isFile [rcvMedianFilter src dst kSize canvas2/image: dst]]
    button "Min"                [if isFile [rcvMinFilter src dst kSize canvas2/image: dst]]
    button "Max"                [if isFile [rcvMaxFilter src dst kSize canvas2/image: dst]]
    button "MidPoint"           [if isFile [rcvMidPointFilter src dst kSize canvas2/image: dst]]
    button "Arithmetic Mean"    [if isFile [rcvMeanFilter src dst kSize 0 canvas2/image: dst]]
    button "Harmonic Mean"      [if isFile [rcvMeanFilter src dst kSize 1 canvas2/image: dst]]
    button "Geometric Mean"     [if isFile [rcvMeanFilter src dst kSize 2 canvas2/image: dst]]
    button "Quit"               [quit]
    return
    canvas1: base 512x512 white
    canvas2: base 512x512 white
]



Aucun commentaire:

Enregistrer un commentaire