用matlab写一个图像特征提取代码
时间: 2024-05-10 13:21:07 浏览: 3
以下是一个简单的图像特征提取代码,它可以提取图像的灰度直方图、颜色直方图和纹理特征。
```matlab
% 读取图像
img = imread('image.jpg');
% 将图像转换为灰度图像
gray_img = rgb2gray(img);
% 计算灰度直方图
gray_hist = imhist(gray_img);
% 计算颜色直方图
color_hist = zeros(256, 3);
for i = 1:3
channel = img(:, :, i);
color_hist(:, i) = imhist(channel);
end
% 计算纹理特征
glcm = graycomatrix(gray_img, 'NumLevels', 8, 'Offset', [0 1; -1 1; -1 0; -1 -1]);
stats = graycoprops(glcm, {'Contrast', 'Correlation', 'Energy', 'Homogeneity'});
% 将特征组合为一个向量
features = [gray_hist; color_hist(:); cat(1, stats.Contrast, stats.Correlation, stats.Energy, stats.Homogeneity)];
% 显示图像和特征向量
figure;
subplot(2, 1, 1);
imshow(img);
title('原图像');
subplot(2, 1, 2);
bar(features);
title('图像特征向量');
```