灰度共生矩阵

C++ OPENCV 灰度共生矩阵的生成和利用 #include <string> #include<fstream> #include<iostream> #include <vector> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; typedef struct _GLCMFeatures { _GLCMFeatures() : energy(0.0) , 阅读详情

使用C++、opencv获取图像的灰度共生矩阵,即能量、熵、对比度、逆差矩等图像特征参数

 灰度共生矩阵,指的是一种通过研究灰度的空间相关特性来描述纹理的常用方法,通俗的说就是图像的一组关于纹理信息图像特征(能量、熵、对比度、逆差矩),可以将纹理数字化。

灰度共生矩阵的原理和四个特征参数的计算公式可参考博客:https://blog.csdn.net/zhangxz259/article/details/81700167及https://blog.csdn.net/qq_37059483/article/details/78292869


代码:

#include "stdafx.h"
#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

//灰度等级设为16
const int gray_level = 16;

//0度灰度共生矩阵
void getglcm_horison(Mat& input, Mat& dst)
{
	Mat src = input;
	CV_Assert(1 == src.channels());
	src.convertTo(src, CV_32S);
	int height = src.rows;
	int width = src.cols;
	int max_gray_level = 0;
	for (int j = 0; j < height; j++)//寻找像素灰度最大值
	{
		int* srcdata = src.ptr<int>(j);
		for (int i = 0; i < width; i++)
		{
			if (srcdata[i] > max_gray_level)
			{
				max_gray_level = srcdata[i];
			}
		}
	}
	max_gray_level++;//像素灰度最大值加1即为该矩阵所拥有的灰度级数
	if (max_gray_level > 16)//若灰度级数大于16,则将图像的灰度级缩小至16级,减小灰度共生矩阵的大小。
	{
		for (int i = 0; i < height; i++)
		{
			int*srcdata = src.ptr<int>(i);
			for (int j = 0; j < width; j++)
			{
				srcdata[j] = (int)srcdata[j] / gray_level;
			}
		}

		dst.create(gray_level, gray_level, CV_32SC1);
		dst = Scalar::all(0);
		for (int i = 0; i < height; i++)
		{
			int*srcdata = src.ptr<int>(i);
			for (int j = 0; j < width - 1; j++)
			{
				int rows = srcdata[j];
				int cols = srcdata[j + 1];
				dst.ptr<int>(rows)[cols]++;
			}
		}
	}
	else//若灰度级数小于16,则生成相应的灰度共生矩阵
	{
		dst.create(max_gray_level, max_gray_level, CV_32SC1);
		dst = Scalar::all(0);
		for (int i = 0; i < height; i++)
		{
			int*srcdata = src.ptr<int>(i);
			for (int j = 0; j < width - 1; j++)
			{
				int rows = srcdata[j];
				int cols = srcdata[j + 1];
				dst.ptr<int>(rows)[cols]++;
			}
		}
	}
}
//90度灰度共生矩阵
void getglcm_vertical(Mat& input, Mat& dst)
{
	Mat src = input;
	CV_Assert(1 == src.channels());
	src.convertTo(src, CV_32S);
	int height = src.rows;
	int width = src.cols;
	int max_gray_level = 0;
	for (int j = 0; j < height; j++)
	{
		int* srcdata = src.ptr<int>(j);
		for (int i = 0; i < width; i++)
		{
			if (srcdata[i] > max_gray_level)
			{
				max_gray_level = srcdata[i];
			}
		}
	}
	max_gray_level++;
	if (max_gray_level > 16)
	{
		for (int i = 0; i < height; i++)//将图像的灰度级缩小至16级,减小灰度共生矩阵的大小。
		{
			int*srcdata = src.ptr<int>(i);
			for (int j = 0; j < width; j++)
			{
				srcdata[j] = (int)srcdata[j] / gray_level;
			}
		}

		dst.create(gray_level, gray_level, CV_32SC1);
		dst = Scalar::all(0);
		for (int i = 0; i < height - 1; i++)
		{
			int*srcdata = src.ptr<int>(i);
			int*srcdata1 = src.ptr<int>(i + 1);
			for (int j = 0; j < width; j++)
			{
				int rows = srcdata[j];
				int cols = srcdata1[j];
				dst.ptr<int>(rows)[cols]++;
			}
		}
	}
	else
	{
		dst.create(max_gray_level, max_gray_level, CV_32SC1);
		dst = Scalar::all(0);
		for (int i = 0; i < height - 1; i++)
		{
			int*srcdata = src.ptr<int>(i);
			int*srcdata1 = src.ptr<int>(i + 1);
			for (int j = 0; j < width; j++)
			{
				int rows = srcdata[j];
				int cols = srcdata1[j];
				dst.ptr<int>(rows)[cols]++;
			}
		}
	}
}
//45度灰度共生矩阵
void getglcm_45(Mat& input, Mat& dst)
{
	Mat src = input;
	CV_Assert(1 == src.channels());
	src.convertTo(src, CV_32S);
	int height = src.rows;
	int width = src.cols;
	int max_gray_level = 0;
	for (int j = 0; j < height; j++)
	{
		int* srcdata = src.ptr<int>(j);
		for (int i = 0; i < width; i++)
		{
			if (srcdata[i] > max_gray_level)
			{
				max_gray_level = srcdata[i];
			}
		}
	}
	max_gray_level++;
	if (max_gray_level > 16)
	{
		for (int i = 0; i < height; i++)//将图像的灰度级缩小至16级,减小灰度共生矩阵的大小。
		{
			int*srcdata = src.ptr<int>(i);
			for (int j = 0; j < width; j++)
			{
				srcdata[j] = (int)srcdata[j] / gray_level;
			}
		}

		dst.create(gray_level, gray_level, CV_32SC1);
		dst = Scalar::all(0);
		for (int i = 0; i < height - 1; i++)
		{
			int*srcdata = src.ptr<int>(i);
			int*srcdata1 = src.ptr<int>(i + 1);
			for (int j = 0; j < width - 1; j++)
			{
				int rows = srcdata[j];
				int cols = srcdata1[j + 1];
				dst.ptr<int>(rows)[cols]++;
			}
		}
	}
	else
	{
		dst.create(max_gray_level, max_gray_level, CV_32SC1);
		dst = Scalar::all(0);
		for (int i = 0; i < height - 1; i++)
		{
			int*srcdata = src.ptr<int>(i);
			int*srcdata1 = src.ptr<int>(i + 1);
			for (int j = 0; j < width - 1; j++)
			{
				int rows = srcdata[j];
				int cols = srcdata1[j + 1];
				dst.ptr<int>(rows)[cols]++;
			}
		}
	}
}
//135度灰度共生矩阵
void getglcm_135(Mat& input, Mat& dst)
{
	Mat src = input;
	CV_Assert(1 == src.channels());
	src.convertTo(src, CV_32S);
	int height = src.rows;
	int width = src.cols;
	int max_gray_level = 0;
	for (int j = 0; j < height; j++)
	{
		int* srcdata = src.ptr<int>(j);
		for (int i = 0; i < width; i++)
		{
			if (srcdata[i] > max_gray_level)
			{
				max_gray_level = srcdata[i];
			}
		}
	}
	max_gray_level++;
	if (max_gray_level > 16)
	{
		for (int i = 0; i < height; i++)//将图像的灰度级缩小至16级,减小灰度共生矩阵的大小。
		{
			int*srcdata = src.ptr<int>(i);
			for (int j = 0; j < width; j++)
			{
				srcdata[j] = (int)srcdata[j] / gray_level;
			}
		}

		dst.create(gray_level, gray_level, CV_32SC1);
		dst = Scalar::all(0);
		for (int i = 0; i < height - 1; i++)
		{
			int*srcdata = src.ptr<int>(i);
			int*srcdata1 = src.ptr<int>(i + 1);
			for (int j = 1; j < width; j++)
			{
				int rows = srcdata[j];
				int cols = srcdata1[j - 1];
				dst.ptr<int>(rows)[cols]++;
			}
		}
	}
	else
	{
		dst.create(max_gray_level, max_gray_level, CV_32SC1);
		dst = Scalar::all(0);
		for (int i = 0; i < height - 1; i++)
		{
			int*srcdata = src.ptr<int>(i);
			int*srcdata1 = src.ptr<int>(i + 1);
			for (int j = 1; j < width; j++)
			{
				int rows = srcdata[j];
				int cols = srcdata1[j - 1];
				dst.ptr<int>(rows)[cols]++;
			}
		}
	}
}

