颜色特征提取
sourceimg =img2double(img); %将图像img转换成double数据类型
rmatix = sourceimg( :, : ,1); %分别提取图像的r,g,b分量
gmatix = sourceimg( :, : , 2);
bmatix =sourceimg( :, :, 3);
2.形状特征
grayimg = rgb2gray( sourceimg ); %将rgb图像转换成灰度图像
hx = [-1 0 1;
-2 0 2;
-1 0 1;] %x方向3*3窗口滤波因子,不记得是哪个模板了
hy = hx’; %转置,Y方向滤波因子,
hxx = [1 0 -2 0 1;
4 0 -8 0 4;
6 0 -12 0 6;
4 0 -8 0 4;
1 0 -2 0 1;] %x方向5*5窗口滤波因子
hyy = hxx’; %转置,Y方向滤波因子
dx = imfilter(grayimg, hx); %滤波进行时。
dy = imfilter(grayimg, hy);
dxx = imfilter(grayimg, hxx);
dyy =imfilter(grayimg, hyy);
3.图像信息检索
r = rsshape( rmatix, m*n, 1); %rsshape是你自己写的程序吗?还是写错了(reshape)
g = rsshape( gmatix, m*n, 1); %reshape是修改图像的大小
b = rsshape( bmatix, m*n, 1);
dx1 = rsshape( dx, m*n, 1);
dy1 = rsshape( dy, m*n, 1);
dxx1 = rsshape( dxx, m*n, 1);
dyy1 = rsshape( dyy, m*n, 1);
Feature = [r, g, b, dx1, dy1, dxx1,dyy1]; %横向合并矩阵
Feature = double(Feature); %将Feature改成double型
M1= cov(Feature); %求Feature的协方差矩阵