我試圖用一系列4波段(R,G,B,NIR)航空照片計算一些使用Haralick描述的GLCM(能量,同質性等)有。我已經在一個子集上嘗試了這一點,但結果是大部分是空白的圖像。我目前的理解是,它與greyscaling和levels
參數有關,但我無法弄清楚。GLCM圖像中的黑色空間
我的日期是非常大的(幾個GB)所以我想是通過使用模塊RIOS(在效率作爲400 × 400個× nbands numpy的陣列,處理該數據讀取圖像,並寫出到輸出圖片)。
我的輸入場景可以找到here(200 MB)。
我的輸出圖像看起來像(這可能是很難看到的黑色像素都非常小):
我的代碼是:
#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'或'255'。執行'np.unique()'說服自己。這種圖像的GLCM將只有四個非零條目。 –
Tonechas
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] –
我跑這段代碼: '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