本文整理汇总了Python中skimage.util.pad函数的典型用法代码示例。如果您正苦于以下问题:Python pad函数的具体用法?Python pad怎么用?Python pad使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pad函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: prefilt
def prefilt(img, fc=4):
"""
assume greyscale (c==1), individual image(N==1)
"""
w = 5
s1 = fc/np.sqrt(np.log(2.0))
# pad images to reduce boundary artifacts
img = np.log(img+1)
img = util.pad(img, w, mode='symmetric')
sn, sm = img.shape
n = max(sn, sm)
n += np.mod(n, 2)
img = util.pad(img, ((0, n-sn), (0, n-sm)), mode='symmetric')
# filter
fx, fy = np.meshgrid(np.arange(-n/2, n/2), np.arange(-n/2, n/2))
gf = np.fft.fftshift(np.exp(-(fx**2+fy**2)/(s1**2)))
# whitening
output = img - np.real(np.fft.ifft2(np.fft.fft2(img)*gf))
# local contrast normalization
localstd = np.sqrt(
np.abs(np.fft.ifft2(np.fft.fft2(output**2)*gf)))
output = output / (0.2+localstd)
# crop output to have the same size as the input
output = output[w:sn-w, w:sm-w]
return output
开发者ID:yskmt,项目名称:sccomp,代码行数:33,代码来源:lmgist.py
示例2: test_check_negative_pad_amount
def test_check_negative_pad_amount(self):
arr = np.arange(30)
arr = np.reshape(arr, (6, 5))
kwargs = dict(mode='mean', stat_length=(3, ))
with pytest.raises(ValueError):
pad(arr, ((-2, 3), (3, 2)),
**kwargs)
开发者ID:andreydung,项目名称:scikit-image,代码行数:7,代码来源:test_arraypad.py
示例3: test_check_wrong_pad_amount
def test_check_wrong_pad_amount(self):
arr = np.arange(30)
arr = np.reshape(arr, (6, 5))
kwargs = dict(mode='mean', stat_length=(3, ))
with pytest.raises(TypeError):
pad(arr, ((2, 3, 4), (3, 2)),
**kwargs)
开发者ID:andreydung,项目名称:scikit-image,代码行数:7,代码来源:test_arraypad.py
示例4: test_pad_too_many_axes
def test_pad_too_many_axes(self):
arr = np.arange(30).reshape(5, 6)
# Attempt to pad using a 3D array equivalent
bad_shape = (((3,), (4,), (5,)), ((0,), (1,), (2,)))
with testing.raises(ValueError):
pad(arr, bad_shape, mode='constant')
开发者ID:Cadair,项目名称:scikit-image,代码行数:7,代码来源:test_arraypad.py
示例5: test_check_simple
def test_check_simple(self):
arr = np.arange(30)
arr = np.reshape(arr, (6, 5))
kwargs = dict(mode='mean', stat_length=(3, ))
with pytest.raises(ValueError):
pad(arr, ((2, 3), (3, 2), (4, 5)),
**kwargs)
开发者ID:andreydung,项目名称:scikit-image,代码行数:7,代码来源:test_arraypad.py
示例6: sliding_concentric_windows
def sliding_concentric_windows(self, img):
n_rows, n_cols = img.shape[:2]
y_a, x_a = 5, 5
y_b, x_b = 11, 11
new_img = np.zeros((n_rows, n_cols), dtype=np.uint)
img_a = util.pad(img, ((y_a/2, y_a/2), (x_a/2, x_a/2)), mode='constant')
img_b = util.pad(img, ((y_b/2, y_b/2), (x_b/2, x_b/2)), mode='constant')
blocks_a = util.view_as_windows(img_a, (y_a, x_a), step=1)
blocks_b = util.view_as_windows(img_b, (y_b, x_b), step=1)
for row in xrange(n_rows):
for col in xrange(n_cols):
mean_a = blocks_a[row, col].mean()
mean_b = blocks_b[row, col].mean()
r_mean = 0
if mean_a != 0:
r_mean = mean_b/float(mean_a)
if r_mean > 1.0:
new_img[row, col] = 0
else:
new_img[row, col] = 255
return new_img
开发者ID:allansp84,项目名称:license-plate,代码行数:29,代码来源:segmentation.py
示例7: test_shallow_statistic_range
def test_shallow_statistic_range(self):
test = np.arange(120).reshape(4, 5, 6)
pad_amt = [(1, 1) for axis in test.shape]
modes = ['maximum',
'mean',
'median',
'minimum',
]
for mode in modes:
assert_array_equal(pad(test, pad_amt, mode='edge'),
pad(test, pad_amt, mode=mode, stat_length=1))
开发者ID:andreydung,项目名称:scikit-image,代码行数:11,代码来源:test_arraypad.py
示例8: test_clip_statistic_range
def test_clip_statistic_range(self):
test = np.arange(30).reshape(5, 6)
pad_amt = [(3, 3) for axis in test.shape]
modes = ['maximum',
'mean',
'median',
'minimum',
]
for mode in modes:
assert_array_equal(pad(test, pad_amt, mode=mode),
pad(test, pad_amt, mode=mode, stat_length=30))
开发者ID:andreydung,项目名称:scikit-image,代码行数:11,代码来源:test_arraypad.py
示例9: data_augmentation_test
def data_augmentation_test(img_id=1, crop_size=200, pad_size=100):
Xb = np.array(Image.open('data/images/train/' + str(img_id) + '.jpg'),
dtype=np.uint8) / np.float32(255.)
im_size = Xb.shape[0]
frame_size = im_size + 2 * pad_size
print "X shape ", Xb.shape
padded = np.zeros((3, frame_size, frame_size))
for i in range(3):
padded[i] = pad(np.swapaxes(Xb, 0, 2)[i], (pad_size, pad_size), 'reflect')
padded = np.swapaxes(padded, 0, 2)
print "Padded shape ", padded.shape
lower_cut = (im_size - crop_size) / 2 + pad_size
upper_cut = (im_size + crop_size) / 2 + pad_size
shift_x = frame_size / 2
shift_y = shift_x
tf_shift = AffineTransform(translation=[-shift_x, -shift_y])
tf_shift_inv = AffineTransform(translation=[shift_x, shift_y])
scaling_factor = 0.2 * np.random.random() + 0.9
angle = 2 * pi * (np.random.random() - 0.5)
trans_x = np.random.randint(-5, 5)
trans_y = np.random.randint(-5, 5)
tf = AffineTransform(scale=(scaling_factor, scaling_factor),
rotation=angle, shear=None,
translation=(trans_x, trans_y))
padded = warp(padded, (tf_shift + (tf + tf_shift_inv)).inverse)
print "Padded shape after transform ", padded.shape
# Crop to desired size
tmp = padded[lower_cut:upper_cut, lower_cut:upper_cut, :]
print "Finally, cuts and shape: ", lower_cut, upper_cut, padded.shape
plt.imshow(tmp)
开发者ID:Wajsbrot,项目名称:bees,代码行数:35,代码来源:utils.py
示例10: test_check_median_stat_length
def test_check_median_stat_length(self):
a = np.arange(100).astype('f')
a[1] = 2.
a[97] = 96.
a = pad(a, (25, 20), 'median', stat_length=(3, 5))
b = np.array(
[ 2., 2., 2., 2., 2., 2., 2., 2., 2., 2.,
2., 2., 2., 2., 2., 2., 2., 2., 2., 2.,
2., 2., 2., 2., 2.,
0., 2., 2., 3., 4., 5., 6., 7., 8., 9.,
10., 11., 12., 13., 14., 15., 16., 17., 18., 19.,
20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
40., 41., 42., 43., 44., 45., 46., 47., 48., 49.,
50., 51., 52., 53., 54., 55., 56., 57., 58., 59.,
60., 61., 62., 63., 64., 65., 66., 67., 68., 69.,
70., 71., 72., 73., 74., 75., 76., 77., 78., 79.,
80., 81., 82., 83., 84., 85., 86., 87., 88., 89.,
90., 91., 92., 93., 94., 95., 96., 96., 98., 99.,
96., 96., 96., 96., 96., 96., 96., 96., 96., 96.,
96., 96., 96., 96., 96., 96., 96., 96., 96., 96.]
)
assert_array_equal(a, b)
开发者ID:andreydung,项目名称:scikit-image,代码行数:25,代码来源:test_arraypad.py
示例11: gist_gabor
def gist_gabor(img, param):
"""
Assume single image
Assume greyscale image
"""
w = param.number_blocks
G = param.G
be = param.boundary_extension
n_rows, n_cols = img.shape
c = 1
N = c
ny, nx, n_filters = G.shape
W = w*w
g = np.zeros((W*n_filters, N))
# pad image
img = util.pad(img, be, mode='symmetric')
img = np.fft.fft2(img)
k = 0
for n in range(n_filters):
ig = np.abs(np.fft.ifft2(img*G[:,:,n]))
ig = ig[be:ny-be, be:nx-be]
v = downN(ig, w)
g[k:k+W] = np.reshape(v.T, [W, N])
k = k + W
return g
开发者ID:yskmt,项目名称:sccomp,代码行数:32,代码来源:lmgist.py
示例12: test_check_large_pad
def test_check_large_pad(self):
a = np.arange(12)
a = np.reshape(a, (3, 4))
a = pad(a, (10, 12), 'wrap')
b = np.array(
[[10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10,
11, 8, 9, 10, 11, 8, 9, 10, 11],
[2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2,
3, 0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, 4, 5, 6, 7, 4, 5, 6, 7],
[10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10,
11, 8, 9, 10, 11, 8, 9, 10, 11],
[2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2,
3, 0, 1, 2, 3, 0, 1, 2, 3],
[6, 7, 4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6,
7, 4, 5, 6, 7, 4, 5, 6, 7],
[10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10,
11, 8, 9, 10, 11, 8, 9, 10, 11],
[2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2,
3, 0, 1, 2, 3, 0, 1, 2, 3],
[6, 7, 4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6,
7, 4, 5, 6, 7, 4, 5, 6, 7],
[10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10,
11, 8, 9, 10, 11, 8, 9, 10, 11],
[2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2,
3, 0, 1, 2, 3, 0, 1, 2, 3],
[6, 7, 4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6,
7, 4, 5, 6, 7, 4, 5, 6, 7],
[10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10, 11, 8, 9, 10,
11, 8, 9, 10, 11, 8, 9, 10, 11]]
)
assert_array_equal(a, b)
开发者ID:andreydung,项目名称:scikit-image,代码行数:59,代码来源:test_arraypad.py
示例13: image_padding
def image_padding(img, padding_value=0, crop_size=None, ismask=0):
h, w = img.shape[:2]
if crop_size is None:
pad_h = h
pad_w = w
else:
if h > w:
pad_h = int(crop_size/2.)
pad_w = int(1.*pad_h*w/h)
else:
pad_w = int(crop_size/2.)
pad_h = int(1.*pad_w*h/w)
if not ismask:
return pad(img, ((pad_h, pad_h), (pad_w, pad_w), (0, 0)), mode='constant', constant_values=int(padding_value)), pad_h, pad_w
else:
return pad(img, ((pad_h, pad_h), (pad_w, pad_w)), mode='constant', constant_values=0), pad_h, pad_w
开发者ID:RE-ID,项目名称:deepsaldet,代码行数:17,代码来源:predict_stage1.py
示例14: adj_matrix
def adj_matrix(Graph, skel_mat):
"""
Returns adjacency matrix for the given skeleton
binary matrix and the corresponding graph of nodes.
Parameters
--------
Graph : a graph of nodes; each node correspond to the
nonzero element of skeleton matrix and has the attrubutes
'index' and 'neig'
skel_mat : 3d binary matrix
Returns
-------
a_m : 2d array of the dimentions n by n, where n is equal to
the number of nodes; matrix is symmetric, nonzero elements
indicate the connections between the nodes.
Examples
-------
>>>b = np.zeros((3,3,3))
>>>b[1,1,:] = 1
>>>b
array([[[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]],
[[ 0., 0., 0.],
[ 1., 1., 1.],
[ 0., 0., 0.]],
[[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]]])
>>>G = label(b)
>>>adj_m = adj_matrix(G,b)
>>>adj_m
array([[ 0., 1., 0.],
[ 1., 0., 1.],
[ 0., 1., 0.]])
"""
point = nx.get_node_attributes(Graph, 'index')
node_label = dict( (j,i) for i,j in point.iteritems())
a_pad = util.pad(skel_mat,((1,1),(1,1),(1,1)), 'constant')
n = nx.number_of_nodes(Graph)
a_m = np.zeros((n,n))
for i in Graph.nodes():
vol = np.zeros(a_pad.shape)
co = point[i]
vol[co[0]:co[0]+3, co[1]:co[1]+3,
co[2]:co[2]+3] = a_pad[co[0]:co[0]+3, co[1]:co[1]+3, co[2]:co[2]+3]
nz_vol = np.transpose(np.nonzero(vol)) - 1
el = tuple(map(tuple,nz_vol))
for elem in el:
j = node_label[elem]
a_m [i-1,j-1] = 1
a_m = a_m - np.eye(n)
return a_m
开发者ID:YuliyaKar,项目名称:Skeleton_to_graph,代码行数:58,代码来源:skel_to_graph.py
示例15: read_img_file_PIL
def read_img_file_PIL(file_path, size=(32,32)):
img = Image.open(file_path).convert('L')
img.thumbnail(size, Image.NEAREST)
data = np.array(img)
shape = data.shape
append_top = int(ceil(max(0, size[0] - shape[0])/2.0))
append_bot = int(floor(max(0, size[0] - shape[0])/2.0))
data = util.pad(data, ((append_top, append_bot),
(0,0)), mode='constant', constant_values=0)
return data
开发者ID:krsnewwave,项目名称:distracted_drivers,代码行数:10,代码来源:notebook_functions.py
示例16: center_crop_reflect
def center_crop_reflect(img, size):
"""Center crop with mirror padding if necessary"""
a0 = max(0, size[0] - img.shape[0])
a1 = max(0, size[1] - img.shape[1])
v = ((a0//2, a0-a0//2), (a1//2, a1-a1//2))
if img.ndim == 3:
v = v + ((0, 0),)
pimg = util.pad(img, v, mode='reflect')
return center_crop(pimg, size)
开发者ID:caomw,项目名称:autocolorize,代码行数:11,代码来源:image.py
示例17: transform
def transform(self, Xb, yb):
Xb, yb = super(DataAugmentationBatchIterator, self).transform(Xb, yb)
# Flip half of the images in this batch at random:
bs = Xb.shape[0]
indices = np.random.choice(bs, bs / 2, replace=False)
Xb[indices] = Xb[indices, :, :, ::-1]
# Divide pixels values by 255 to make it fit in [-1;1], for SimilarityTransform compatibility
Xb /= np.float32(255.)
# Change shape from [Batch_size, nb_channels, width, height] to [Batch_size, width, height, nb_channels]
Xb = np.swapaxes(Xb, 1, 3)
# Define relevant shapes
im_size = Xb.shape[1]
frame_size = im_size + 2 * self.pad_size
lower_cut = (frame_size - self.crop_size) / 2
upper_cut = (frame_size + self.crop_size) / 2
shift_x = frame_size / 2
shift_y = shift_x
# Necessary shifts to allow rotation around center
tf_shift = SimilarityTransform(translation=[-shift_x, -shift_y])
tf_shift_inv = SimilarityTransform(translation=[shift_x, shift_y])
# Xb_new = np.zeros((bs,self.crop_size,self.crop_size,self.nb_channels))
for i in xrange(bs):
pic = Xb[i] # Picture as a [width, height, nb_channels] np.array
# Pad image to avoid black regions after zoom/rotation/translation
padded = np.zeros((self.nb_channels, frame_size, frame_size))
for j in xrange(self.nb_channels):
padded[j] = pad(np.swapaxes(pic, 0, 2)[j], (self.pad_size, self.pad_size), 'reflect')
padded = np.swapaxes(padded, 0, 2)
# Pick random values
scaling_factor_tmp = 2 * np.random.random() * self.scale_delta + (1. - self.scale_delta)
scaling_factor = random.choice([1./scaling_factor_tmp, 1., scaling_factor_tmp])
angle = 2 * pi * (np.random.random() - 0.5) * self.angle_factor
trans_x = np.random.randint(-self.max_trans, self.max_trans)
trans_y = np.random.randint(-self.max_trans, self.max_trans)
# Apply similarity transform to zoom, rotate and translate
tf = SimilarityTransform(scale=scaling_factor, rotation=angle, translation=(trans_x, trans_y))
padded = warp(padded, (tf_shift + (tf + tf_shift_inv)).inverse)
# Crop to desired size
Xb[i] = padded[lower_cut:upper_cut, lower_cut:upper_cut, :]
Xb = np.swapaxes(Xb, 1, 3)
Xb *= np.float32(255.)
return Xb, yb
开发者ID:Wajsbrot,项目名称:bees,代码行数:53,代码来源:data_augmentation.py
示例18: test_check_median_02
def test_check_median_02(self):
a = np.array([[3, 1, 4], [4, 5, 9], [9, 8, 2]])
a = pad(a.T, 1, 'median').T
b = np.array([
[5, 4, 5, 4, 5],
[3, 3, 1, 4, 3],
[5, 4, 5, 9, 5],
[8, 9, 8, 2, 8],
[5, 4, 5, 4, 5]])
assert_array_equal(a, b)
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:12,代码来源:test_arraypad.py
示例19: test_check_2d
def test_check_2d(self):
arr = np.arange(20).reshape(4, 5).astype(np.float64)
test = pad(arr, (2, 2), mode='linear_ramp', end_values=(0, 0))
expected = np.array(
[[0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0.5, 1., 1.5, 2., 1., 0.],
[0., 0., 0., 1., 2., 3., 4., 2., 0.],
[0., 2.5, 5., 6., 7., 8., 9., 4.5, 0.],
[0., 5., 10., 11., 12., 13., 14., 7., 0.],
[0., 7.5, 15., 16., 17., 18., 19., 9.5, 0.],
[0., 3.75, 7.5, 8., 8.5, 9., 9.5, 4.75, 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0.]])
assert_allclose(test, expected)
开发者ID:andreydung,项目名称:scikit-image,代码行数:13,代码来源:test_arraypad.py
示例20: test_blob_dog
def test_blob_dog():
r2 = math.sqrt(2)
img = np.ones((512, 512))
xs, ys = circle(400, 130, 5)
img[xs, ys] = 255
xs, ys = circle(100, 300, 25)
img[xs, ys] = 255
xs, ys = circle(200, 350, 45)
img[xs, ys] = 255
blobs = blob_dog(img, min_sigma=5, max_sigma=50)
radius = lambda x: r2 * x[2]
s = sorted(blobs, key=radius)
thresh = 5
b = s[0]
assert abs(b[0] - 400) <= thresh
assert abs(b[1] - 130) <= thresh
assert abs(radius(b) - 5) <= thresh
b = s[1]
assert abs(b[0] - 100) <= thresh
assert abs(b[1] - 300) <= thresh
assert abs(radius(b) - 25) <= thresh
b = s[2]
assert abs(b[0] - 200) <= thresh
assert abs(b[1] - 350) <= thresh
assert abs(radius(b) - 45) <= thresh
# Testing no peaks
img_empty = np.zeros((100,100))
assert blob_dog(img_empty).size == 0
# Testing 3D
r = 10
pad = 10
im3 = ellipsoid(r, r, r)
im3 = util.pad(im3, pad, mode='constant')
blobs = blob_dog(im3, min_sigma=3, max_sigma=10,
sigma_ratio=1.2, threshold=0.1)
b = blobs[0]
assert b[0] == r + pad + 1
assert b[1] == r + pad + 1
assert b[2] == r + pad + 1
assert abs(math.sqrt(3) * b[3] - r) < 1
开发者ID:Cadair,项目名称:scikit-image,代码行数:51,代码来源:test_blob.py
注:本文中的skimage.util.pad函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论