# extract features for one sampleimage = imreadrEDesktop ContentProject_IITBsubmissionimg_00109jpggray = rgb2grayimage# Convert the gray image to integer data typegray_int = gray 255astypenpuint8radi
Certainly! Here's the code converted to Python syntax:
from skimage.io import imread
from skimage.color import rgb2gray
from skimage.feature import local_binary_pattern, greycomatrix, greycoprops
import numpy as np
import pickle
from sklearn.externals import joblib
# Extract features for one sample
image = imread(r"E:\Desktop Content\Project_IITB\submission\img_00109.jpg")
gray = rgb2gray(image)
# Convert the gray image to integer data type
gray_int = (gray * 255).astype(np.uint8)
radius = 1
n_points = 8 * radius
lbp = local_binary_pattern(gray_int, n_points, radius)
# Normalize the LBP image to the range [0, 1]
lbp = lbp / np.max(lbp)
# Calculating the GLCM
glcm = greycomatrix(gray_int, distances=[2], angles=[0, np.pi/4, np.pi/2, 3*np.pi/4], levels=256, symmetric=True, normed=True)
# Extract GLCM features from the matrix
contrast = greycoprops(glcm, 'contrast')
homogeneity = greycoprops(glcm, 'homogeneity')
energy = greycoprops(glcm, 'energy')
correlation = greycoprops(glcm, 'correlation')
# Concatenate the features into a single feature vector
glcm_features = np.concatenate((contrast.ravel(), homogeneity.ravel(), energy.ravel(), correlation.ravel()))
# Append the feature vector to the data list
data.append(glcm_features)
with open('model_pickle_12', 'rb') as f:
mod = pickle.load(f)
mod.predict([obs])
classifier = joblib.load('model_joblib_12.pkl')
classifier.predict([obs])
acc_2 = 0.9453441295546559
acc_dist.append(acc_2)
Please note that the code assumes you have the necessary libraries installed and the variable obs is defined
原文地址: http://www.cveoy.top/t/topic/hXEG 著作权归作者所有。请勿转载和采集!