2017-04-06 75 views
2

我試圖用一系列4波段(R,G,B,NIR)航空照片計算一些使用Haralick描述的GLCM(能量,同質性等)有。我已經在一個子集上嘗試了這一點,但結果是大部分是空白的圖像。我目前的理解是,它與greyscaling和levels參數有關,但我無法弄清楚。GLCM圖像中的黑色空間

我的日期是非常大的(幾個GB)所以我想是通過使用模塊RIOS(在效率作爲400 × 400個× nbands numpy的陣列,處理該數據讀取圖像,並寫出到輸出圖片)。

我的輸入場景可以找到here(200 MB)。

我的輸出圖像看起來像(這可能是很難看到的黑色像素都非常小):

output

我的代碼是:

#Set up input and output filenames 
infiles = applier.FilenameAssociations() 
infiles.image1 = "infile.tif" 

outfiles = applier.FilenameAssociations() 
outfiles.outimage = "outfile.tif" 

controls = applier.ApplierControls() 
controls.progress = cuiprogress.CUIProgressBar() 
# I ultimately want to use a window here 
# which RIOS easily allows you to set up. 
# For a 3x3 the overlap is 1, 5x5 overlap is 2 etc 
#controls.setOverlap(4) 

def doFilter(info, infiles, outfiles, controls=controls): 
    grayImg = img_as_ubyte(color.rgb2gray(infiles.image1[3])) 
    g = greycomatrix(grayImg, distances=[1], angles=[0, np.pi/4, np.pi/2, 3*np.pi/4], symmetric=True, normed=True) 
    filtered = greycoprops(g, 'energy') 
    # create 3d image from 2d array 
    outfiles.outimage = numpy.expand_dims(filtered, axis=0) 


applier.apply(doFilter, infiles, outfiles, controls=controls) 

顯然有些不妥因爲我的產出不像我預期的那樣。我猜測它是用'levels'參數來做的。我已經在這裏指出了一個解釋:Black line in GLCM result它很好地解釋了這個參數,但是我無法改進我的結果。

有人可以向我解釋爲什麼我的結果如圖所示出現以及如何補救?

+0

您的圖片是二進制的,所有的像素強度或者是'0'或'255'。執行'np.unique()'說服自己。這種圖像的GLCM將只有四個非零條目。 – Tonechas

+0

numpy.unique yield [21 22 23 24 25 26 27 28 29 30 3 ......... 186 187 188 189 190 191 192 193 194 195 196 197 198] –

+0

我跑這段代碼: 'import numpy as np' 'from skimage import io' 'x = io.imread('https://i.stack.imgur.com/EyCI1.png')' 'np.unique(x)' '並獲得:'array([0,255],dtype = uint8)' – Tonechas

回答

2

下面的代碼計算對應於偏移 「1像素向上偏移」 從你的TIF圖像的NIR頻帶GLCM:

import numpy as np 
from skimage import io 
from skimage.feature import greycomatrix, greycoprops 

x = io.imread('m_2909112_se_15_1_20150826.tif') 
nir = x[:, :, 3] 

glcm = greycomatrix(nir, [1], [np.pi/2], levels=256, normed=True, symmetric=True) 

這是如何nir看起來:

NIR band

將參數normed設置爲True的效果是計算的GLCM除以其總和,結果glcm的元素具有小的價值。這裏有一個例子:

In [48]: np.set_printoptions(precision=3) 

In [49]: glcm[:5, :5, 0, 0] 
Out[49]: 
array([[ 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00], 
     [ 0.000e+00, 2.725e-03, 6.940e-05, 3.725e-05, 2.426e-05], 
     [ 0.000e+00, 6.940e-05, 1.709e-04, 4.103e-05, 2.216e-05], 
     [ 0.000e+00, 3.725e-05, 4.103e-05, 4.311e-04, 4.222e-05], 
     [ 0.000e+00, 2.426e-05, 2.216e-05, 4.222e-05, 5.972e-05]]) 

要顯示glcm爲圖像,你需要重新調整它,例如像這樣:

from skimage.exposure import rescale_intensity 
scaled = rescale_intensity(glcm[:,:,0,0]) 
io.imshow(scaled) 

scaled

+0

中添加我的實際數據我已經實現了你的建議,但我的結果是一樣的。我使用打印語句查看了一些輸出。正如我所期望的,數據正在以塊的形式被讀入,如:[174 169 176 179 200 203 200 183 175 192 186 180 183 181 187 178 170 177 171 ...... 173 166 155 148 166 162 138 115 146 163 172 170 172 173 173 180 181 173 171 171],但greycomatrix的結果通常是空的,就像[0 0 0 0],只有少數填充的像[0 1 0 1]。這主要是將空數組傳遞給greycoprops命令。 –