用python改写:%% 确定特征向量尺寸 img = read(trainingSet(1), 1); % %转化为灰度图像 % img=rgb2gray(img); % %转化为2值图像 % lvl = graythresh(img); % img = im2bw(img, lvl); img=imresize(img,[256 256]); cellSize = [4 4]; [hog_feature, vis_hog] = extractHOGFeatures(img,'CellSize',cellSize); % glcm_feature = getGLCMFeatures(img); % SizeOfFeature = length(hog_feature)+ length(glcm_feature); SizeOfFeature = length(hog_feature)
时间: 2024-02-03 21:15:32 浏览: 75
```python
import cv2
from skimage.feature import hog
img = cv2.imread(trainingSet(1), 1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
lvl = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
img_resized = cv2.resize(lvl, (256, 256))
cellSize = (4, 4)
hog_feature, vis_hog = hog(img_resized, orientations=9, pixels_per_cell=cellSize, cells_per_block=(2, 2), visualize=True, multichannel=False)
# glcm_feature = getGLCMFeatures(img_resized) # 如果需要使用 GLCM 特征,需要定义 getGLCMFeatures 函数
SizeOfFeature = len(hog_feature)
```
阅读全文