[英]Creating gray-level co-occurrence matrix from 16-bit image
我有一個16位圖像的數據集,我想從中創建GLCM矩陣以提取GLCM特征。
但是,結果矩陣顯示一個值(如下圖所示),我想知道為什么。
我嘗試使用相同的圖像,但轉換為8位,結果GLCM顯示多個值。
注意:我使用了以下Matlab函數:
glcm_matrix = graycomatrix(image.tif);
這是16位圖像的裁剪樣本:
注意:計算中使用的圖像可從此處下載。 原始圖像對比度很低,看起來完全暗。 上面顯示的圖像具有被拉伸的對比度,僅用於可視化目的。
編輯:
我用了
glcm_matrix = graycomatrix(image.tif, 'GrayLimits', []);
它給了我以下結果:
這是一個裝箱/縮放問題。
讓我們來看看里面:
edit graycomatrix
在這種情況下,我們對兩個選項“ NumLevels”和“ GrayLimits”感興趣
% '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 values in I are scaled into gray levels. 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(:))].
因此,換句話說,該函數將您的數據分成8x8個bin,並假設縮放范圍是整個uint16范圍(0-65535)。 但是,您提供的樣本圖像最小值為305,最大值為769,使其落入第一個bin中(0-8192左右)。 當我調用A = graycomatrix(I)
它給出了以下矩陣:
A =
6600 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
但是,當A = graycomatrix(I,'GrayLimits', [])
,縮放范圍取為min(I) A = graycomatrix(I,'GrayLimits', [])
(I),並且該函數按預期工作:
A =
4 2 1 0 0 0 0 0
1 1 2 2 0 0 0 0
2 2 4 7 1 0 0 0
0 1 7 142 72 1 0 0
0 0 0 65 1711 252 0 0
0 0 0 0 230 3055 178 0
0 0 0 0 0 178 654 8
0 0 0 0 0 0 8 9
在您的原始示例中,單個值最有可能在8x8矩陣的中間,因為您的原始圖像是int16而不是uint16,因此考慮到負值的可能性,灰度comatrix是對稱的。
當然,您也可以縮放原始圖像以適合其數據類型。 例如,如果您預期有異常值,百分位數縮放可能是個好主意。
我只是想以@Tapio的出色答案為基礎。
當您在函數調用中使用名稱/值對GrayLimits', []
時,由graycomatrix
的GLCM看起來不錯。 但是,這種方法可能對您的應用程序無效。 如果以此方式為一組圖像計算GLCM,則對應於兩個不同圖像的兩個不同GLCM的相同元素可能具有不同的含義。 確實,由於對每個圖像的強度進行了不同的縮放,因此GLCM的組件實際上在編碼從一個圖像到另一個圖像的不同同時出現。
為避免這種情況,您可以首先計算整個圖像數據集的最小和最大強度(例如minImgs
和maxImgs
),然后使用這些值以完全相同的方式重新調整構成數據集的所有圖像的強度:
glcm_matrix = graycomatrix(image_tif, 'GrayLimits', [minImgs maxImgs]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.