前言:

本节继续讨论Matlab的机器视觉工具集举例,这次为分类的综合实现:该例子,用到了图像处理,统计,并行计算等方法。


1 分类的难度:

【计算机视觉里面,分类的精髓在选取适当的数据集和算法,这一点在用计算机去选择处理的时候,往往具备难度】

图像分类的步骤如下:

本例,演示对纹理图像进行分类:KTH-TIPS数据集,包括了10中不同的纹理数据集,(铝箔,砂纸,橘子皮)在不同尺度和光照条件下拍摄的图片,每一种物质包括81张图片。

1.1 显示分类的纹理图片:

1. 2  确定分类的特征属性:

比如,我们是边缘特征还是颜色特征进行分类:

【案,对纹理物体来说,灰度共生矩阵往往可以用来】我们尝试用灰度共生矩阵来解决分类问题,

【Matlab利用graycomatrix这个函数来求取灰度共生矩阵】

【上图】是一个8*8的灰度共生矩阵,每个方块,代表这个像素上该灰度出现的频率次数。

灰度共生矩阵的生成,就是依据纹理图像的元素图像,找到相邻的像素的灰度对出现的次数,构建一个表述矩阵【具体的生成逻辑,后面我摘录了原文的HELP说明,也做了比较详细的分析】

然后,我们可以把10个不同纹理的灰度共生矩阵给画出来:

可以看到,大多数的灰度共生矩阵的值非常不同(除了海绵和泡沫塑料)

这样我们可以选定了分类的基本的依赖的属性特征。

1. 3  进行分类尝试:

然后,我们提取所有810张纹理的特征:

1.3.1 数据集分割

然后,对数据集进行分割:

【通过交叉验证的方式,将数据分成训练集和测试集,各占50%,利用函数cvpartition进行处理,】


1.3.2  决策树算法进行分类

通过view,看到决策树的算法的叶子树,为一个二叉树。

【案,节点是灰度共生矩阵里面64个元素的判断条件,叶子是满足当前条件下,分类的结果。也就是叶子取值范围是1 到 10 ,这10个纹理类】

构建了决策树后,可以唉在训练集和测试集里面分别应用决策树分类算法进行核实,

在命令行,可以看到输出的结果,其中,训练集的准确度要高一些:

然后,我们把数据集的结果放到一个混淆矩阵里面直观的显示出来:

对角线上,是正确的分类结果。

【案,绿色箭头我们看的同类的纹理分类还是比较正确的,但是,在浅蓝色的区域,红色箭头所指的部分比较容易出现混淆错误】


1.3.3  K最近领域算法:

其结果,准确的高2个百分点,

现在,把数据集的划分重新定义一下,之前是50%的训练集,50%的测试集,现在,二八分开,测试集的数据是20%,

输出结果又提高了2个百分点:


1.3.4  决策树的升级算法 - 决策树集:

为提高运行的效率,我们先使能并行计算

然后,用150个决策树,进行决策树森林的计算,treebagger,

计算的分类结果大大提高了,

再看计算的结果直观表示,也比单纯决策树算法要好:


Matlab的其他图像处理功能


参考:灰度共生矩阵:

graycomatrix

Create gray-level co-occurrence matrix from image

collapse all in page

Syntax

glcms = graycomatrix(I)

glcms = graycomatrix(I,Name,Value,...)

[glcms,SI] = graycomatrix(___)

Description

glcms = graycomatrix(I) creates a gray-level co-occurrence matrix (GLCM) 【灰度共生矩阵】from image I. Another name for a gray-level co-occurrence matrix is a gray-level spatial dependence matrix. Also, the word co-occurrence 【共生矩阵】is frequently used in the literature without a hyphen, cooccurrence.

graycomatrix creates the GLCM by calculating how often a pixel with gray-level (grayscale intensity) value i occurs horizontally adjacent to a pixel with the value j. (You can specify other pixel spatial relationships using the 'Offsets' parameter.) Each element (i,j) in glcm specifies the number of times that the pixel with value i occurred horizontally adjacent to a pixel with value j.

【灰度共生矩阵,用来计算一个像素灰度值出现的频率】

example

glcms = graycomatrix(I,Name,Value,...) returns one or more gray-level co-occurrence matrices, depending on the values of the optional name/value pairs. Parameter names can be abbreviated, and case does not matter.

example

[glcms,SI] = graycomatrix(___) returns the scaled image, SI, used to calculate the gray-level co-occurrence matrix. The values in SI are between 1 and NumLevels.

Examples

collapse all

Create Gray-Level Co-occurrence Matrix for Grayscale Image

Open Live Script

Read a grayscale image into workspace.

