graycomatrix 計算(影象)灰度共生矩陣(CLCM)——matlab相關函式說明,很詳細
功 能:建立灰度共生矩陣
Gray-level co-occurrence matrix from an image
影象的灰度共生矩陣
灰度共生矩陣是畫素距離和角度的矩陣函式,它通過計算影象中一定距離和一定方向的兩點灰度之間的相關性,來反映影象在方向、間隔、變化幅度及快慢上的綜合資訊。
使用方法:
glcm = graycomatrix(I)
glcms = graycomatrix(I,param1,val1,param2,val2,...)
[glcms,SI] = graycomatrix(...)
描述:
glcms = graycomatrix(I) 產生影象I的灰度共生矩陣GLCM。它是通過計算兩灰度值 i,j 在影象 I 中水平相鄰的次數而得到的 (你也可以通過調整' Offsets' 引數來指定其它的畫素空間關係),GLCM中的每一個元素(i,j)代表灰度 i 與灰度 j 在影象 I 中水平相鄰的次數。
graycomatrix()先將影象 I 歸一化到指定的灰度級,再計算GLCM;這是因為動態地求取影象的GLCM區間代價過高。如果I是一個二值影象,那麼灰度共生矩陣就將影象轉換到二值灰度級(黑和白)。如果I是一個灰度影象, 那將轉換到8灰度級(預設)。灰度的級數決定了GLCM的大小尺寸,假設灰度級為L,則GLCM的尺寸是L x L。你可以通過設定引數“NumLevels”來指定灰度級數目,還可以通過設定“GrayLimits"引數來設定灰度共生矩陣的轉換方式。
下圖在一個4x5的影象I中顯示瞭如何求解灰度共生矩陣,以(1,1)點為例,在影象 I 中水平相鄰的畫素對的灰度值都為1的情況只出現了1次,所以GLCM(1,1)的值是1。,同理,在影象 I 中水平相鄰的畫素對的灰度值分別為 1和2 的情況出現了2次,所以GLCM(1,2)的值是2。 graycomatrix迭代以上過程,就可以計算出GLCM的所有位置(L^2)的取值。
glcms = graycomatrix(I,param1,val1,param2,val2,...) 返回一個或多個灰度灰度共生矩陣,根據指定的引數對的值。引數可以簡寫,並且對大小寫不敏感。
引數
下面按照字母的順序列寫了引數:
'GrayLimits' 是兩個元素的向量[low,high],指明瞭影象 I 中的灰度值如何線性歸一化到灰度級別。低於或等於low的灰度值置成1,大於或等於high的灰度值置成NumLevels。如果其設為[],灰度共生矩陣將使用影象I的最小和最大灰度值分別作為GrayLimits的low和high,即[min(I(:) , max(I(:)))]。
'NumLevels' 一個整數,指定灰度級的數目。例如,如果NumLevels為8,意思就是將影象I的灰度對映到1到8之間,它也決定了灰度共生矩陣的大小。預設值是8。
'Offset' 一個p*2的整數矩陣,指定了感興趣畫素對之間的距離和方向。矩陣中的每一行是一個兩元素的向量,[row_offset , col_offset],它指定了一對畫素之間的關係,或者說是位移。row_offset是感興趣畫素對間隔的行的數目;col_offset是感興趣畫素對間隔的列的數目。offset通常表示一個角度,下面列寫的offset的值指定了常見角度。D代表是當前畫素與鄰居的距離。
Angle Offset
0 [0 D]
45 [-D D]
90 [-D 0]
135 [-D -D]
下圖說明了陣列:offset = [0 1; -1 1; -1 0; -1 -1]
'Symmetric' 一個布林型數(邏輯型),指定建立GLCM時畫素對中的兩畫素的順序是否考慮。例如,當 'Symmetric' 是true時,graycomatrix計算1連線2的次數時,(1,2)和(2,1)這兩種數對都計算在內。當'Symmetric'是false時,graycomatrix只是計算(1,2)或(2,1).
[glcm,SI] = graycomatrix(....) 返回歸一化(灰度級的)影象,SI,它被用來計算灰度共生矩陣(GLCM),SI影象的取值範圍是[1,NumLevels]。
支援型別
I可以是數字型或邏輯型,但必須是二維的,實數的,非稀疏的矩陣。SI是一個double型矩陣,它和I的尺寸相同。glcms是一個‘NumLevels’ x ‘NumLevels’ x P的double型矩陣,P是offsets的數目(即‘Offset’引數值的列數)。
說明:
灰度共生矩陣(GLCM)的另一個名字是灰度空間相關矩陣(gray-level spatial dependence matrix)。另一方面,co-occurrence在文獻中使用時經常不帶連字元,即cooccurrence。
如果畫素對中的一個畫素值為NaN,graycomatrix忽略該畫素對。
graycomatrix用NumLevels值替代positive Inf,用1代替negative Inf。
如果邊界畫素的鄰居落在影象邊界的外邊,graycomatrix忽略該邊界畫素。
當'Symmetric'設定成'true'時,GLCM 是關於對角線對稱的,就是Haralick (1973)描述的GLCM。下面句法(1)使用'Symmetric'為'true'時建立了GLCM等於句法(2)和句法(3)使用'Symmetric'為‘false’時產生的GLCM的和。
graycomatrix(I, 'offset', [0 1], 'Symmetric', true) (1)
graycomatrix(I,'offset', [0,1], 'Symmetric', false) (2)
graycomatrix(I,'offset', [0,-1], 'Symmetric',false) (3)
示例:
計算灰度共生矩陣,並且返回縮放後的影象,SI
I = [ 1 1 5 6 8 8; 2 3 5 7 0 2; 0 2 3 5 6 7]; % 生成影象I矩陣
[glcm,SI] = graycomatrix(I,'NumLevels',9,'G',[]) % 計算灰度共生矩陣(glcm)和歸一化影象(SI)
計算灰度影象的灰度共生矩陣
I = imread('circuit.tif'); % 讀入circuit.tif影象
glcm = graycomatrix(I,'Offset',[2 0]);
參考文獻
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.
Haralick, R.M., and L.G. Shapiro. Computer and Robot Vision: Vol. 1, Addison-Wesley, 1992, p. 459.
灰度共生矩陣的特徵:
角二階矩(Angular Second Moment, ASM)
也稱為 能量
ASM=sum(p(i,j).^2) p(i,j)指歸一化後的灰度共生矩陣
角二階矩是影象灰度分佈均勻程度和紋理粗細的一個度量,當影象紋理絞細緻、灰度分佈均勻時,能量值較大,反之,較小。
熵(Entropy, ENT)
ENT=sum(p(i,j)*(-ln(p(i,j)))
是描述影象具有的資訊量的度量,表明影象的複雜程式,當複雜程式高時,熵值較大,反之則較小。
反差分矩陣(Inverse Differential Moment, IDM)
IDM=sum(p(i,j)/(1+(i-j)^2))
反映了紋理的清晰程度和規則程度,紋理清晰、規律性較強、易於描述的,值較大;雜亂無章的,難於描述的,值較小。
************************************************************************************************************************************************************************
************************************************************* graycomatrix源程式程式碼 *****************************************************************************
************************************************************************************************************************************************************************
[plain] view plaincopyprint?- function [GLCMS,SI] = graycomatrix(varargin)
- %GRAYCOMATRIX Create gray-level co-occurrence matrix.
- % GLCMS = GRAYCOMATRIX(I) analyzes pairs of horizontally adjacent pixels
- % in a scaled version of I. If I is a binary image, it is scaled to 2
- % levels. If I is an intensity image, it is scaled to 8 levels. In this
- % case, there are 8 x 8 = 64 possible ordered combinations of values for
- % each pixel pair. GRAYCOMATRIX accumulates the total occurrence of each
- % such combination, producing a 8-by-8 output array, GLCMS. The row and
- % column subscripts in GLCMS correspond respectively to the first and
- % second (scaled) pixel-pair values.
- %
- % GLCMS = GRAYCOMATRIX(I,PARAM1,VALUE1,PARAM2,VALUE2,...) returns one or
- % more gray-level co-occurrence matrices, depending on the values of the
- % optional parameter/value pairs. Parameter names can be abbreviated, and
- % case does not matter.
- %
- % Parameters include:
- %
- % 'Offset' A p-by-2 array of offsets specifying the distance
- % between the pixel-of-interest and its neighbor. Each
- % row in the array is a two-element vector,
- % [ROW_OFFSET COL_OFFSET], that specifies the
- % relationship, or 'Offset', between 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. For example, if you want the number of
- % occurrences where the pixel of interest is one pixel
- % to the left of its neighbor, then
- % [ROW_OFFSET COL_OFFSET] is [0 1].
- %
- % Because this 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]
- %
- % ROW_OFFSET and COL_OFFSET must be integers.
- %
- % Default: [0 1]
- %
- % 'NumLevels' An integer specifying the number of gray levels to use when
- % scaling the grayscale values in I. 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).
- %
- % 'NumLevels' must be an integer. 'NumLevels' must be 2 if I
- % is logical.
- %
- % Default: 8 for numeric
- % 2 for logical
- %
- % 'GrayLimits' A two-element vector, [LOW HIGH], that specifies how
- % the grayscale values in I are linearly scaled into
- % gray levels. Grayscale values less than or equal to
- % LOW are scaled to 1. Grayscale values greater than or
- % equal to HIGH are scaled to HIGH. If 'GrayLimits' is
- % set to [], GRAYCOMATRIX uses the minimum and maximum
- % grayscale values in I as limits,
- % [min(I(:)) max(I(:))].
- %
- % Default: the LOW and HIGH values specified by the
- % class, e.g., [LOW HIGH] is [0 1] if I is double and
- % [-32768 32767] if I is int16.
- %
- % 'Symmetric' A Boolean that creates a GLCM where the ordering of
- % values in the pixel pairs is not considered. For
- % example, when calculating the number of times the
- % value 1 is adjacent to the value 2, GRAYCOMATRIX
- % counts both 1,2 and 2,1 pairings, if 'Symmetric' is
- % set to true. When 'Symmetric' is set to false,
- % GRAYCOMATRIX only counts 1,2 or 2,1, depending on the
- % value of 'offset'. The GLCM created in this way is
- % symmetric across its diagonal, and is equivalent to
- % the GLCM described by Haralick (1973).
- %
- % The GLCM produced by the following syntax,
- %
- % graycomatrix(I, 'offset', [0 1], 'Symmetric', true)
- %
- % is equivalent to the sum of the two GLCMs produced by
- % these statements.
- %
- % graycomatrix(I, 'offset', [0 1], 'Symmetric', false)
- % graycomatrix(I, 'offset', [0 -1], 'Symmetric', false)
- %
- % Default: false
- %
- %
- % [GLCMS,SI] = GRAYCOMATRIX(...) returns the scaled image used to
- % calculate GLCM. The values in SI are between 1 and 'NumLevels'.
- %
- % Class Support
- % -------------
- % I can be numeric or logical. I must be 2D, real, and nonsparse. SI is
- % a double matrix having the same size as I. GLCMS is an
- % 'NumLevels'-by-'NumLevels'-by-P double array where P is the number of
- % offsets in OFFSET.
- %
- % Notes
- % -----
- % Another name for a gray-level co-occurrence matrix is a gray-level
- % spatial dependence matrix.
- %
- % GRAYCOMATRIX ignores pixels pairs if either of their values is NaN. It
- % also replaces Inf with the value 'NumLevels' and -Inf with the value 1.
- %
- % GRAYCOMATRIX ignores border pixels, if the corresponding neighbors
- % defined by 'Offset' fall outside the image boundaries.
- %
- % References
- % ----------
- % 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.
- %
- % Haralick, R.M., and L.G. Shapiro. Computer and Robot Vision: Vol. 1,
- % Addison-Wesley, 1992, p. 459.
- %
- % Example 1
- % ---------
- % Calculate the gray-level co-occurrence matrix (GLCM) and return the
- % scaled version of the image, SI, used by GRAYCOMATRIX to generate the
- % GLCM.
- %
- % I = [1 1 5 6 8 8;2 3 5 7 0 2; 0 2 3 5 6 7];
-
相關推薦
graycomatrix 計算(影象)灰度共生矩陣(CLCM)——matlab相關函式說明,很詳細
功 能:建立灰度共生矩陣 Gray-level co-occurrence matrix from an image 影象的灰度共生矩陣 灰度共生矩陣是畫素距離和角度的矩陣函式,它通過計算影象中一定距離和一定方向的兩點灰度之間的相關性,來反映影象在方向、間隔、變化幅度及快慢上
利用灰度共生矩陣提取影象紋理特徵
1. 灰度共生矩陣概念 灰度共生矩陣定義為畫素對的聯合概率分佈,是一個對稱矩陣,它不僅反映影象灰度在相鄰的方向、相鄰間隔、變化幅度的綜合資訊,也反映了相同的灰度級畫素之間的位置分佈特徵,是計算紋理特徵的基礎。 在影象中任意取一點(x,y)及偏離它的一點(x+
影象紋理——灰度共生矩陣
1.灰度共生矩陣生成原理 灰度共生矩陣(GLDM)的統計方法是20世紀70年代初由R.Haralick等人提出的,它是在假定影象中各畫素間的空間分佈關係包含了影象紋理資訊的前提下,提出的具有廣泛性的紋理分析方法。 度共生矩陣被定義為從灰度為i的畫素點出發,離開某個固定位置
灰度共生矩陣及相關特徵值的計算——opencv
#include<iostream> #include<opencv2/highgui.hpp> #include<opencv2/core.hpp> #include<opencv2/imgcodecs.hpp>
灰度共生矩陣的原理
最近在看一些影象分類的東西,出現灰度共生矩陣 不甚明白。一直懵懵懂懂的,直到我看到了下面的圖解: 左側就是原始圖,原圖中一共有1-8個畫素,那麼對應的GLCM就應該是8*8的矩陣,GLCM(1,1)就是在原圖I中畫素值1和1 出現的次數。 在影象中任意一點(x,y)及偏離它的一點(x+
灰度共生矩陣(GLCM,Gray-Level Co-occurrence Matrix)
概念 由於紋理是由灰度分佈在空間位置上反覆出現而形成的,因而在影象空間中相隔某距離的兩畫素之間會存在一定的灰度關係,即影象中灰度的空間相關特性。灰度共生矩陣就是一種通過研究灰度的空間相關特性來描述紋理的常用方法。 灰度共生矩陣是涉及畫素距離和角度的矩陣函式,它通過計算影象中一定距離和
灰度共生矩陣GLCM及其matlab實現
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
灰度共生矩陣(GLCM)
琦小蝦:https://blog.csdn.net/ajianyingxiaoqinghan/article/details/71552744 二. 灰度共生矩陣(GLCM) 1. 演算法簡介 灰度共生矩陣法(GLCM, Gray-level co-occurrence matrix),就是通過
紋理特徵分析的灰度共生矩陣(GLCM)
紋理分析是對影象灰度(濃淡)空間分佈模式的提取和分析。紋理分析在遙感影象、X射線照片、細胞影象判讀和處理方面有廣泛的應用。關於紋理,還沒有一個統一的數學模型。它起源於表徵紡織品表面性質的紋理概念,可以用來描述任何物質組成成分的排列情況,例如醫學上X 射線照片中的肺紋理、血管紋理、航天(或航空)地形照
灰度共生矩陣-python
灰度共生矩陣(Gray Level Co-occurrence Matrix,GLCM)統計了灰度圖中畫素間的灰度值分佈規律以區分不同的紋理。灰度共生矩陣中每個元素的值可以定義為(x, y)點與(x + dx, y + dy)點的值對為(i, j)的概率。統計
灰度共生矩陣(GLCM)
轉載:http://blog.csdn.net/xw20084898/article/details/20528997 灰度共生矩陣 灰度共生矩陣法,顧名思義,就是通過計算灰度影象得到它的共生矩陣,然後透過計算這個共生矩陣得到矩陣的部分特徵值,來分別代表影象的某些紋
MATLAB:虹膜識別的影象灰度化處理,直方圖均衡化
(1)影象灰度化處理: 讀取一張圖片之後,進行灰度化處理,然後對其進行直方圖均值化。 clear;close all %讀取原圖地址 RGB= imread('D:\img\1.jpg'); %影象灰度化處理 GRAY = rgb2gray(RGB); % 直方圖均衡化:Histogr
MATLAB的影象灰度線性變換
下面重點介紹一下如何用MATLAB對影象進行灰度線性變換,具體如下: 1、開啟MATLAB主介面,在其中的編輯器中寫入下列程式碼,其中I=imread('G:\MATLAB練習\bm.bmp');此程式碼是讀入圖片的語句,也就是我們想要處理的圖片,這裡我是存放在G盤的MATLAB練習資料夾中,名
opencv-python 影象灰度變換
灰度變換作為一種影象預處理技術可以顯著的改善影象的質量,下面將介紹幾種灰度變換的方法 1. gamma 變換 Gamma變換是對輸入影象灰度值進行的非線性操作,使輸出影象灰度值與輸入影象灰度值呈指數關係:
影象灰度拉伸
影象灰度拉伸 文章目錄 1 原理 2 Matlab實現 3 OpenCV實現 4 效果 1 原理 影象灰度拉伸是改變影象對比度的一種方法,通過灰度對映,將原圖中某一區段中的灰度值對映到另一灰度值,從而拉伸或壓縮整個影象的灰
簡單的影象灰度化
將彩色圖片轉化為灰度影象的過程叫灰度化處理,對影象的灰度處理有多種方法,在本次實驗中使用的是功能較為強大的影象處理庫OpenCV。 實現內容:讀入一張彩色影象RGBImag,轉換成灰度影象gray。 # -*-coding:utf-8 -*- import cv2 as cv image =
python全域性灰度線性變換——自由設定影象灰度範圍
全域性線性變換的公式是s = (r-a)*(d-c)/(b-a)+c,其中a、b是原圖片的灰度最小值和最大值,c、d是變換後的灰度值的最小值和最大值。r是當前畫素點的灰度值,s是當前畫素點變換後的灰度值
C++——bmp影象灰度化+二值化
本文實現bmp影象的灰度化及二值化操作:1、灰度化 對於彩色轉灰度,有一個很著名的心理學公式: Gray = R*0.299 + G*0.587 + B*0.114而實際應用時,希望避免低速的浮點運算,所以需要整數
影象灰度化
灰度就是沒有色彩,RGB色彩分量全部相等。 一個256級灰度的圖象,如果RGB三個量相同時,如:RGB(100,100,100)就代表灰度為100,RGB(50,50,50)代表灰度為50。 影象灰度化處理可以作為影象處理的預處理步驟,為之後的影象分割、影象識別和影象分析等上層操作做準備。
matlab影象灰度調整——imadjust函式的使用
在MATLAB中,通過函式imadjust()進行影象灰度的調整,該函式呼叫格式如下:J=imadjust( I ) 對影象I進行灰度調整J=imadjust( I,[low_in;high_in],[low_out;high_out]) [low_in;high_in]為