Logo elodees  elodees

A caring AI for a better world













Only alphabetic characters accented or not as well as the space are accepted

Logo IA




Erlang gamma image noise





No account yet ?

Sign up to access all content




Tested in Anaconda and Python 3.7

import cv2
import numpy as np
import math
 
def Erlang_gamma_noise_add(img, prob_noise, mean, variance):
 
    height, width, depth = np.shape(img)
 
    num_noise_pixels = height * width * prob_noise
 
    print(num_noise_pixels)
 
    noise_array = np.zeros(20, np.float)
 
    noise_mat = np.zeros(shape = (img.shape[0], img.shape[1], img.shape[2]),dtype = np.float)
 
    count = 0
 
 
    a = mean / variance
 
    b = a * mean
 
    for i in range(-10,10):
 
        if i >= 0:
            fx = (((a**b) * (i**(b - 1))) / math.factorial(math.ceil(b) - 1) * math.exp(-(a * i)))
        elif i < a:
            fx = 0
 
        noise_array[count] = fx
 
        count += 1
 
    num_noise_pixels = 0
 
    cdf_g = np.cumsum(noise_array)
 
    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
 
            random_number = np.random.rand()
 
            count = -10
 
            for k in cdf_g:
 
                if random_number <= k:
 
                    noise_mat[i,j] = count * 20
 
                    break
 
                count += 1
 
    return noise_mat
 
if  __name__ == "__main__":
 
    img = cv2.imread("Lenna.jpg")
 
    mean = 10
    variance = 10
    prob_noise = 0.10
 
    noise_mat = Erlang_gamma_noise_add(img,prob_noise,mean,variance)
 
    img = img + noise_mat
 
    cv2.imwrite("Lenna_gamma_noise.jpg",img)
 


Image-Restoration-in-Digital-Image-Processing - GitHub



Original image

Free image provided by pexel.com

Erlang gamma image noise

Free image provided by pexel.com




Image noise











Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !

Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License