//计算特征值
void feature_computer(Mat&src, double& Asm, double& Eng, double& Con, double& Idm)
{
	int height = src.rows;
	int width = src.cols;
	int total = 0;
	for (int i = 0; i < height; i++)
	{
		int*srcdata = src.ptr<int>(i);
		for (int j = 0; j < width; j++)
		{
			total += srcdata[j];//求图像所有像素的灰度值的和
		}
	}

	Mat copy;
	copy.create(height, width, CV_64FC1);
	for (int i = 0; i < height; i++)
	{
		int*srcdata = src.ptr<int>(i);
		double*copydata = copy.ptr<double>(i);
		for (int j = 0; j < width; j++)
		{
			copydata[j] = (double)srcdata[j] / (double)total;//图像每一个像素的的值除以像素总和
		}
	}

	for (int i = 0; i < height; i++)
	{
		double*srcdata = copy.ptr<double>(i);
		for (int j = 0; j < width; j++)
		{
			Asm += srcdata[j] * srcdata[j];//能量
			if (srcdata[j]>0)
				Eng -= srcdata[j] * log(srcdata[j]);//熵             
			Con += (double)(i - j)*(double)(i - j)*srcdata[j];//对比度
			Idm += srcdata[j] / (1 + (double)(i - j)*(double)(i - j));//逆差矩
		}
	}
}

