def extract_RGB_LBP_features(image, labels, size=5, P=8, R=2):
n_sp = np.max(labels)+1
hs = size//2
img_superpixel = np.zeros_like(labels, dtype='int')
# calculate lbp for entire region
lbp_img = np.empty((3, ), dtype='object')
for d in range(3):
lbp_img[d] = local_binary_pattern(image[..., d], P=P, R=R, method='uniform')
feat_desc_size = P+1
feat_descs = np.zeros((n_sp, feat_desc_size*3))
for i in range(n_sp):
# get centroid of i'th superpixel
img_superpixel[:] = labels == i
cy, cx = [np.rint(x).astype('int') for x in regionprops(img_superpixel)[0].centroid]
# extract lbp values in sizeXsize region centred on the centroid
x0, y0, x1, y1 = cx-hs, cy-hs, cx+hs+1, cy+hs+1
# clip to boundaries of image
x0 = 0 if x0 < 0 else x0
y0 = 0 if y0 < 0 else y0
x1 = image.shape[1]-1 if x1 > image.shape[1]-2 else x1
y1 = image.shape[0]-1 if y1 > image.shape[0]-2 else y1
# fill in the feature vector for each image channel
for d in range(3):
j, k = d*feat_desc_size, (1+d)*feat_desc_size
patch = lbp_img[d][y0:y1, x0:x1].flat
fv = np.histogram(patch, bins=np.arange(0, feat_desc_size+1), range=(0, feat_desc_size+1))[0]
feat_descs[i, j:k] = fv
return feat_descs
python类local_binary_pattern()的实例源码
data_conversion.py 文件源码
项目:apparent-age-gender-classification
作者: danielyou0230
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def LBP(train_image,radius, no_points):
im = cv2.imread(train_image)
im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
lbp = local_binary_pattern(im_gray, no_points, radius, method='default')
#(hist, _) = np.histogram(lbp.ravel(), bins=np.arange(0,(no_points*(no_points-1)+4)))
#hist = hist.astype("float")
#hist /= (hist.sum() + eps)
#print hist.sum()
print lbp
return lbp
data_conversion_2.py 文件源码
项目:apparent-age-gender-classification
作者: danielyou0230
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def LBP(train_image,radius, no_points):
im = cv2.imread(train_image)
im_gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
lbp = local_binary_pattern(im_gray, no_points, radius, method='default')
(hist, _) = np.histogram(lbp[0:63][0:63].ravel(), bins=np.arange(0,(no_points*(no_points-1)+4)))
hist = hist.astype("float")
hist /= (hist.sum() + eps)
#print hist.sum()
#print lbp
return hist
def calculatehistogram(self, image, eps=1e-7):
lbp = feature.local_binary_pattern(image, self.numberOfPoints, self.radius, method="uniform")
(histogram, _) = np.histogram(lbp.ravel(),
bins=np.arange(0, self.numberOfPoints + 3),
range=(0, self.numberOfPoints + 2))
#now we need to normalise the histogram so that the total sum=1
histogram = histogram.astype("float")
histogram /= (histogram.sum() + eps)
return histogram
def calculatehistogram(self, image, eps=1e-7):
lbp = feature.local_binary_pattern(image, self.numberOfPoints, self.radius, method="uniform")
(histogram, _) = np.histogram(lbp.ravel(),
bins=np.arange(0, self.numberOfPoints + 3),
range=(0, self.numberOfPoints + 2))
#now we need to normalise the histogram so that the total sum=1
histogram = histogram.astype("float")
histogram /= (histogram.sum() + eps)
return histogram
testing_emo.py 文件源码
项目:Vision-Based-Age-Estimation
作者: parthapritam2717
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def calculatehistogram(self, image, eps=1e-7):
lbp = feature.local_binary_pattern(image, self.numberOfPoints, self.radius, method="uniform")
(histogram, _) = np.histogram(lbp.ravel(),
bins=np.arange(0, self.numberOfPoints + 3),
range=(0, self.numberOfPoints + 2))
# now we need to normalise the histogram so that the total sum=1
histogram = histogram.astype("float")
histogram /= (histogram.sum() + eps)
return histogram
training_emo.py 文件源码
项目:Vision-Based-Age-Estimation
作者: parthapritam2717
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def calculatehistogram(self, image, eps=1e-7):
lbp = feature.local_binary_pattern(image, self.numberOfPoints, self.radius, method="uniform")
(histogram, _) = np.histogram(lbp.ravel(),
bins=np.arange(0, self.numberOfPoints + 3),
range=(0, self.numberOfPoints + 2))
# now we need to normalise the histogram so that the total sum=1
histogram = histogram.astype("float")
histogram /= (histogram.sum() + eps)
return histogram
def getLBP(img):
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
radius = 1
n_points = 8 * radius
lbpImage = (local_binary_pattern(img2, n_points, radius)).astype(int)**(1.0/radius)
# block processing:
lbpImages = block_view(lbpImage, ( int(lbpImage.shape[0] / 2), int(lbpImage.shape[1] / 4)))
count = 0
LBP = np.array([]);
for i in range(lbpImages.shape[0]): # for each block:
for j in range(lbpImages.shape[1]):
count += 1
# plt.subplot(4,2,count)
# plt.imshow(lbpImages[i,j,:,:],cmap = cm.Greys_r)
# plt.subplot(4,2,count+4*2/2)
# print count*2+1
LBPt = cv2.calcHist([lbpImages[i,j,:,:].astype('uint8')], [0], None, [8], [0, 256])
LBP = np.append(LBP, LBPt[:,0]);
# plt.plot(LBPt)
# plt.show()
Fnames = ["LBP"+str(i).zfill(2) for i in range(len(LBP))]
return normalize(LBP).tolist(), Fnames
def generate_lbp_features(filename):
radius = 3
n_points = 10 * radius
image_arr = io.imread(filename, as_grey=True)
return local_binary_pattern(image_arr, P=n_points, R=radius)
def generate_lbp_features(filename):
radius = 3
n_points = 10 * radius
image_arr = io.imread(filename, as_grey=True)
return local_binary_pattern(image_arr, P=n_points, R=radius)
def getLBP(img):
img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
radius = 1
n_points = 8 * radius
lbpImage = (local_binary_pattern(img2, n_points, radius)).astype(int)**(1.0/radius)
# block processing:
lbpImages = block_view(lbpImage, ( int(lbpImage.shape[0] / 2), int(lbpImage.shape[1] / 4)))
count = 0
LBP = np.array([]);
for i in range(lbpImages.shape[0]): # for each block:
for j in range(lbpImages.shape[1]):
count += 1
# plt.subplot(4,2,count)
# plt.imshow(lbpImages[i,j,:,:],cmap = cm.Greys_r)
# plt.subplot(4,2,count+4*2/2)
# print count*2+1
LBPt = cv2.calcHist([lbpImages[i,j,:,:].astype('uint8')], [0], None, [8], [0, 256])
LBP = np.append(LBP, LBPt[:,0]);
# plt.plot(LBPt)
# plt.show()
Fnames = ["LBP"+str(i).zfill(2) for i in range(len(LBP))]
return normalize(LBP).tolist(), Fnames