本文整理汇总了Python中skimage.data.text函数的典型用法代码示例。如果您正苦于以下问题:Python text函数的具体用法?Python text怎么用?Python text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了text函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
"""Load image, apply histogram stretching and cumulative histogram
equalization. Plot the results."""
img = data.text()
height, width = img.shape
nb_pixels = height * width
# apply histogram stretching
gray_min = np.min(img)
gray_max = np.max(img)
img_hist_stretched = (img - gray_min) * (255 / (gray_max - gray_min))
img_hist_stretched = img_hist_stretched.astype(np.uint8)
# apply cumulative histogram equalization
img_cumulative = np.zeros(img.shape, dtype=np.uint8)
hist_cumulative = [0] * 256
running_sum = 0
hist, edges = np.histogram(img, 256, (0, 255))
for i in range(256):
count = hist[i]
running_sum += count
hist_cumulative[i] = running_sum / nb_pixels
for i in range(256):
img_cumulative[img == i] = int(256 * hist_cumulative[i])
# plot
plot_images_grayscale(
[img, img_hist_stretched, img_cumulative],
["Image", "Histogram stretched to 0-255", "Cumulative Histogram Equalization"]
)
开发者ID:aleju,项目名称:computer-vision-algorithms,代码行数:32,代码来源:histogram_equalization.py
示例2: test_RGB
def test_RGB():
img = gaussian(data.text(), 1)
imgR = np.zeros((img.shape[0], img.shape[1], 3))
imgG = np.zeros((img.shape[0], img.shape[1], 3))
imgRGB = np.zeros((img.shape[0], img.shape[1], 3))
imgR[:, :, 0] = img
imgG[:, :, 1] = img
imgRGB[:, :, :] = img[:, :, None]
x = np.linspace(5, 424, 100)
y = np.linspace(136, 50, 100)
init = np.array([x, y]).T
snake = active_contour(imgR, init, bc='fixed',
alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1)
refx = [5, 9, 13, 17, 21, 25, 30, 34, 38, 42]
refy = [136, 135, 134, 133, 132, 131, 129, 128, 127, 125]
assert_equal(np.array(snake[:10, 0], dtype=np.int32), refx)
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
snake = active_contour(imgG, init, bc='fixed',
alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1)
assert_equal(np.array(snake[:10, 0], dtype=np.int32), refx)
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
snake = active_contour(imgRGB, init, bc='fixed',
alpha=0.1, beta=1.0, w_line=-5/3., w_edge=0, gamma=0.1)
assert_equal(np.array(snake[:10, 0], dtype=np.int32), refx)
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
开发者ID:TonyMou,项目名称:scikit-image,代码行数:25,代码来源:test_active_contour_model.py
示例3: test_free_reference
def test_free_reference():
img = data.text()
x = np.linspace(5, 424, 100)
y = np.linspace(70, 40, 100)
init = np.array([x, y]).T
snake = active_contour(gaussian(img, 3), init, bc='free',
alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1)
refx = [10, 13, 16, 19, 23, 26, 29, 32, 36, 39]
refy = [76, 76, 75, 74, 73, 72, 71, 70, 69, 69]
assert_equal(np.array(snake[:10, 0], dtype=np.int32), refx)
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
开发者ID:TonyMou,项目名称:scikit-image,代码行数:11,代码来源:test_active_contour_model.py
示例4: test_fixed_reference
def test_fixed_reference():
img = data.text()
x = np.linspace(5, 424, 100)
y = np.linspace(136, 50, 100)
init = np.array([x, y]).T
snake = active_contour(gaussian(img, 1), init, bc='fixed',
alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1)
refx = [5, 9, 13, 17, 21, 25, 30, 34, 38, 42]
refy = [136, 135, 134, 133, 132, 131, 129, 128, 127, 125]
assert_equal(np.array(snake[:10, 0], dtype=np.int32), refx)
assert_equal(np.array(snake[:10, 1], dtype=np.int32), refy)
开发者ID:TonyMou,项目名称:scikit-image,代码行数:11,代码来源:test_active_contour_model.py
示例5: test_triangle_float_images
def test_triangle_float_images():
text = data.text()
int_bins = text.max() - text.min() + 1
# Set nbins to match the uint case and threshold as float.
assert(round(threshold_triangle(
text.astype(np.float), nbins=int_bins)) == 104)
# Check that rescaling image to floats in unit interval is equivalent.
assert(round(threshold_triangle(text / 255., nbins=int_bins) * 255) == 104)
# Repeat for inverted image.
assert(round(threshold_triangle(
np.invert(text).astype(np.float), nbins=int_bins)) == 151)
assert (round(threshold_triangle(
np.invert(text) / 255., nbins=int_bins) * 255) == 151)
开发者ID:Gildus,项目名称:scikit-image,代码行数:13,代码来源:test_thresholding.py
示例6: profile
def profile():
import time
from iib.simulation import CLContext
from skimage import io, data, transform
gs, wgs = 256, 16
# Load some test data
r = transform.resize
sigs = np.empty((gs, gs, 4), np.float32)
sigs[:, :, 0] = r(data.coins().astype(np.float32) / 255.0, (gs, gs))
sigs[:, :, 1] = r(data.camera().astype(np.float32) / 255.0, (gs, gs))
sigs[:, :, 2] = r(data.text().astype(np.float32) / 255.0, (gs, gs))
sigs[:, :, 3] = r(data.checkerboard().astype(np.float32) / 255.0, (gs, gs))
sigs[:, :, 2] = r(io.imread("../scoring/corpus/rds/turing_001.png",
as_grey=True), (gs, gs))
sigs[:, :, 3] = io.imread("../scoring/corpus/synthetic/blobs.png",
as_grey=True)
sigs = sigs.reshape(gs*gs*4)
# Set up OpenCL
ctx = cl.create_some_context(interactive=False)
queue = cl.CommandQueue(ctx)
mf = cl.mem_flags
ifmt_f = cl.ImageFormat(cl.channel_order.RGBA, cl.channel_type.FLOAT)
bufi = cl.Image(ctx, mf.READ_ONLY, ifmt_f, (gs, gs))
cl.enqueue_copy(queue, bufi, sigs, origin=(0, 0), region=(gs, gs))
clctx = CLContext(ctx, queue, ifmt_f, gs, wgs)
# Compile the kernels
feats = cl.Program(ctx, features_cl()).build()
rdctn = cl.Program(ctx, reduction.reduction_sum_cl()).build()
blur2 = cl.Program(ctx, convolution.gaussian_cl([np.sqrt(2.0)]*4)).build()
blur4 = cl.Program(ctx, convolution.gaussian_cl([np.sqrt(4.0)]*4)).build()
iters = 500
t0 = time.time()
for i in range(iters):
get_features(clctx, feats, rdctn, blur2, blur4, bufi)
print((time.time() - t0)/iters)
开发者ID:adamgreig,项目名称:iib,代码行数:39,代码来源:features.py
示例7: test_text
def test_text():
""" Test that "text" image can be loaded. """
data.text()
开发者ID:Gildus,项目名称:scikit-image,代码行数:3,代码来源:test_data.py
示例8: test_triangle_uint_images
def test_triangle_uint_images():
assert(threshold_triangle(np.invert(data.text())) == 151)
assert(threshold_triangle(data.text()) == 104)
assert(threshold_triangle(data.coins()) == 80)
assert(threshold_triangle(np.invert(data.coins())) == 175)
开发者ID:Gildus,项目名称:scikit-image,代码行数:5,代码来源:test_thresholding.py
示例9:
from skimage import data, transform
import numpy as np
import matplotlib.pyplot as plt
image = data.text()
plt.imshow(image, cmap=plt.cm.gray)
target = np.array(plt.ginput(4))
source = np.array([(0, 0), (0, 50), (300, 50), (300, 0)])
plt.close()
pt = transform.ProjectiveTransform()
pt.estimate(source, target)
warped = transform.warp(image, pt, output_shape=(50, 300))
f, (ax0, ax1) = plt.subplots(1, 2)
ax0.imshow(image, cmap=plt.cm.gray)
ax1.imshow(warped, cmap=plt.cm.gray)
plt.show()
开发者ID:salmcdonagh,项目名称:python-seminar,代码行数:25,代码来源:warp_text.py
示例10:
fig = plt.figure(figsize=(7, 7))
ax = fig.add_subplot(111)
plt.gray()
ax.imshow(img)
ax.plot(init[:, 0], init[:, 1], '--r', lw=3)
ax.plot(snake[:, 0], snake[:, 1], '-b', lw=3)
ax.set_xticks([]), ax.set_yticks([])
ax.axis([0, img.shape[1], img.shape[0], 0])
######################################################################
# Here we initialize a straight line between two points, `(5, 136)` and
# `(424, 50)`, and require that the spline has its end points there by giving
# the boundary condition `bc='fixed'`. We furthermore make the algorithm
# search for dark lines by giving a negative `w_line` value.
img = data.text()
x = np.linspace(5, 424, 100)
y = np.linspace(136, 50, 100)
init = np.array([x, y]).T
if new_scipy:
snake = active_contour(gaussian(img, 1), init, bc='fixed',
alpha=0.1, beta=1.0, w_line=-5, w_edge=0, gamma=0.1)
fig = plt.figure(figsize=(9, 5))
ax = fig.add_subplot(111)
plt.gray()
ax.imshow(img)
ax.plot(init[:, 0], init[:, 1], '--r', lw=3)
ax.plot(snake[:, 0], snake[:, 1], '-b', lw=3)
开发者ID:andreydung,项目名称:scikit-image,代码行数:31,代码来源:plot_active_contours.py
示例11:
"""
This example illustrates the use of the horizontal Sobel filter, to compute
horizontal gradients.
"""
from skimage import data, filter
import matplotlib.pyplot as plt
text = data.text()
hsobel_text = filter.hsobel(text)
plt.figure(figsize=(12, 3))
plt.subplot(121)
plt.imshow(text, cmap='gray', interpolation='nearest')
plt.axis('off')
plt.subplot(122)
plt.imshow(hsobel_text, cmap='jet', interpolation='nearest')
plt.axis('off')
plt.tight_layout()
plt.show()
开发者ID:B-Rich,项目名称:scipy-lecture-notes,代码行数:21,代码来源:plot_sobel.py
示例12: test
def test():
import matplotlib.pyplot as plt
from skimage import io, data, transform
from iib.simulation import CLContext
gs, wgs = 256, 16
# Load some test data
r = transform.resize
sigs = np.empty((gs, gs, 4), np.float32)
sigs[:, :, 0] = r(data.coins().astype(np.float32) / 255.0, (gs, gs))
sigs[:, :, 1] = r(data.camera().astype(np.float32) / 255.0, (gs, gs))
sigs[:, :, 2] = r(data.text().astype(np.float32) / 255.0, (gs, gs))
sigs[:, :, 3] = r(data.checkerboard().astype(np.float32) / 255.0, (gs, gs))
sigs[:, :, 2] = r(io.imread("../scoring/corpus/rds/turing_001.png",
as_grey=True), (gs, gs))
sigs[:, :, 3] = io.imread("../scoring/corpus/synthetic/blobs.png",
as_grey=True)
#sq = np.arange(256).astype(np.float32).reshape((16, 16)) / 255.0
#sigs[:, :, 0] = np.tile(sq, (16, 16))
sigs = sigs.reshape(gs*gs*4)
# Set up OpenCL
ctx = cl.create_some_context(interactive=False)
queue = cl.CommandQueue(ctx)
mf = cl.mem_flags
ifmt_f = cl.ImageFormat(cl.channel_order.RGBA, cl.channel_type.FLOAT)
bufi = cl.Image(ctx, mf.READ_ONLY, ifmt_f, (gs, gs))
cl.enqueue_copy(queue, bufi, sigs, origin=(0, 0), region=(gs, gs))
clctx = CLContext(ctx, queue, ifmt_f, gs, wgs)
# Compile the kernels
feats = cl.Program(ctx, features_cl()).build()
rdctn = cl.Program(ctx, reduction.reduction_sum_cl()).build()
blur2 = cl.Program(ctx, convolution.gaussian_cl([np.sqrt(2.0)]*4)).build()
blur4 = cl.Program(ctx, convolution.gaussian_cl([np.sqrt(4.0)]*4)).build()
entropy = get_entropy(clctx, feats, rdctn, bufi)
print("Average entropy:", entropy)
variance = get_variance(clctx, feats, rdctn, bufi)
print("Variance:", variance)
edges = get_edges(clctx, feats, rdctn, blur4, bufi, summarise=False)
edge_counts = get_edges(clctx, feats, rdctn, blur4, bufi)
print("Edge pixel counts:", edge_counts)
blobs = get_blobs(clctx, feats, rdctn, blur2, bufi, summarise=False)
features = get_features(clctx, feats, rdctn, blur2, blur4, bufi)
print("Feature vector:")
print(features)
# Plot the edges and blobs
for i in range(4):
plt.subplot(4, 3, i*3+1)
img = sigs.reshape((gs, gs, 4))[:, :, i]
plt.imshow(img, cmap="gray")
plt.xticks([])
plt.yticks([])
plt.subplot(4, 3, i*3+2)
img = edges.reshape((gs, gs, 4))[:, :, i]
plt.imshow(img, cmap="gray")
plt.xticks([])
plt.yticks([])
ax = plt.subplot(4, 3, i*3+3)
img = sigs.reshape((gs, gs, 4))[:, :, i]
plt.imshow(img, cmap="gray")
plt.xticks([])
plt.yticks([])
for j in range(len(blobs)):
sblobs = blobs[j]
s = 2**(j+1)
r = np.sqrt(2.0) * s
im = sblobs[:, :, i]
posns = np.transpose(im.nonzero()) * 2**(j+1)
for xy in posns:
circ = plt.Circle((xy[1], xy[0]), r, color="green", fill=False)
ax.add_patch(circ)
plt.show()
开发者ID:adamgreig,项目名称:iib,代码行数:82,代码来源:features.py
示例13: plot_harris_points
from matplotlib import pyplot as plt
from skimage import data, img_as_float
from skimage.feature import harris
def plot_harris_points(image, filtered_coords):
""" plots corners found in image"""
plt.imshow(image)
y, x = np.transpose(filtered_coords)
plt.plot(x, y, 'b.')
plt.axis('off')
# display results
plt.figure(figsize=(8, 3))
im_lena = img_as_float(data.lena())
im_text = img_as_float(data.text())
filtered_coords = harris(im_lena, min_distance=4)
plt.axes([0, 0, 0.3, 0.95])
plot_harris_points(im_lena, filtered_coords)
filtered_coords = harris(im_text, min_distance=4)
plt.axes([0.2, 0, 0.77, 1])
plot_harris_points(im_text, filtered_coords)
plt.show()
开发者ID:GerardoLopez,项目名称:scikits-image,代码行数:30,代码来源:plot_harris.py
示例14: test_triangle_images
def test_triangle_images():
assert threshold_triangle(np.invert(data.text())) == 151
assert threshold_triangle(data.text()) == 104
assert threshold_triangle(data.coins()) == 80
assert threshold_triangle(np.invert(data.coins())) == 175
开发者ID:Hiyorimi,项目名称:scikit-image,代码行数:5,代码来源:test_thresholding.py
示例15: autolevel
==================================
Demo of a CollectionViewer for viewing collections of images with the
`autolevel` rank filter connected as a plugin.
"""
from skimage import data
from skimage.filter import rank
from skimage.morphology import disk
from skimage.viewer import CollectionViewer
from skimage.viewer.widgets import Slider
from skimage.viewer.plugins.base import Plugin
# Wrap autolevel function to make the disk size a filter argument.
def autolevel(image, disk_size):
return rank.autolevel(image, disk(disk_size))
img_collection = [data.camera(), data.coins(), data.text()]
plugin = Plugin(image_filter=autolevel)
plugin += Slider("disk_size", 2, 8, value_type="int")
plugin.name = "Autolevel"
viewer = CollectionViewer(img_collection)
viewer += plugin
viewer.show()
开发者ID:alexeyum,项目名称:scikit-image,代码行数:30,代码来源:collection_plugin.py
注:本文中的skimage.data.text函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论