int main()
{
	system("color 02");

	Mat dst_horison, dst_vertical, dst_45, dst_135;

	//读取源图像
	Mat src = imread("D:\\哀.jpg");
	if (src.empty())
	{
		return -1;
	}
	namedWindow("原图", WINDOW_NORMAL);
	imshow("原图", src);
	Mat src_gray;
	//src.create(src.size(), CV_8UC1);
	//src_gray = Scalar::all(0);
	cvtColor(src, src_gray, COLOR_BGR2GRAY);
	namedWindow("灰度图", WINDOW_NORMAL);
	imshow("灰度图", src_gray);

	getglcm_horison(src_gray, dst_horison);
	getglcm_vertical(src_gray, dst_vertical);
	getglcm_45(src_gray, dst_45);
	getglcm_135(src_gray, dst_135);

	double eng_horison = 0, con_horison = 0, idm_horison = 0, asm_horison = 0;
	feature_computer(dst_horison, asm_horison, eng_horison, con_horison, idm_horison);

	cout << "能量asm_horison:" << asm_horison << endl;
	cout << "熵eng_horison:" << eng_horison << endl;
	cout << "对比度con_horison:" << con_horison << endl;
	cout << "逆差矩idm_horison:" << idm_horison << endl;

	double eng_vertical = 0, con_vertical = 0, idm_vertical = 0, asm_vertical = 0;
	feature_computer(dst_vertical, asm_vertical, eng_vertical, con_vertical, idm_vertical);

	cout << "能量asm_vertical:" << asm_vertical << endl;
	cout << "熵eng_vertical:" << eng_vertical << endl;
	cout << "对比度con_vertical:" << con_vertical << endl;
	cout << "逆差矩idm_vertical:" << idm_vertical << endl;

	double eng_45 = 0, con_45 = 0, idm_45 = 0, asm_45 = 0;
	feature_computer(dst_45, asm_45, eng_45, con_45, idm_45);

	cout << "能量asm_45:" << asm_45 << endl;
	cout << "熵eng_45:" << eng_45 << endl;
	cout << "对比度con_45:" << con_45 << endl;
	cout << "逆差矩idm_45:" << idm_45 << endl;

	double eng_135 = 0, con_135 = 0, idm_135 = 0, asm_135 = 0;
	feature_computer(dst_135, asm_135, eng_135, con_135, idm_135);

	cout << "能量asm_135:" << asm_135 << endl;
	cout << "熵eng_135:" << eng_135 << endl;
	cout << "对比度con_135:" << con_135 << endl;
	cout << "逆差矩idm_135:" << idm_135 << endl;

	//写入文件
	/*FILE *fp;
	fp = fopen("灰度共生矩阵数据.txt", "a");
	if (fp != NULL)
		fprintf(fp, "\n水平:%f\t%f\t%f\t%f\n垂直:%f\t%f\t%f\t%f\n45:%f\t%f\t%f\t%f\n135:%f\t%f\t%f\t%f\n", asm_horison, eng_horison, con_horison, idm_horison,asm_vertical, eng_vertical, con_vertical, idm_vertical, asm_45, eng_45, con_45, idm_45, asm_135, eng_135, con_135, idm_135);
	fclose(fp);*/


	waitKey(0);
	return 0;
}

原图:

结果:

