Python 如何使用标签保存lbp值?
我想在python中保存5个带有标签的图像的lbp值,以便在机器学习模型中使用它们。我知道如何保存1个图像的lbp值并将其保存在csv文件中,但我不确定我的代码是否正确。我希望每个lbp值有一个标签。我不熟悉python和计算机视觉。如果有人对此有一些想法,请随时提出建议Python 如何使用标签保存lbp值?,python,computer-vision,Python,Computer Vision,我想在python中保存5个带有标签的图像的lbp值,以便在机器学习模型中使用它们。我知道如何保存1个图像的lbp值并将其保存在csv文件中,但我不确定我的代码是否正确。我希望每个lbp值有一个标签。我不熟悉python和计算机视觉。如果有人对此有一些想法,请随时提出建议 from skimage import feature import numpy as np import cv2 from matplotlib import pyplot as plt import pandas
from skimage import feature
import numpy as np
import cv2
from matplotlib import pyplot as plt
import pandas as pd
# load the image, convert it to grayscale, and describe it
image1 = cv2.imread("almond1.jpg")
gray1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
image2 = cv2.imread("almond2.jpg")
gray2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)
image3 = cv2.imread("almond3.jpg")
gray3 = cv2.cvtColor(image3, cv2.COLOR_BGR2GRAY)
image4 = cv2.imread("almond4.jpg")
gray4 = cv2.cvtColor(image4, cv2.COLOR_BGR2GRAY)
image5 = cv2.imread("almond5.jpg")
gray5 = cv2.cvtColor(image5, cv2.COLOR_BGR2GRAY)
numPoints = 8
radius = 2
lbp1 = feature.local_binary_pattern(gray1, numPoints,radius)
feature
lbp2 = feature.local_binary_pattern(gray2, numPoints,radius)
feature
lbp3 = feature.local_binary_pattern(gray3, numPoints,radius)
feature
lbp4 = feature.local_binary_pattern(gray4, numPoints,radius)
feature
lbp5 = feature.local_binary_pattern(gray5, numPoints,radius)
feature
cv2.imshow("LBP Image", lbp2)
hist1, bin_edges = np.histogram(lbp1, bins=256)
hist2, bin_edges = np.histogram(lbp2, bins=256)
hist3, bin_edges = np.histogram(lbp3, bins=256)
hist4, bin_edges = np.histogram(lbp4, bins=256)
hist5, bin_edges = np.histogram(lbp5, bins=256)
#plt.bar(bin_edges2[:-1], hist2, width = 1)
#plt.xlim(min(bin_edges2), max(bin_edges2))
#plt.show()
np.savetxt('array.csv', [hist1,hist2,hist3,hist4,hist5], delimiter=',', fmt='%f', newline='\n')
#np.savetxt('array.csv', [hist2], delimiter=',', fmt='%f', newline='\n')
#np.savetxt('array.csv', [hist3], delimiter=',', fmt='%f', newline='\n')
#np.savetxt('array.csv', [hist4], delimiter=',', fmt='%f', newline='\n')
#np.savetxt('array.csv', [hist5], delimiter=',', fmt='%f', newline='\n')
#print(hist2)
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()