本文整理汇总了Python中skimage.util.random_noise函数的典型用法代码示例。如果您正苦于以下问题:Python random_noise函数的具体用法?Python random_noise怎么用?Python random_noise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_noise函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_localvar
def test_localvar():
seed = 42
data = np.zeros((128, 128)) + 0.5
local_vars = np.zeros((128, 128)) + 0.001
local_vars[:64, 64:] = 0.1
local_vars[64:, :64] = 0.25
local_vars[64:, 64:] = 0.45
data_gaussian = random_noise(data, mode='localvar', seed=seed,
local_vars=local_vars, clip=False)
assert 0. < data_gaussian[:64, :64].var() < 0.002
assert 0.095 < data_gaussian[:64, 64:].var() < 0.105
assert 0.245 < data_gaussian[64:, :64].var() < 0.255
assert 0.445 < data_gaussian[64:, 64:].var() < 0.455
# Ensure local variance bounds checking works properly
bad_local_vars = np.zeros_like(data)
with testing.raises(ValueError):
random_noise(data, mode='localvar', seed=seed,
local_vars=bad_local_vars)
bad_local_vars += 0.1
bad_local_vars[0, 0] = -1
with testing.raises(ValueError):
random_noise(data, mode='localvar', seed=seed,
local_vars=bad_local_vars)
开发者ID:Cadair,项目名称:scikit-image,代码行数:25,代码来源:test_random_noise.py
示例2: noise
def noise(image):
r = np.random.rand(1)[0]
# TODO randomize parameters of the noises; check how to init seed
if r < 0.33:
return random_noise(x, 's&p', seed=np.random.randint(1000000))
if r < 0.66:
return random_noise(x, 'gaussian', seed=np.random.randint(1000000))
return random_noise(x, 'speckle', seed=np.random.randint(1000000))
开发者ID:jpilaul,项目名称:IFT6266_project,代码行数:8,代码来源:data_preprocessing.py
示例3: test_gaussian
def test_gaussian():
seed = 42
data = np.zeros((128, 128)) + 0.5
data_gaussian = random_noise(data, seed=seed, var=0.01)
assert 0.008 < data_gaussian.var() < 0.012
data_gaussian = random_noise(data, seed=seed, mean=0.3, var=0.015)
assert 0.28 < data_gaussian.mean() - 0.5 < 0.32
assert 0.012 < data_gaussian.var() < 0.018
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_random_noise.py
示例4: test_poisson
def test_poisson():
seed = 42
data = camera() # 512x512 grayscale uint8
cam_noisy = random_noise(data, mode='poisson', seed=seed)
cam_noisy2 = random_noise(data, mode='poisson', seed=seed, clip=False)
np.random.seed(seed=seed)
expected = np.random.poisson(img_as_float(data) * 256) / 256.
assert_allclose(cam_noisy, np.clip(expected, 0., 1.))
assert_allclose(cam_noisy2, expected)
开发者ID:Cadair,项目名称:scikit-image,代码行数:10,代码来源:test_random_noise.py
示例5: load
def load(self):
self._log.info('Initiating load of Chars74K data set')
image_paths, image_labels = self.get_all_image_paths()
image_matrices = []
all_labels = []
for index in range(len(image_paths)):
raw_image = io.imread(image_paths[index], as_grey=True) # As grey to get 2D without RGB
raw_image = raw_image / 255.0 # Normalize image by dividing image by 255.0
image_matrices.append(raw_image.reshape((self.config['img_size'][0] ** 2)))
all_labels.append(image_labels[index])
if self.config['extend_data_set']:
# Add noisy images
for noise in self.config['noise_types']:
noisy_img = random_noise(raw_image, mode=noise)
image_matrices.append(noisy_img.reshape((400, )))
all_labels.append(image_labels[index])
# Add shifted images
shifted_images = [np.roll(raw_image, 1, axis=i) for i in range(-1, 2)]
for image in shifted_images:
image_matrices.append(image.reshape((400, )))
all_labels.append(image_labels[index])
# Split data set into (X_train, y_train, X_test and y_test)
data_set_tuple = self.split_data_set(image_matrices, all_labels)
log.info('Loaded %i images of %s pixels' % (len(all_labels), self.config['img_size']))
return data_set_tuple
开发者ID:OptimusCrime,项目名称:ntnu-2016-tdt4173-assignment5,代码行数:29,代码来源:chars74k_load.py
示例6: filtre2D
def filtre2D(img):
N = 3
type_bruit = 'AG'
selem = np.ones([N, N])
if type_bruit == 'AG':
bruit = util.random_noise(np.zeros(img.shape), mode='gaussian')
img_bruitee = util.random_noise(img, mode='gaussian')
else:
bruit = util.random_noise(np.zeros(img.shape), mode='s&p')
img_bruitee = util.random_noise(img, mode='s&p')
img_bruit_median = filters.median(img_bruitee, selem)
img_bruit_linear = ndimage.convolve(img_bruitee, selem)
fig = plt.figure()
if type_bruit == 'AG':
bruit_linear = ndimage.convolve(bruit, selem)
img_linear = ndimage.convolve(img, selem)
fig.add_subplot(3, 3, 1)
plt.imshow(img, cmap='gray')
fig.add_subplot(3, 3, 2)
plt.imshow(bruit, cmap='gray')
fig.add_subplot(3, 3, 3)
plt.imshow(img_bruitee, cmap='gray')
fig.add_subplot(3, 3, 4)
plt.imshow(img_linear, cmap='gray')
fig.add_subplot(3, 3, 5)
plt.imshow(bruit_linear, cmap='gray')
fig.add_subplot(3, 3, 6)
plt.imshow(img_bruit_linear, cmap='gray')
fig.add_subplot(3, 3, 9)
plt.imshow(img_bruit_median, cmap='gray')
else:
fig.add_subplot(2, 2, 1)
plt.imshow(img, cmap='gray')
fig.add_subplot(2, 2, 2)
plt.imshow(img_bruitee, cmap='gray')
fig.add_subplot(2, 2, 3)
plt.imshow(img_bruit_linear, cmap='gray')
fig.add_subplot(2, 2, 4)
plt.imshow(img_bruit_median, cmap='gray')
# fig.tight_layout()
plt.show()
开发者ID:Fibri,项目名称:Multimedia-Benchmark-Python,代码行数:45,代码来源:TP2-scikit.py
示例7: test_extended_search_area
def test_extended_search_area():
""" test of the extended area PIV """
frame_a = np.zeros((64,64))
frame_a = random_noise(frame_a)
frame_a = img_as_ubyte(frame_a)
frame_b = np.roll(np.roll(frame_a,3,axis=1),2,axis=0)
u,v = piv(frame_a.astype(np.int32),frame_b.astype(np.int32),window_size=16,search_area_size=32,overlap=0)
# print u,v
assert(np.max(np.abs(u-3)+np.abs(v+2)) <= 0.5)
开发者ID:OpenPIV,项目名称:openpiv-python,代码行数:9,代码来源:test_process.py
示例8: test_clip_poisson
def test_clip_poisson():
seed = 42
data = camera() # 512x512 grayscale uint8
data_signed = img_as_float(data) * 2. - 1. # Same image, on range [-1, 1]
# Signed and unsigned, clipped
cam_poisson = random_noise(data, mode='poisson', seed=seed, clip=True)
cam_poisson2 = random_noise(data_signed, mode='poisson', seed=seed,
clip=True)
assert (cam_poisson.max() == 1.) and (cam_poisson.min() == 0.)
assert (cam_poisson2.max() == 1.) and (cam_poisson2.min() == -1.)
# Signed and unsigned, unclipped
cam_poisson = random_noise(data, mode='poisson', seed=seed, clip=False)
cam_poisson2 = random_noise(data_signed, mode='poisson', seed=seed,
clip=False)
assert (cam_poisson.max() > 1.15) and (cam_poisson.min() == 0.)
assert (cam_poisson2.max() > 1.3) and (cam_poisson2.min() == -1.)
开发者ID:Cadair,项目名称:scikit-image,代码行数:18,代码来源:test_random_noise.py
示例9: test_speckle
def test_speckle():
seed = 42
data = np.zeros((128, 128)) + 0.1
np.random.seed(seed=42)
noise = np.random.normal(0.1, 0.02 ** 0.5, (128, 128))
expected = np.clip(data + data * noise, 0, 1)
data_speckle = random_noise(data, mode="speckle", seed=seed, m=0.1, v=0.02)
assert_allclose(expected, data_speckle)
开发者ID:RONNCC,项目名称:scikit-image,代码行数:9,代码来源:test_random_noise.py
示例10: test_clip_gaussian
def test_clip_gaussian():
seed = 42
data = camera() # 512x512 grayscale uint8
data_signed = img_as_float(data) * 2. - 1. # Same image, on range [-1, 1]
# Signed and unsigned, clipped
cam_gauss = random_noise(data, mode='gaussian', seed=seed, clip=True)
cam_gauss2 = random_noise(data_signed, mode='gaussian', seed=seed,
clip=True)
assert (cam_gauss.max() == 1.) and (cam_gauss.min() == 0.)
assert (cam_gauss2.max() == 1.) and (cam_gauss2.min() == -1.)
# Signed and unsigned, unclipped
cam_gauss = random_noise(data, mode='gaussian', seed=seed, clip=False)
cam_gauss2 = random_noise(data_signed, mode='gaussian', seed=seed,
clip=False)
assert (cam_gauss.max() > 1.22) and (cam_gauss.min() < -0.36)
assert (cam_gauss2.max() > 1.219) and (cam_gauss2.min() < -1.337)
开发者ID:Cadair,项目名称:scikit-image,代码行数:18,代码来源:test_random_noise.py
示例11: test_clip_speckle
def test_clip_speckle():
seed = 42
data = camera() # 512x512 grayscale uint8
data_signed = img_as_float(data) * 2. - 1. # Same image, on range [-1, 1]
# Signed and unsigned, clipped
cam_speckle = random_noise(data, mode='speckle', seed=seed, clip=True)
cam_speckle2 = random_noise(data_signed, mode='speckle', seed=seed,
clip=True)
assert (cam_speckle.max() == 1.) and (cam_speckle.min() == 0.)
assert (cam_speckle2.max() == 1.) and (cam_speckle2.min() == -1.)
# Signed and unsigned, unclipped
cam_speckle = random_noise(data, mode='speckle', seed=seed, clip=False)
cam_speckle2 = random_noise(data_signed, mode='speckle', seed=seed,
clip=False)
assert (cam_speckle.max() > 1.219) and (cam_speckle.min() == 0.)
assert (cam_speckle2.max() > 1.219) and (cam_speckle2.min() < -1.306)
开发者ID:Cadair,项目名称:scikit-image,代码行数:18,代码来源:test_random_noise.py
示例12: test_piv_smaller_window
def test_piv_smaller_window():
""" test of the simplest PIV run """
frame_a = np.zeros((32,32))
frame_a = random_noise(frame_a)
frame_a = img_as_ubyte(frame_a)
frame_b = np.roll(np.roll(frame_a,-3,axis=1),-2,axis=0)
u,v = piv(frame_a.astype(np.int32),frame_b.astype(np.int32),window_size=16,search_area_size=32)
# print u,v
assert(np.max(np.abs(u+3)) < 0.2)
assert(np.max(np.abs(v-2)) < 0.2)
开发者ID:OpenPIV,项目名称:openpiv-python,代码行数:10,代码来源:test_process.py
示例13: AddNoise
def AddNoise(img):
# mean = 0
# sigma = 0.045
# gauss = np.random.normal(mean, sigma, img.shape)
# gauss = gauss.reshape(img.shape[0], img.shape[1])
# noisy = img + gauss
noisy = util.random_noise(img, mode='gaussian', var=0.002)
# noisy = util.random_noise(img, mode='gaussian', var=0.0015)
# noisy = util.random_noise(img, mode='s&p')
return noisy
开发者ID:chongyeegan,项目名称:computer-vision-hw-1,代码行数:11,代码来源:utils.py
示例14: SaltPepper
def SaltPepper(request):
from skimage.util import random_noise
image, response = process(request, False)
image = random_noise(image, mode = 's&p')
io.imsave(response['filename'], image)
return JsonResponse(response)
开发者ID:Johannes-brahms,项目名称:blog,代码行数:11,代码来源:views.py
示例15: test_piv
def test_piv():
""" test of the simplest PIV run """
frame_a = np.zeros((32,32))
frame_a = random_noise(frame_a)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
frame_a = img_as_ubyte(frame_a)
frame_b = np.roll(np.roll(frame_a,3,axis=1),2,axis=0)
u,v = piv(frame_a.astype(np.int32),frame_b.astype(np.int32),window_size=32)
# print u,v
assert(np.max(np.abs(u-3)) < 0.2)
assert(np.max(np.abs(v+2)) < 0.2)
开发者ID:OpenPIV,项目名称:openpiv-python,代码行数:12,代码来源:test_process.py
示例16: test_pepper
def test_pepper():
seed = 42
cam = img_as_float(camera())
cam_noisy = random_noise(cam, seed=seed, mode="pepper", d=0.15)
peppermask = cam != cam_noisy
# Ensure all changes are to 1.0
assert_allclose(cam_noisy[peppermask], np.zeros(peppermask.sum()))
# Ensure approximately correct amount of noise was added
proportion = float(peppermask.sum()) / (cam.shape[0] * cam.shape[1])
assert 0.11 < proportion <= 0.18
开发者ID:RONNCC,项目名称:scikit-image,代码行数:12,代码来源:test_random_noise.py
示例17: test_salt
def test_salt():
seed = 42
cam = img_as_float(camera())
cam_noisy = random_noise(cam, seed=seed, mode='salt', amount=0.15)
saltmask = cam != cam_noisy
# Ensure all changes are to 1.0
assert_allclose(cam_noisy[saltmask], np.ones(saltmask.sum()))
# Ensure approximately correct amount of noise was added
proportion = float(saltmask.sum()) / (cam.shape[0] * cam.shape[1])
assert 0.11 < proportion <= 0.15
开发者ID:Cadair,项目名称:scikit-image,代码行数:12,代码来源:test_random_noise.py
示例18: recall_with_noise
def recall_with_noise(clf, X, noise_amount=0.05):
X = X.astype(float)
X_noise = random_noise(X, mode='s&p', amount=noise_amount)
X_noise = binarize(X_noise, binary_values=(-1,1))
X_recall = []
for x in X_noise:
recall = clf.recall(x=x, n_times=10).reshape(-1)
recall[recall < 0] = -1
recall[recall >= 0] = 1
X_recall.append(recall)
X_recall = np.array(X_recall)
return X, X_noise, X_recall
开发者ID:wkentaro,项目名称:utmi-intelligent-mechano-informatics,代码行数:12,代码来源:recall.py
示例19: input_data
def input_data(path, filename, blur_amount):
img_path = os.path.join(path, filename)
img = io.imread(img_path)
img = img[85:341,90:346]
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(blur_amount,blur_amount),0)
noise = random_noise(gray, mode = "gaussian")
return img, gray, blur
开发者ID:charparr,项目名称:tundra-snow,代码行数:13,代码来源:gsmd.py
示例20: test_pepper
def test_pepper():
seed = 42
cam = img_as_float(camera())
data_signed = cam * 2. - 1. # Same image, on range [-1, 1]
cam_noisy = random_noise(cam, seed=seed, mode='pepper', amount=0.15)
peppermask = cam != cam_noisy
# Ensure all changes are to 1.0
assert_allclose(cam_noisy[peppermask], np.zeros(peppermask.sum()))
# Ensure approximately correct amount of noise was added
proportion = float(peppermask.sum()) / (cam.shape[0] * cam.shape[1])
assert 0.11 < proportion <= 0.15
# Check to make sure pepper gets added properly to signed images
orig_zeros = (data_signed == -1).sum()
cam_noisy_signed = random_noise(data_signed, seed=seed, mode='pepper',
amount=.15)
proportion = (float((cam_noisy_signed == -1).sum() - orig_zeros) /
(cam.shape[0] * cam.shape[1]))
assert 0.11 < proportion <= 0.15
开发者ID:Cadair,项目名称:scikit-image,代码行数:23,代码来源:test_random_noise.py
注:本文中的skimage.util.random_noise函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论