灰度共生矩阵GLCM及其matlab实现 Prerequisites概念计算方式对于精度要求高且纹理细密的纹理分布,我们取像素间距为d=1d = 1,以下是方向的说明:我们来看,matlab内置工具箱中的灰度共生矩阵的生成函数graycomatrix(gray-level co-occurrence matrix)对方向的说明: 如上图所示,方向是在每一个像素点(pixel of interest)的邻域(当然,边界点除外)中获得的, 阅读详情

相关推荐

利用灰度共生矩阵提取图像纹理特征

利用灰度共生矩阵提取图像纹理特征 --xuliang

vipxuliang的专栏 1万+

图像特征提取——灰度共生矩阵(GLCM)

灰度共生矩阵(Gray-level Co-occurrence Matrix,GLCM)

远方的橄榄树 6万+

灰度共生矩阵(GLCM)

灰度共生矩阵(GLCM) 算法简介 灰度共生矩阵法(GLCM, Gray - level co - occurrence matrix),就是通过计算灰度图像得到它的共生矩阵,然后透过计算该共生矩阵得到矩阵的部分特征值,来分别代表图像的某些纹理特征(纹理的定义仍是难点)。灰度共生矩阵能反映图像灰度关于方向、相邻间隔、变化幅度等综合信息,它是分析图像的局部模式和它们排列规则的基础。 (灰度共...

abele280的博客 6513

灰度共生矩阵代码实现

2概念 2灰度共生矩阵生成编辑 灰度直方图是对图像上单个象素具有某个灰度进行统计的结果,而灰度共生矩阵是对图像上保持某距离的两象素分别具有某灰度的状况进行统计得到的。 取图像(N×N)中任意一点 (x,y)及偏离它的另一点 (x+a,y+b),设该点对的灰度值为 (g1,g2)。令点(x,y) 在整个画面上移动,则会得到各种 (g1,g2)值,设灰度值的级

积沙成塔 6960

VC++&opencv实现的灰度共生矩阵

用visual studio 2008和opencv2.0的库实现的灰度共生矩阵,并简单计算了纹理的能量特征。自己编写并测试过,只要opencv2.0的库没问题就OK。4个方向,灰度级可调,距离可调。

C++ 灰度共生矩阵代码

配置好opencv就可以直接用 ,在程序中每部分都有注释,方便理解。

灰度共生矩阵(超简单理解)

1.灰度共生矩阵生成原理   灰度共生矩阵(GLDM)的统计方法是20世纪70年代初由R.Haralick等人提出的,它是在假定图像中各像素间的空间分布关系包含了图像纹理信息的前提下,提出的具有广泛性的纹理分析方法。   灰度共生矩阵被定义为从灰度为i的像素点出发,离开某个固定位置(相隔距离为d,方位为)的点上灰度值为的概率,即,所有估计的值可以表示成一个矩阵的形式,以此被称为灰度共生矩阵。对于纹理变化缓慢的图像,其灰度共生矩阵对角线上的数值较大;而对于纹理变化较快的图像,其灰度共生矩阵对角线上...

白雪 9万+

OPENCV灰度图像共生矩阵C++.cpp

编写距离1的0度共生矩阵,编写距离1的135度共生矩阵。编译马上使用。因为图像是离散的灰度像素,所以很容易找到各个角度的像素位置。 例如要找135度方向,距离为1的共生矩阵。设点坐标为(i,j)则此方向的坐标为(i+1,j-1)。不同方向改变i,j。

灰度共生矩阵(附python代码)

最近在研究机器学习相关内容,后面会尽量花时间整理成一个系列的博客,然后朋友让我帮他实现一种基于SVR支持向量回归的图像质量评价方法,然而在文章的开头竟然发现 灰度共生矩阵这个陌生的家伙,于是便有此文。 主要参考博客1:http://blog.csdn.net/jialeheyeshu/article/details/51337225 主要参考博客2:http://blog.csdn.net/guanyuqiu/article/details/53117507 主要参考博客3:http://ww...

白雪 1万+

计算图像的熵(一阶、二阶和差熵)

本代码是计算图像的一阶熵、二阶熵和差熵的程序。希望能对大家有所帮助

5分钟搞定!用OpenCV实现全景图像柱面展开的保姆级教程(附完整代码)

本文提供了一份使用OpenCV实现全景图像柱面展开的详细教程。通过清晰的数学原理讲解和分步代码演示,指导读者快速掌握从等距柱状投影全景图到平面展开图的核心转换方法,并涵盖性能优化、参数调整及透视视图扩展等实用技巧,适合图像处理爱好者和开发者实践。

sony5的博客 578

灰度共生矩阵的原理及代码实现(python)

灰度共生矩阵的原理及代码实现(python) 1原理: 灰度共生矩阵(Gray Level Co-occurrence Matrix,GLCM)统计了灰度图中像素间的灰度值分布规律以区分不同的纹理。灰度共生矩阵中每个元素的值可以定义为(x, y)点与(x + dx, y + dy)点的值对为(i, j)的概率。统计整幅图像中每一种灰度值组合出现的概率矩阵 P 即为灰度共生矩阵。 灰度级量化 在实际应用中,一幅灰度影像的灰度级一般为256级,在计算由灰度共生矩阵推导出的纹理特征时,要求影像的灰...

Viraha_的博客 6557

MIPI D-PHYv2.5笔记(11) -- 高速时钟传输(High-Speed Clock Transmission)

在High-Speed模式中,Clock Lane提供了一个低摆幅(low-swing)、差分DDR时钟信号,此信号从Master到Slave,用于为高速数据传输提供时钟信号。时钟信号关于Forward Direction中的Data Lane上的位切换序列(toggling bit sequence)有正交相位,并且在一次burst的第一个被传输的bit的中心点有一个上升沿。

vivo01的专栏 3028

计算灰度共生矩阵GLCM

灰度共生矩阵         灰度共生矩阵定义为像素对的联合分布概率,是一个对称矩阵,它不仅反映图像灰度在相邻的方向、相邻间隔、变化幅度的综合信息,但也反映了相同的灰度级像素之间的位置分布特征,是计算纹理特征的基础。        设f(x,y)为一幅数字图像,其大小为M×N,灰度级别为Ng,则满足一定空间关系的灰度共生矩阵为:         其中#(x)表示集合x中的元素

cxf7394373的专栏 4万+

记录LeNet的硬件加速器设计(一)

LeNet的硬件加速器设计实现。

2301_81029398的博客 3549

什么是Merkle树?用“文件柜”类比理解区块链的核心技术

Merkle树是一种用于区块链的数据结构,像一个高效的“文件柜”,用于存储和验证大量交易数据。比特币通过Merkle树将交易哈希组织成树状结构,层层汇总,最终生成一个唯一的根哈希,存储在区块头中。这种设计大幅减少数据存储和验证成本,支持快速校验交易的完整性和存在性。Merkle树通过密码学保证数据不可篡改,广泛应用于比特币、区块链及其他分布式系统。它的优势在于高效、轻量和安全,尤其适合轻节点验证和数据同步。理解Merkle树就像掌握区块链的“索引秘籍”,是Web3世界的关键技术。

在路上的专栏 1195

图像处理基础——灰度共生矩阵

标准定义如下:对于取定的方向θ 和距离 d, 在方向为θ的直线上, 一个像元灰度为 i, 另一个与其相距为 d 像元的灰度为 j 的点对出现的频数即为灰度共生矩阵第(i, j)阵元的值。 怎样理解呢?看起来好复杂呀 呜呜呜 小白理解:灰度共生矩阵就是整幅图像中,按照一定的平移方向,相距为d的两个像素同时出现的联合概率密度分布。 怎么样?还是没办法深入理解 那就上图吧 怎样理解呢? ...

Wanda && Aidem 1万+

开源数显表

开源数显表,广泛应用于车床、铣床、磨床、镗床、火花机、线切割等。市面上此类液晶数显表多数都是基于此项目。 一、基本配置 硬件 主控:STM32F407VGT6 LCD:群创AT070TN92 显示驱动:RA8875 光栅尺:3 x 输入(X/Y/Z) 串口:1 x MAX3232 继电器:2 x 输出 存储:AT24C64 模拟输入:LM324C 电源:AC 220V 软件 工程版本:Keil 5 STM32库:V1.4.0 图形界面:uCGUI 多语言支持:中文、英文 二、项目文

m0_70934529的博客 443

纹理特征分析的灰度共生矩阵(GLCM)

纹理分析是对图像灰度(浓淡)空间分布模式的提取和分析。纹理分析在遥感图像、X射线照片、细胞图像判读和处理方面有广泛的应用。关于纹理,还没有一个统一的数学模型。它起源于表征纺织品表面性质的纹理概念,可以用来描述任何物质组成成分的排列情况,例如医学上X 射线照片中的肺纹理、血管纹理、航天(或航空)地形照片中的岩性纹理等。图像处理中的视觉纹理通常理解为某种基本模式(色调基元)的重复排列。因此描述一种纹理

lskyne的专栏 8万+

NXP S32K-144开发环境搭建与Keil MDK 5调试实战

嵌入式开发中,Cortex-M系列微控制器凭借其高性能和低功耗特性广泛应用于汽车电子和工业控制领域。以NXP S32K-144为例,该芯片采用Cortex-M4内核,支持SWD两线制调试协议,通过CoreSight调试系统可实现硬件断点、实时内存访问等高级功能。开发环境搭建涉及Keil MDK 5工具链配置、RTX5实时系统集成以及CMSIS-DSP算法库调用,其中SWD接口优化和ITM跟踪技术能显著提升调试效率。在汽车电子等对可靠性要求高的场景中,结合MPU内存保护单元和窗口看门狗等安全机制,可构建符合功

weixin_33722405的博客 328

深入解析report_timing:从基础参数到高级时序路径分析技巧

本文深入解析了静态时序分析(STA)中`report_timing`命令的核心用法与高级技巧。作为芯片设计的关键诊断工具,它能根据SDC约束精准定位时序路径问题。文章从基础参数过滤讲起,详细介绍了如何通过`-from`、`-through`、`-to`等选项定位关键路径,并深入讲解了`-input_pins`、`-nets`、`-transition_time`等高级选项如何揭示延迟细节,以及`-nworst`、`-slack_lesser_than`等过滤排序技巧,旨在帮助工程师高效解读时序报告,优化设计

h6i7j8的博客 1118

图像纹理——灰度共生矩阵

1.灰度共生矩阵 本文是借用一篇文章的例子讲解灰度共生矩阵,用文字说明感觉说不清,自己之前用该方法做过实验,还是会忘,所以干脆用例子的方式介绍,下一次再看也容易理解。 在图像中任意一点(x,y)及偏离它的一点(x+a,y+b)(其中a,b为整数,认为定义)构成点对。设该点对的灰度值为(f1,f2),假设图像的最大灰度级为L,则f1与f2的组合共有L*L种。对于整福图像,统计每一种(f1,f2)

sunny的专栏 8万+

基于共识的捆绑算法CBBA在多无人机多任务调度中的实现

在捆绑过程中,每个无人机根据自己的任务清单和其他无人机的任务清单,确定一个被称为“束”的集合。通过合理的任务分配和无人机协作,CBBA算法能够实现最优的任务调度,提高了多无人机系统的效率和执行能力。在每一轮迭代中,无人机根据自己的当前任务和位置信息将任务清单发送给其他无人机,并接收其他无人机发送过来的任务清单。通过比较其他无人机的任务清单和自身的任务清单,每个无人机可以更新自己的任务分配情况。在这一步中,每个无人机根据自己选择的新任务,更新自身的任务清单,并将更新后的清单发送给其他无人机。

持续更新 1159

图像处理 - GLCM灰度共生矩阵如何计算

因为最近要在OpenCV上试试各种图像分割算法的效果,其中灰度共生算法没有办法直接调用库函数,看了很多文章,其中有一篇博文讲的很清楚。 原文地址 现在按照自己的理解再复盘一遍算法过程,详细推导一下,有一些是上面那个博文搬过来的,本文只是学习笔记,以便日后查询使用。 // 在计算灰度共生矩阵前需要确定一些参数: 灰度共生矩阵灰度级,与灰度共生矩阵的阶数相同,即当灰度图像灰度级为N时,灰度共生矩阵为......

Jen_Hsueh的博客 2万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

灰度共生矩阵-python

本篇博客参考灰度共生矩阵(GLCM)附Python代码 ,对其进行了完善与修改。 灰度共生矩阵(Gray Level Co-occurrence Matrix,GLCM)统计了灰度图中像素间的灰度值分布规律以区分不同的纹理。灰度共生矩阵中每个元素的值可以定义为(x, y)点与(x + dx, y + dy)点的值对为(i, j)的概率。统计整幅图像中每一种灰度值组合出现的概率矩阵 P 即...

明月清風 1万+

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

上一篇: 图像的阈值分割
下一篇: 获取图像的Hu不变矩
Lemon_jay
博客等级 码龄9年 109粉丝 26原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值