本文整理汇总了Python中skimage.feature.local_binary_pattern函数的典型用法代码示例。如果您正苦于以下问题:Python local_binary_pattern函数的具体用法?Python local_binary_pattern怎么用?Python local_binary_pattern使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了local_binary_pattern函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: logistic_lbp_diff
def logistic_lbp_diff(image1, image2, gamma=1e-3, points=4, radius=2):
"""
Generate local binary patterns (LBP) for each of the images by taking the
average across the color components (assumed to be axis = 0), and then
generating a LBP using a given number of points and comparing at a given
radius away from the center of the image. The distance between the LBPs
is regressed. gamma, points, and radius defaults chosen purely
hearuistically to provide decent dynamic range as seen in
image_handling_tb.ipynb, figure 14.
"""
return logistic_vector_dist(
local_binary_pattern(np.average(image1, axis=0), points, radius),
local_binary_pattern(np.average(image2, axis=0), points, radius),
gamma)
示例2: fit
def fit(self, modality, ground_truth=None, cat=None):
"""Compute the LBP images in the three-ortogonal planes.
Parameters
----------
modality : object of type TemporalModality
The modality object of interest.
ground-truth : object of type GTModality or None
The ground-truth of GTModality. If None, the whole data will be
considered.
cat : str or None
String corresponding at the ground-truth of interest. Cannot be
None if ground-truth is not None.
Return
------
self : object
Return self.
"""
super(LBPExtraction, self).fit(modality=modality,
ground_truth=ground_truth,
cat=cat)
# Fix the z axis
lbp_z = np.zeros(modality.data_.shape)
for z in range(modality.data_.shape[2]):
lbp_z[:, :, z] = local_binary_pattern(modality.data_[:, :, z],
self.p, self.r,
method=self.kind)
# Fix the x axis
lbp_x = np.zeros(modality.data_.shape)
for x in range(modality.data_.shape[1]):
lbp_x[:, x, :] = local_binary_pattern(modality.data_[:, x, :],
self.p, self.r,
method=self.kind)
# Fix the y axis
lbp_y = np.zeros(modality.data_.shape)
for y in range(modality.data_.shape[0]):
lbp_y[y, :, :] = local_binary_pattern(modality.data_[y, :, :],
self.p, self.r,
method=self.kind)
self.data_ = np.array((lbp_z, lbp_x, lbp_y))
return self
示例3: lbp
def lbp(self, image, label_bboxes, axes, mins, maxs):
rawbbox = image
ccbboxobject, passed, ccbboxexcl = label_bboxes
#FIXME: there is a mess about which of the lbp features are computed (obj, excl or incl)
import skimage.feature as ft
P=8
R=1
lbp_total = np.zeros(passed.shape)
for iz in range(maxs.z - mins.z):
#an lbp image
bboxkey = [slice(None)] * 3
bboxkey[axes.z] = iz
bboxkey = tuple(bboxkey)
lbp_total[bboxkey] = ft.local_binary_pattern(rawbbox[bboxkey], P, R, "uniform")
#extract relevant parts
lbp_incl = lbp_total[passed]
lbp_excl = lbp_total[ccbboxexcl.astype(bool)]
lbp_obj = lbp_total[ccbboxobject.astype(bool)]
lbp_hist_incl, _ = np.histogram(lbp_incl, normed=True, bins=(P + 2), range=(0, P + 2))
lbp_hist_excl, _ = np.histogram(lbp_excl, normed=True, bins=(P + 2), range=(0, P + 2))
lbp_hist_obj, _ = np.histogram(lbp_obj, normed=True, bins=(P + 2), range=(0, P + 2))
result = {}
result["lbp_incl"] = lbp_hist_incl
result["lbp_excl"] = lbp_hist_excl
result["lbp"] = lbp_hist_obj
return result
示例4: predictImg
def predictImg(img):
img = transform.resize(img, (100, 150))
lbp = feature.local_binary_pattern(img, n_points, radius, METHOD)
lbp = lbp.flatten()
k = dt.predict(lbp)
return tags[k[0]]
示例5: trainSys
def trainSys():
global a
global tags
i = 0
print "Starting training..."
directory = "/home/leroy/Desktop/ATI - Mini/datasets/"
for key, ta in tags.iteritems():
folder = directory + ta + '/'
for file in os.listdir(folder):
file2 = folder + file
img = io.imread(file2, as_grey = True)
img = transform.resize(img, (100, 150))
lbp = feature.local_binary_pattern(img, n_points, radius, METHOD)
lbp = lbp.flatten()
a[i] = lbp
i = i + 1
input_images_tags = numpy.ones(20)
input_images_tags2 = numpy.empty(20)
input_images_tags2.fill(2)
input_images_tags3 = numpy.empty(20)
input_images_tags3.fill(3)
input_images_tags4 = numpy.empty(20)
input_images_tags4.fill(4)
#input_images_tags3 = numpy.concatenate([input_images_tags3, input_images_tags4])
input_images_tags2 = numpy.concatenate([input_images_tags2, input_images_tags3])
input_images_tags = numpy.concatenate([input_images_tags, input_images_tags2])
dt.fit(a, input_images_tags)
print "Training Successfully Completed!"
示例6: calculateLBP
def calculateLBP(self):
paramList = list()
with open(self.paramTxt) as f:
for line in f:
paramList.append(int(line.strip()))
print(paramList)
for image in self.trainDict.iterkeys():
print(image)
img = cv2.imread(image)
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# radius = 3
# noPoints = 8 * radius
radius = paramList[0]
noPoints = paramList[1] * radius
print(radius)
print(noPoints)
lbpImage = local_binary_pattern(imgGray, noPoints, radius, method='uniform')
# Calculate the histogram
x = itemfreq(lbpImage.ravel())
# normalize the histogram
hist = x[:, 1] / sum(x[:, 1])
# hist = cv2.calcHist(lbp, [0], None, [256], [0, 256])
# cv2.normalize(hist,hist)
# hist = hist.flatten()
self.addrImg.append(image)
self.lbpHistogram.append(hist)
self.tagNo.append(self.trainDict.get(image))
joblib.dump((self.addrImg, self.lbpHistogram, self.tagNo), "lbp.pkl", compress=3)
示例7: LBP
def LBP(self, img, save=False, parms=None, subtract=False):
"""Get the LBP image
(reference: http://goo.gl/aeADZd)
@param img: image array
Keyword arguments:
save -- True to save the image
parms -- [points, radius] (default: None)
subtract -- True to subtract values to pts (default: False)
"""
from skimage.feature import local_binary_pattern
if self.is_rgb(img):
img = self.gray(img)
if parms is None:
pts = int(img.shape[0]*img.shape[1]*0.0003)
radius = min(img.shape[0], img.shape[1])*0.015
else:
pts = parms[0]
radius = parms[1]
lbp = local_binary_pattern(img, pts, radius, method='uniform')
if subtract:
lbp = np.abs(lbp - pts)
if save:
self.pl.plot_matrix(lbp, fname='lbp_cm.png', show_text=False,
show_axis=False, norm=False)
return lbp
示例8: pca_hash
def pca_hash(fxy,pca):
lbp = local_binary_pattern(fxy,3,24)
#print(len(flattn(lbp)))
#print(np.array([flattn(lbp)]).shape)
res = pca.transform(np.array([flattn(lbp)]))
#print(res.shape)
return res[0]
示例9: __init__
def __init__(self, clf):
'''
Classifies and scores eyes based
on whether they are open or closed.
INPUTS:
clf - a classifier
the following are defined by the clf:
n_size - a float, the size of the LBP
n_circ_sym - number of the LBP divisions to use
n_splt - how many times to symmetrically
subdivide the image
trim - the number of pixels to trim off the
the borders of the returned LBP image.
scaler - a standard scaler
'''
self.clf = clf
self._n_size = clf.n_size
self._n_circ_sym = clf.n_circ_sym
self._n_split = clf.n_splits
self._trim = clf.trim
self._resize = clf.img_size
self.scaler = clf.scaler
self.f_lbp = lambda x: feature.local_binary_pattern(x,
self._n_circ_sym,
self._n_size).astype(int)
示例10: get_features
def get_features(directory):
features = []
for fn in iglob("%s/*.png" % directory):
image = color.rgb2gray(io.imread(fn))
lbp_image = feature.local_binary_pattern(image, LBP_POINTS, LBP_RADIUS, "uniform")
features.append(get_histogram_feature(lbp_image))
return features
示例11: ExtractLBPFeatures
def ExtractLBPFeatures(img):
# This function extracts LBP features from a given image
radius = 3
n_points = 8 * radius
lbp_feature = local_binary_pattern(image,n_points,radius)
return lbp_feature
示例12: retrieve_LBP_feature_histogram
def retrieve_LBP_feature_histogram(image_path):
try:
# Read feature directly from file
image_feature_path = image_path + FEATURE_EXTENSION
if os.path.isfile(image_feature_path):
LBP_feature_histogram = np.genfromtxt(image_feature_path, delimiter=",")
return LBP_feature_histogram
# Define LBP parameters
radius = 5
n_points = 8
bins_num = pow(2, n_points)
LBP_value_range = (0, pow(2, n_points) - 1)
# Retrieve feature
assert os.path.isfile(image_path)
image_content_in_gray = imread(image_path, as_grey=True)
image_content_in_gray = img_as_ubyte(image_content_in_gray)
LBP_feature = local_binary_pattern(image_content_in_gray, n_points, radius)
LBP_feature_histogram, _ = np.histogram(LBP_feature, bins=bins_num, range=LBP_value_range, density=True)
# Save feature to file
assert LBP_feature_histogram is not None
np.savetxt(image_feature_path, LBP_feature_histogram, delimiter=",")
return LBP_feature_histogram
except:
print("Unable to retrieve LBP feature histogram in %s." % (os.path.basename(image_path)))
return None
示例13: lbf
def lbf(infile):
result = []
label = []
ix = 0
for here, i in enumerate(open(infile).readlines()):
ix +=1
imgpath, l = i.split(',')
if os.path.exists(imgpath):
im = cv2.imread(imgpath)
im = cv2.resize(im, (200, 200))
im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
radius = 3
no_points = 8 * radius
lbp = local_binary_pattern(im_gray, no_points, radius, method='uniform')
x = itemfreq(lbp.ravel())
hist = x[:, 1]/sum(x[:, 1])
result.append(hist)
if "FE" in l:
label.append(1)
else:
label.append(-1)
print len(result)
print len(label)
示例14: extract
def extract(self, image):
features = np.array([])
vec = []
if 'raw' in self.features:
vec = image.flatten()
features = np.append(features, vec)
vec = []
if 'textons' in self.features:
import gen_histogram as tx
vec = np.array(tx.histogram(image, self.centers))
features = np.append(features, vec)
vec = []
if 'hog' in self.features:
vec = hog(image, cells_per_block=(3, 3))
vec = np.append(vec, hog(image, cells_per_block=(4, 4)))
vec = np.append(vec, hog(image, cells_per_block=(1, 1)))
vec = np.append(vec, hog(image, cells_per_block=(2, 2)))
features = np.append(features, vec)
vec = []
if 'lbp' in self.features:
vec = local_binary_pattern(image, 24, 3).flatten()
features = np.append(features, vec)
vec = []
if 'daisy' in self.features:
vec = daisy(image).flatten()
features = np.append(features, vec)
return features
示例15: get_lbp
def get_lbp(img):
# settings for LBP
radius = 4
n_points = 8 * radius
METHOD = 'uniform'
lbp = local_binary_pattern(color.rgb2gray(img), n_points, radius, METHOD)
return lbp