I = imread('circuit.tif');

Calculate the gray-level co-occurrence matrix (GLCM) for the grayscale image. By default, graycomatrix calculates the GLCM based on horizontal proximity of the pixels: [0 1]. That is the pixel next to the pixel of interest on the same row. This example specifies a different offset: two rows apart on the same column.

glcm = graycomatrix(I,'Offset',[2 0])
glcm = 14205        2107         126           0           0           0           0           02242       14052        3555         400           0           0           0           0191        3579        7341        1505          37           0           0           00         683        1446        7184        1368           0           0           00           7         116        1502       10256        1124           0           00           0           0           2        1153        1435           0           00           0           0           0           0           0           0           00           0           0           0           0           0           0           0

Create Gray-Level Co-occurrence Matrix Returning Scaled Image

Open Live Script

Create a simple 3-by-6 sample array.

I = [ 1 1 5 6 8 8; 2 3 5 7 0 2; 0 2 3 5 6 7]
I = 1     1     5     6     8     82     3     5     7     0     20     2     3     5     6     7

Calculate the gray-level co-occurrence matrix (GLCM) and return the scaled image used in the calculation. By specifying empty brackets for the GrayLimits parameter, the example uses the minimum and maximum grayscale vales in the input image as limits.

[glcm, SI] = graycomatrix(I,'NumLevels',9,'GrayLimits',[])
glcm = 0     0     2     0     0     0     0     0     00     1     0     0     0     1     0     0     00     0     0     2     0     0     0     0     00     0     0     0     0     2     0     0     00     0     0     0     0     0     0     0     00     0     0     0     0     0     2     1     00     0     0     0     0     0     0     1     11     0     0     0     0     0     0     0     00     0     0     0     0     0     0     0     1
SI = 2     2     6     7     9     93     4     6     8     1     31     3     4     6     7     8

Calculate GLCMs using Four Different Offsets

Open Live Script

Read grayscale image into the workspace.

I = imread('cell.tif');

Define four offsets.

offsets = [0 1; -1 1;-1 0;-1 -1];

Calculate the GLCMs, returning the scaled image as well.

[glcms, SI] = graycomatrix(I,'Offset',offsets);

Note how the function returns an array of four GLCMs.

whos
  Name           Size              Bytes  Class     AttributesI            159x191             30369  uint8               SI           159x191            242952  double              glcms          8x8x4              2048  double              offsets        4x2                  64  double

Calculate Symmetric GLCM for Grayscale Image

Open Live Script

Read grayscale image into the workspace.

I = imread('circuit.tif');

Calculate GLCM using the Symmetric option. The GLCM created when you set Symmetric to true is symmetric across its diagonal, and is equivalent to the GLCM described by Haralick (1973).

glcm = graycomatrix(I,'Offset',[2 0],'Symmetric', true)
glcm = 28410        4349         317           0           0           0           0           04349       28104        7134        1083           7           0           0           0317        7134       14682        2951         153           0           0           00        1083        2951       14368        2870           2           0           00           7         153        2870       20512        2277           0           00           0           0           2        2277        2870           0           00           0           0           0           0           0           0           00           0           0           0           0           0           0           0

Input Arguments

collapse all

I — Input image
2-D, real, nonsparse, numeric or logical array

Input image, specified as a 2-D, real, nonsparse, numeric or logical array.

Example:

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.

Example:

collapse all

'GrayLimits' — Range used scaling input image into gray levels
range specified by class (default) | two-element vector [low high]

Range used scaling input image into gray levels, specified as a two-element vector [low high]. If N is the number of gray levels (see parameter 'NumLevels') to use for scaling, the range [low high] is divided into N equal width bins and values in a bin get mapped to a single gray level. Grayscale values less than or equal to low are scaled to 1. Grayscale values greater than or equal to high are scaled to 'NumLevels'. If'GrayLimits' is set to []graycomatrix uses the minimum and maximum grayscale values in I as limits,[min(I(:)) max(I(:))], for example, [0 1] for class double and [-32768 32767] for class int16.

Example:

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

'NumLevels' — Number of gray levels
8 for numeric, 2 for binary (default) | integer

Number of gray levels, specified as an integer. For example, if NumLevels is 8, graycomatrix scales the values in I so they are integers between 1 and 8. The number of gray-levels determines the size of the gray-level co-occurrence matrix (glcm).

Example:

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

'Offset' — Distance between the pixel of interest and its neighbor
[0 1] (default) | p-by-2 array of integers

