本文整理汇总了Python中scipy.misc.lena函数的典型用法代码示例。如果您正苦于以下问题:Python lena函数的具体用法?Python lena怎么用?Python lena使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lena函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_weight_lena
def get_weight_lena(sigma=50000.):
"""
Calculates the weight matrix of a small patch of lena's image
Parameters
----------
sigma: int
Returns
-------
"""
lena = misc.lena()
lena = lena[:30:, :30]
patches = []
for i in range(lena.shape[0] - 7):
for j in range(lena.shape[1] - 7):
patches.append(lena[i:i + 6, j:j + 6].flatten())
dist = np.exp(- euclidean_distances(patches, patches) ** 2 / sigma ** 2)
thres = dist.copy()
thres.sort(axis=1)
thres = thres[:, ::-1][:, 6]
dist[dist < thres] = 0
return dist
开发者ID:NelleV,项目名称:COPRE,代码行数:26,代码来源:data.py
示例2: run
def run(self, img=misc.lena(), increase=True):
img = misc.imread('/Users/Daniel/Desktop/p0.jpg')
img_blurred = self.__blur(img)
img = self.__divide(img, img_blurred)
if False:
img = exposure.adjust_sigmoid(img)
misc.imsave('/Users/Daniel/Desktop/p1.jpg', img)
开发者ID:idf,项目名称:scanify,代码行数:7,代码来源:core.py
示例3: main
def main():
args = parse_args()
syris.init(device_index=0)
m = 20
if args.input == 'grid':
image = make_grid(args.n, m * q.m).thickness.get()
elif args.input == 'lena':
from scipy.misc import lena
image = lena().astype(cfg.PRECISION.np_float)
if args.n != image.shape[0]:
image = gutil.get_host(ip.rescale(image, (args.n, args.n)))
n = image.shape[0]
crop_n = n - 2 * m - 2
y, x = np.mgrid[-n / 2:n / 2, -n / 2:n / 2]
# Compute a such that the disk diameter is exactly the period when distance from the middle is n
# / 2
a = m / (2 * (crop_n / 2.) ** 2)
radii = (a * np.sqrt(x ** 2 + y ** 2) ** 2 + 1e-3).astype(cfg.PRECISION.np_float)
x_param = radii
y_param = radii
result = ip.varconvolve_disk(image, (y_param, x_param)).get()
result = ip.crop(result, (m - 1, m - 1, crop_n, crop_n)).get()
radii = ip.crop(radii, (m - 1, m - 1, crop_n, crop_n)).get()
image = ip.crop(image, (m - 1, m - 1, crop_n, crop_n)).get()
if args.output:
save_image(args.output, result)
show(image, title='Original Image')
show(2 * radii, title='Blurring Disk Diameters')
show(result, title='Blurred Image')
plt.show()
开发者ID:ufo-kit,项目名称:syris,代码行数:35,代码来源:varconvolution.py
示例4: setUp
def setUp(self):
im = lena()
self.lena_offset = np.array((256, 256))
s = hs.signals.Image(np.zeros((10, 100, 100)))
self.scales = np.array((0.1, 0.3))
self.offsets = np.array((-2, -3))
izlp = []
for ax, offset, scale in zip(
s.axes_manager.signal_axes, self.offsets, self.scales):
ax.scale = scale
ax.offset = offset
izlp.append(ax.value2index(0))
self.izlp = izlp
self.ishifts = np.array([(0, 0), (4, 2), (1, 3), (-2, 2), (5, -2),
(2, 2), (5, 6), (-9, -9), (-9, -9), (-6, -9)])
self.new_offsets = self.offsets - self.ishifts.min(0) * self.scales
zlp_pos = self.ishifts + self.izlp
for i in xrange(10):
slices = self.lena_offset - zlp_pos[i, ...]
s.data[i, ...] = im[slices[0]:slices[0] + 100,
slices[1]:slices[1] + 100]
self.spectrum = s
# How image should be after successfull alignment
smin = self.ishifts.min(0)
smax = self.ishifts.max(0)
offsets = self.lena_offset + self.offsets / self.scales - smin
size = np.array((100, 100)) - (smax - smin)
self.aligned = im[offsets[0]:offsets[0] + size[0],
offsets[1]:offsets[1] + size[1]]
开发者ID:jerevon,项目名称:hyperspy,代码行数:30,代码来源:test_2D_tools.py
示例5: _plot_default
def _plot_default(self):
# Create a GridContainer to hold all of our plots: 2 rows, 4 columns:
container = GridContainer(fill_padding=True,
bgcolor="lightgray", use_backbuffer=True,
shape=(2, 4))
arrangements = [('top left', 'h'),
('top right', 'h'),
('top left', 'v'),
('top right', 'v'),
('bottom left', 'h'),
('bottom right', 'h'),
('bottom left', 'v'),
('bottom right', 'v')]
orientation_name = {'h': 'horizontal', 'v': 'vertical'}
pd = ArrayPlotData(image=lena())
# Plot some bessel functions and add the plots to our container
for origin, orientation in arrangements:
plot = Plot(pd, default_origin=origin, orientation=orientation)
plot.img_plot('image')
# Attach some tools to the plot
plot.tools.append(PanTool(plot))
zoom = ZoomTool(plot, tool_mode="box", always_on=False)
plot.overlays.append(zoom)
title = '{0}, {1}'
plot.title = title.format(orientation_name[orientation],
origin.replace(' ', '-'))
# Add to the grid container
container.add(plot)
return container
开发者ID:binaryannamolly,项目名称:chaco,代码行数:35,代码来源:image_plot_origin_and_orientation.py
示例6: IST
def IST():
from scipy.misc import lena
#from numpy.random import random
seed(42)
x = lena()
xx = x + np.random.random(x.shape) * 255 / 10
xx, ys = ISTreal(xx, p=1.0)
xx = idwt2_full(xx)
a = np.random.random(x.shape) * 255 / 10
error = abs(xx - x)
print mean(a)
print mean(error)
imshow(error)
show()
subplot(121)
imshow(ys, cmap='gray')
subplot(122)
imshow(xx, cmap='gray')
savefig('stackexchange.png', dpi=300)
show()
开发者ID:stsievert,项目名称:side-projects,代码行数:27,代码来源:IST.py
示例7: initTexture
def initTexture(self):
"""
init the texture - this has to happen after an OpenGL context
has been created
"""
# make the OpenGL context associated with this canvas the current one
#self.SetCurrent()
data = np.uint8(np.flipud(lena()))
w,h = data.shape
# generate a texture id, make it current
self.texture = gl.glGenTextures(1)
gl.glBindTexture(gl.GL_TEXTURE_2D,self.texture)
# texture mode and parameters controlling wrapping and scaling
gl.glTexEnvf( gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE )
gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_REPEAT )
gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_REPEAT )
gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR )
gl.glTexParameterf( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR )
# map the image data to the texture. note that if the input
# type is GL_FLOAT, the values must be in the range [0..1]
gl.glTexImage2D(gl.GL_TEXTURE_2D,0,gl.GL_RGB,w,h,0,
gl.GL_LUMINANCE,gl.GL_UNSIGNED_BYTE,data)
开发者ID:InfiniteSearchSpace,项目名称:GameOfLife,代码行数:27,代码来源:texTest.py
示例8: test_cercle
def test_cercle():
im = lena()
roi = roi_quad(im.shape,250,250,400)
im = np.multiply(roi,im)
plt.imshow(im)
plt.show()
开发者ID:TheDudesGhost,项目名称:Tracking,代码行数:7,代码来源:quad.py
示例9: get_image
def get_image():
# Build Image
try:
filename = sys.argv[1]
image = ndimage.imread(filename, flatten=True).astype(np.float32)
except IndexError:
image = misc.lena().astype(np.float32)
return image
开发者ID:AngelBerihuete,项目名称:numbapro-examples,代码行数:8,代码来源:convolve.py
示例10: pytest_generate_tests
def pytest_generate_tests(metafunc):
"""
Generates a set of test for the registration methods.
"""
image = misc.lena()
image = nd.zoom(image, 0.50)
if metafunc.function is test_shift:
for displacement in np.arange(-10.,10.):
p = np.array([displacement, displacement])
template = warp(
image,
p,
model.Shift,
sampler.Spline
)
metafunc.addcall(
id='dx={}, dy={}'.format(
p[0],
p[1]
),
funcargs=dict(
image=image,
template=template,
p=p
)
)
if metafunc.function is test_affine:
# test the displacement component
for displacement in np.arange(-10.,10.):
p = np.array([0., 0., 0., 0., displacement, displacement])
template = warp(
image,
p,
model.Affine,
sampler.Spline
)
metafunc.addcall(
id='dx={}, dy={}'.format(
p[4],
p[5]
),
funcargs=dict(
image=image,
template=template,
p=p
)
)
开发者ID:pradal,项目名称:python-register,代码行数:58,代码来源:test_register.py
示例11: main
def main():
img = lena()
frames, desc = imagesift.get_sift_keypoints(img)
out = imagesift.draw_sift_frames(img, frames)
cv2.imshow('sift image', out)
cv2.waitKey(0)
开发者ID:TakaomiHasegawa,项目名称:jsk_recognition,代码行数:9,代码来源:sift_keypoints.py
示例12: setUp
def setUp( self ):
import numpy as np
self.np = np
from scipy.misc import lena
self.lena = lena()
self.raw = np.zeros((1,512,512,1,1))
self.raw[0,:,:,0,0] = self.lena
self.source = ArraySource( self.raw )
开发者ID:lcroitor,项目名称:volumeeditor,代码行数:9,代码来源:datasources.py
示例13: __init__
def __init__(self):
iris = datasets.load_iris()
self._x_iris = iris.data
self._y_iris = iris.target
try:
self._lena = sp.lena()
except AttributeError:
from scipy import misc
self._lena = misc.lena()
开发者ID:haisland0909,项目名称:python_practice,代码行数:9,代码来源:unsupervisedlearningsample.py
示例14: main
def main():
print "Loading Lena image..."
# img_size = 50, 50
# orig_img = misc.lena()[160:160+img_size[0], 160:160+img_size[1]]
orig_img = misc.lena()
print "Image dtype: %s" % orig_img.dtype
print "Image size: %6d" % orig_img.size
print "Image shape: %3dx%3d" % (orig_img.shape[0], orig_img.shape[1])
print "Max value %3d at pixel %6d" % (orig_img.max(), orig_img.argmax())
print "Min value %3d at pixel %6d" % (orig_img.min(), orig_img.argmin())
print "Variance: %1.5f" % orig_img.var()
print "Standard deviation: %1.5f" % orig_img.std()
misc.imsave("orig.png", orig_img)
# Generate additive white Gaussian noise (AWGN)
print "Generating noisy image..."
if len(sys.argv) == 2:
# Use sigma specified by the user
user_sigma = float(sys.argv[1])
noise = get_noise(noise_size=orig_img.size, noise_sigma=user_sigma)
else:
# Use default sigma
noise = get_noise(noise_size=orig_img.size)
nois_img = get_noisy_img(orig_img, noise)
misc.imsave("noisy.png", nois_img)
# Normalize image, that is, translate values in image so its
# distribution is comparable to a normal N(0, 1) (mean = 0.0,
# standard deviation = 1.0). This way, parameters of the denoising
# algorithm, like h and sigma, are independent of the values and
# distribution of the image.
print "Normalizing noisy image..."
nois_img_mean = nois_img.mean()
nois_img_std = nois_img.std()
normal_nois_img = nois_img - nois_img_mean
if nois_img_std > 0.01: # Divide by std. dev. if it is not zero
normal_nois_img /= nois_img_std
# Test saving and loading a noisy image.
print "Saving as TMP format..."
save_to_tmp("noisy.tmp", normal_nois_img)
print "Load from TMP format..."
loaded_img = load_from_tmp("noisy.tmp")[0]
# Check if saved and loaded image are quite similar (some small error
# could be expected)
if numpy.allclose(normal_nois_img, loaded_img):
print "Saved and loaded images are equal"
else:
print "Saved and loaded images are NOT equal"
开发者ID:Garthof,项目名称:scriptlets,代码行数:57,代码来源:tmpformat.py
示例15: plot_lena_overlay
def plot_lena_overlay():
plt.figure()
logo = ScipyLogo((300, 300), 180)
logo.plot_snake_curve()
logo.plot_circle()
img = lena()
#mask = logo.get_mask(img.shape, 'upper left')
#img[mask] = 255
plt.imshow(img)
开发者ID:drnlm,项目名称:scikits.image,代码行数:9,代码来源:scipy_logo.py
示例16: gen_lena
def gen_lena():
"""
Generate a (512, 512, 2) matrix where first layer is
lena image. And the second layer is an array of 0s
"""
from scipy.misc import lena
lena = np.atleast_3d(lena()).astype(np.float32)
zeros = np.zeros_like(lena)
feats = np.dstack([lena, zeros])
return feats
开发者ID:0x0all,项目名称:algorithms,代码行数:10,代码来源:benchmarks.py
示例17: test_downsample
def test_downsample():
"""
Tests register data down-sampling.
"""
image = register.RegisterData(misc.lena())
for factor in [1, 2, 4, 6, 8 ,10]:
subSampled = image.downsample(factor)
assert subSampled.data.shape[0] == image.data.shape[0] / factor
assert subSampled.data.shape[1] == image.data.shape[1] / factor
assert subSampled.coords.spacing == factor
开发者ID:pradal,项目名称:python-register,代码行数:10,代码来源:test_register_data.py
示例18: task5
def task5():
img_mat = np.asarray(normalize_intensity(lena()))
outputs = dict()
for param in (0.1, 0.3, 0.8):
outputs[param] = salt_and_pepper_noise(img_mat, param)
file_name = 'noisy_{}.png'.format(str(param).replace('.', '_'))
imsave(os.path.join(OUTPUT_DIR, file_name), outputs[param])
pl.imshow(outputs[0.1], cmap=cm.Greys_r)
pl.show()
开发者ID:mathiasose,项目名称:TDT4195,代码行数:10,代码来源:tasks.py
示例19: main
def main():
print "Loading Lena image..."
orig_img = misc.lena()[160:160+10, 160:160+10]
print "Image dtype: %s" % orig_img.dtype
print "Image size: %6d" % orig_img.size
print "Image shape: %3dx%3d" % (orig_img.shape[0], orig_img.shape[1])
print "Max value %3d at pixel %6d" % (orig_img.max(), orig_img.argmax())
print "Min value %3d at pixel %6d" % (orig_img.min(), orig_img.argmin())
print "Variance: %1.5f" % orig_img.var()
print "Standard deviation: %1.5f" % orig_img.std()
misc.imsave("orig.png", orig_img)
print "Generating noisy image..."
print "Noise standard deviation: %1.5f" % noise_sigma
# Generate additive white Gaussian noise (AWGN) with specifed sigma
normal_noise = np.random.normal(scale=noise_sigma, size=orig_img.size)
normal_noise = normal_noise.reshape(orig_img.shape)
nois_img = orig_img + normal_noise
misc.imsave("noisy.png", nois_img)
# Normalize image, that is, translate values in image so its distribution
# is comparable to a normal N(0, 1) (mean = 0.0, standard deviation = 1.0).
# This way, parameters of the denoising algorithm, like h and sigma, are
# independent of the values and distribution of the image.
print "Normalizing noisy image..."
nois_img_mean = nois_img.mean()
nois_img_std = nois_img.std()
normal_nois_img = np.empty(nois_img.shape, dtype=np.float32)
for x in xrange(normal_nois_img.shape[0]):
for y in xrange(normal_nois_img.shape[1]):
normal_nois_val = nois_img[x, y] - nois_img_mean
if nois_img_std != 0.000001: normal_nois_val /= nois_img_std
normal_nois_img[x, y] = normal_nois_val
print "Denoising image..."
normal_rest_img = denoise2D(normal_nois_img, True)
print "Denormalizing noisy image..."
rest_img = np.empty(nois_img.shape, dtype=orig_img.dtype)
for x in xrange(rest_img.shape[0]):
for y in xrange(rest_img.shape[1]):
rest_val = normal_rest_img[x, y] * nois_img_std
rest_val += nois_img_mean
rest_img[x, y] = rest_val
print "Storing denoised image..."
misc.imsave("denoised.png", rest_img)
开发者ID:Garthof,项目名称:scriptlets,代码行数:55,代码来源:naivenml.py
示例20: test_test_lena_npy_array
def test_test_lena_npy_array():
arr_in = lena()[::32, ::32].astype(DTYPE)
idx = [[4, 2], [4, 2]]
gt = np.array([1280.99987793, 992.0], dtype=DTYPE)
arr_out = lpool(arr_in, plugin=plugin, plugin_kwargs=plugin_kwargs)
gv = arr_out[idx]
assert_allclose_round(gv, gt, rtol=RTOL, atol=ATOL)
开发者ID:npinto,项目名称:sthor,代码行数:11,代码来源:test_lpool.py
注:本文中的scipy.misc.lena函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论