Every line of 'add gaussian noise to image python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
176 def __call__(self, image): 177 if isinstance(self.sigma, collections.Sequence): 178 sigma = random_num_generator( 179 self.sigma, random_state=self.random_state) 180 else: 181 sigma = self.sigma 182 if isinstance(self.mean, collections.Sequence, random_state=self.random_state): 183 mean = random_num_generator(self.mean) 184 else: 185 mean = self.mean 186 row, col, ch = image.shape 187 gauss = self.random_state.normal(mean, sigma, (row, col, ch)) 188 gauss = gauss.reshape(row, col, ch) 189 image += gauss 190 return image
26 def addGaussianNoise(src): 27 row,col,ch= src.shape 28 mean = 0 29 var = 0.1 30 sigma = 15 31 gauss = np.random.normal(mean,sigma,(row,col,ch)) 32 gauss = gauss.reshape(row,col,ch) 33 noisy = src + gauss 34 35 return noisy
305 def noiseImage(n1,n2): 306 r = Random(3) 307 x = sub(randfloat(r,n1,n2),0.5) 308 rgf = RecursiveGaussianFilter(2.0) 309 for x2 in x: 310 rgf.apply1(x2,x2) 311 return x
176 def AddGauss(img, level): 177 return cv2.blur(img, (level * 2 + 1, level * 2 + 1));
29 def compute_scaled_noise(self, noise, background_noise): 30 """Compute a scaled noise map from the baseline noise map. This scales each galaxy component individually \ 31 using their galaxy contribution map and sums their scaled noise maps with the baseline and background noise maps. 32 33 Parameters 34 ----------- 35 noise : ndarray 36 The noise before scaling (electrons per second).. 37 background_noise : ndarray 38 The background noise values (electrons per second).. 39 """ 40 return noise + (self.background_noise_scale * background_noise)
138 def _add_noise(self, img): 139 """Adds Gaussian or Poisson noise to image.""" 140 141 w, h = img.size 142 c = len(img.getbands()) 143 144 # Poisson distribution 145 if self.noise_type == 'poisson': 146 noise = np.random.poisson(self.noise_param, (h, w, c)) 147 148 # Normal distribution (default) 149 else: 150 std = np.random.uniform(0, self.noise_param) 151 noise = np.random.normal(0, std, (h, w, c)) 152 153 # Add noise and clip 154 noise_img = np.array(img) + noise 155 noise_img = np.clip(noise_img, 0, 255).astype(np.uint8) 156 157 return Image.fromarray(noise_img)
87 def rand_noise(img): 88 img_noisy = img + np.random.normal(scale=noise, size=img.shape) 89 return img_noisy
85 def remove_background_gauss(img, min_sigma=3, max_sigma=30, threshold=1): 86 """Remove background from an image using a difference of gaussian approach 87 88 img: ndarray 89 Image array 90 min_sigma: float, optional 91 The minimum standard deviation for the gaussian filter 92 max_sigma: float, optional 93 The maximum standard deviation for the gaussian filter 94 threshold: float, optional 95 Remove any remaining features below this threshold 96 97 Returns img: ndarray 98 Image array with background removed 99 """ 100 img_float = img.astype(float) 101 img_corr = np.maximum(ndimage.gaussian_filter(img_float, min_sigma) - ndimage.gaussian_filter(img_float, max_sigma) - threshold, 0) 102 return img_corr.astype(int)
86 def filter(image): 87 image_ = clean_image.convert_to_greyscale(image) 88 image_ = clean_image.clean_noise(image_, 3) 89 return image_