Distance between the pixel of interest and its neighbor, specified as a p-by-2 array of integers. Each row in the array is a two-element vector, [row_offset, col_offset], that specifies the relationship, or offset, of a pair of pixels. row_offset is the number of rows between the pixel-of-interest and its neighbor. col_offset is the number of columns between the pixel-of-interest and its neighbor. Because the offset is often expressed as an angle, the following table lists the offset values that specify common angles, given the pixel distance D.

Angle

Offset

0

[0 D]

45

[-D D]

90 [-D 0]
135 [-D -D]

The figure illustrates the array: offset = [0 1; -1 1; -1 0; -1 -1]

Example:

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

'Symmetric' — Consider ordering of values
false (default) | true

Consider ordering of values, specified as the Boolean value true or false. For example, when 'Symmetric' is set to truegraycomatrix counts both 1,2 and 2,1 pairings when calculating the number of times the value 1 is adjacent to the value 2. When 'Symmetric'is set to falsegraycomatrix only counts 1,2 or 2,1, depending on the value of 'offset'.

Example:

Data Types: logical

Output Arguments

collapse all

glcms — Gray-level co-occurrence matrix (or matrices)
double array

Gray-level co-occurrence matrix (or matrices), returned as an NumLevels-by-NumLevels-by-P array of class double, where P is the number of offsets in Offset.

SI — Scaled image used in calculation of GLCM
double matrix

Scaled image used in calculation of GLCM, returned as a double matrix the same size as the input image.


Algorithms

graycomatrix calculates the GLCM from a scaled version of the image.

By default, if I is a binary image, graycomatrix scales the image to two gray-levels.

If I is an intensity image, graycomatrix scales the image to eight gray-levels.

You can specify the number of gray-levels graycomatrix uses to scale the image by using the 'NumLevels' parameter, and the way that graycomatrix scales the values using the 'GrayLimits' parameter .

【案,这里表述灰度共生矩阵的主要算法逻辑。

第一步,上面小节介绍的,先把原始的图像采样成你设定的灰阶阶数,这里,I 定义为8个灰阶。

第二步,由于采用了8个灰阶,那么GLCM矩阵,一共包含 8*8 64个元素,如右图。

第三步,计算每一个GLCM元素的值:

具体分析见下面:

The following figure shows how graycomatrix calculates several values in the GLCM of the 4-by-5 image I.

Element (1,1) in the GLCM contains the value 1 because there is only one instance (一次)in the image where two, horizontally adjacent(相邻行) pixels have the values 1 and 1.

【案,看图,GLCM矩阵的第(1,1)元素,表述灰度值1和1相邻的频率(次数),我们从图中看,这个GLCM中只有一次,就是两个行相邻都为1 只有一次】

Element (1,2) in the GLCM contains the value 2 because there are two instances in the image where two, horizontally adjacent pixels have the values 1 and 2graycomatrix continues this processing to fill in all the values in the GLCM.

【案,元素(1,2)表述为2,因为在行的方向,灰度值1,2相邻的次数出现了2次】

【再推,2,3相邻的次数为0;3,4相邻的次数为0;而4,5相邻的次数在第3行有一

graycomatrix ignores pixel pairs if either of the pixels contains a NaN, replaces positive Infs with the value NumLevels, and replaces negative Infs with the value 1graycomatrix ignores border pixels, if the corresponding neighbor pixel falls outside the image boundaries.

The GLCM created when 'Symmetric' is set to true is symmetric across its diagonal, and is equivalent to the GLCM described by Haralick (1973). The GLCM produced by the following syntax, with 'Symmetric' set to true

 graycomatrix(I, 'offset', [0 1], 'Symmetric', true)

is equivalent to the sum of the two GLCMs produced by the following statements where'Symmetric' is set to false.

graycomatrix(I, 'offset', [0 1], 'Symmetric', false)
graycomatrix(I, 'offset', [0 -1], 'Symmetric', false)

References

[1] Haralick, R.M., K. Shanmugan, and I. Dinstein, "Textural Features for Image Classification", IEEE Transactions on Systems, Man, and Cybernetics, Vol. SMC-3, 1973, pp. 610-621.

[2] Haralick, R.M., and L.G. Shapiro. Computer and Robot Vision: Vol. 1, Addison-Wesley, 1992, p. 459.

MATLAB 在图像处理和机器视觉的应用举例01 - 官网培训视频笔记(下)分类/灰度共生矩阵/纹理分类学习相关推荐

  1. MATLAB 在图像处理和机器视觉的应用举例01 - 官网培训视频笔记(上)-- 图像分割和图像配准

    前言:笔记: 以下内容为Matlab的官网视频的笔记: 1课程大意: 2  图像处理的应用: 3 科学计算的基本流程: [案,Matlab的研究方法主要关注在算法的层面,但是,Matlab在数据的采集 ...

  2. 现代汉语词典 v2007 build 07.01 官网

    Welcome to my blog! <script language="javascript" src="http://avss.b15.cnwg.cn/cou ...

  3. dalvik虚拟机与Java区别_05 Android---java虚拟机跟dalvik虚拟机的区别(从01开始点点入门,视频+笔记)...

    大家好,我是森森 这节课我简单给大家介绍一下java虚拟机跟安卓系统虚拟机的区别.可能时间太晚了,有点不在状态,也有点紧张,大家见谅. 05java虚拟机跟dalvik虚拟机的区别 这篇文章重点写一写 ...

  4. matlab 函数优化问题,matlab求解最优化问题 Matlab在最优化问题中的应用举例.doc

    matlab求解最优化问题 Matlab在最优化问题中的应用举例 导读:就爱阅读网友为您分享以下"Matlab在最优化问题中的应用举例"的资讯,希望对您有所帮助,感谢您对92的支持 ...

  5. Autolayout代码实现举例-01使用线性公式

    Autolayout代码实现举例-01使用线性公式 1.例子1 需求: 令一个宽高都为200的view永远显示在屏幕的中央. 1 // 1.创建蓝色view 2 UIView *blueView =[ ...

  6. matlab在图像处理中的应用论文,MATLAB在数字图像处理中的应用

    摘要:数字图像处理是一门新兴技术,经过计算机硬件的快速发展,数字图像的实时处理已经成为可能,由于数字图像处理的各种算法的出现,这就使得其处理速度越来越快,能更好的为人们服务.数字图像处理是一种通过计算 ...

  7. matlab 矩阵线性规划,MATLAB求解线性规划(含整数规划和0-1规划)问题

    对于这类线性规划问题,数学理论已经较为完善,可以有多种方法求解此类问题.但写这篇文章的目的并不是为了介绍数学理论,我们这里主要讲解如果利用工具求解这一类线性规划问题. 最著名,同时也是最强大的数学最优 ...

  8. matlab相位相关图像配准,数字图像处理,相位相关图像配准

    前言 图像配准是图像处理的基本任务之一,用于将不同时间.不同传感器.不同视角及不同拍摄条件下获取的关于同一目标或场景的两幅或多幅图像进行主要是几何意义上的匹配套和的过程.在对图像配准的研究过程中,大量 ...

  9. 基于matlab GUI Powell+蚁群算法图像配准

    基于matlab GUI Powell+蚁群算法图像配准 一.简介 1 蚁群算法(ant colony algorithm,ACA)起源和发展历程 Marco Dorigo等人在研究新型算法的过程中, ...

最新文章

  1. oracle is删除表数据库,rman删除expired备份提示“This command is forbidden”
  2. 《仙剑奇侠传online》游戏后台优化分析:CPU、内存与启动时间
  3. docker部署springboot应用
  4. 绑定dictionary 给定关键字不再字典中_对字典嵌套的理解及二级下拉菜单的制作...
  5. oracle Client 11g静默安装
  6. 利尔达e95蓝牙模块程序_Arduino使用HC05蓝牙模块与手机连接
  7. java yyyy-mm-dd 日期格式_Java中的日历日期为yyyy-MM-dd格式
  8. Gnumeric,专业处理数字软件
  9. Friendster,linkedin,orkut,liring对SNS的求索
  10. yytext table html,快速掌握YYText
  11. 几个多序列比对软件:Muscle,ClustalW和T-coffee的简单比较
  12. Total Control的深入用法,如何使用脚本实现启动或重启指定App
  13. 计算机系统文件格式,iso是什么文件格式,怎么使用呢?
  14. 电子计算机表格,excel电子表格(计算机).ppt
  15. 解耦java_工厂模式实现解耦
  16. RDIFramework.NET 框架之组织机构权限设置
  17. 16天记住英语7000个单词,300个句子
  18. validity属性返回对象中的属性值
  19. 使用xmanager打开远程桌面
  20. jquery 获取元素中class值

热门文章

  1. ramda.js api 速查
  2. gatsby_如何在Gatsby.js中使用本地状态保持页面之间的状态
  3. 不要解决:如何将JavaScript集合与目标相匹配
  4. 把svg图标制作成字体图标_让我们用SVG符号和CSS变量制作彩色图标
  5. zlib.h: 没有那个文件或目录
  6. Python数据可视化之Excel气泡图
  7. Python面试题【315+道题】
  8. 重磅福利!《Apache Flink 十大技术难点实战》发布,帮你从容应对生产环境中的技术难题...
  9. 原版英文书籍《Linux命令行》阅读记录2 | 在文件系统中翱翔
  10. servlet25配置和30