我正在使用skimage
库进行大多数图像分析工作.
我有一个RGB图像,我打算提取texture
喜欢的功能entropy
,energy
,homogeneity
并contrast
从图像.
以下是我正在执行的步骤:
from skimage import io, color, feature
from skimage.filters import rank
rgbImg = io.imread(imgFlNm)
grayImg = color.rgb2gray(rgbImg)
print(grayImg.shape) # (667,1000), a 2 dimensional grayscale image
glcm = feature.greycomatrix(grayImg, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4])
print(glcm.shape) # (256, 256, 1, 4)
rank.entropy(glcm, disk(5)) # throws an error since entropy expects a 2-D array in its arguments
rank.entropy(grayImg, disk(5)) # given an output.
Run Code Online (Sandbox Code Playgroud)
我的问题是,从灰度图像(直接)计算的熵是否与从GLCM(纹理特征)中提取的熵特征相同?
如果没有,从图像中提取所有纹理特征的正确方法是什么?
注:我已经提到过:
我想在 Tensorflow 中应用各种过滤器,如GLCM或Gabor 过滤器组作为自定义层,但我找不到足够的自定义层样本。如何将这些类型的过滤器应用为图层?
生成GLCM的过程在scikit-image库中定义如下:
from skimage.feature import greycomatrix, greycoprops
from skimage import data
#load image
img = data.brick()
#result glcm
glcm = greycomatrix(img, distances=[5], angles=[0], levels=256, symmetric=True, normed=True)
Run Code Online (Sandbox Code Playgroud)
Gabor滤波器组的使用如下:
import matplotlib.pyplot as plt
import numpy as np
from scipy import ndimage as ndi
from skimage import data
from skimage.util import img_as_float
from skimage.filters import gabor_kernel
shrink = (slice(0, None, 3), slice(0, None, 3))
brick = img_as_float(data.brick())[shrink]
grass = img_as_float(data.grass())[shrink]
gravel = img_as_float(data.gravel())[shrink]
image_names = ('brick', …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 GLCM 算法对卫星图像进行纹理分析。scikit-image 文档对此非常有帮助,但对于 GLCM 计算,我们需要在图像上循环的窗口大小。这在 Python 中太慢了。我在 stackoverflow 上找到了很多关于滑动窗口的帖子,但计算需要永远进行。我有一个如下所示的示例,它有效但需要很长时间。我想这一定是一种天真的做法
image = np.pad(image, int(win/2), mode='reflect')
row, cols = image.shape
feature_map = np.zeros((M, N))
for m in xrange(0, row):
for n in xrange(0, cols):
window = image[m:m+win, n:n+win]
glcm = greycomatrix(window, d, theta, levels)
contrast = greycoprops(glcm, 'contrast')
feature_map[m,n] = contrast
Run Code Online (Sandbox Code Playgroud)
我遇到了skimage.util.view_as_windows
一种方法,这对我来说可能是一个很好的解决方案。我的问题是,当我尝试计算 GLCM 时,出现错误:
ValueError:参数
image
必须是二维数组
这是因为 GLCM 图像的结果具有 4d 维度,而 scikit-imageview_as_windows
方法仅接受 2d 数组。这是我的尝试
win_w=40
win_h=40
features = np.zeros(image.shape, dtype='uint8')
target = features[win_h//2:-win_h//2+1, win_w//2:-win_w//2+1]
windowed = …
Run Code Online (Sandbox Code Playgroud) 我正在使用 scikit-image 工具将 Matlab 图像处理算法转移到 Python,并使用greycomatrix计算灰度共生矩阵 ( GLCM ) 。如果参数小于强度图像的最大值 ( ),我会遇到问题。例如:levels
image.max()
import numpy as np
from skimage.feature import greycomatrix
image = np.array([[0, 0, 1, 1],[0, 0, 1, 1],[0, 2, 2, 2],[2, 2, 3, 3]], dtype=np.uint8)
result = greycomatrix(image, distances = [1], angles = [0], levels = 4, symmetric=True)
Run Code Online (Sandbox Code Playgroud)
输出是:
glcm = result[:,:,0,0]
array([[4, 2, 1, 0],
[2, 4, 0, 0],
[1, 0, 6, 1],
[0, 0, 1, 2]], dtype=uint32)
Run Code Online (Sandbox Code Playgroud)
这是正确的,4x4 矩阵。但如果levels=3
,我无法计算 GLCM,错误是:
result = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Python 和 skimage 实现本教程中描述的纹理图像。
问题是将 7x7 窗口移动到大光栅上,并用 7x7 窗口计算出的纹理替换每个像素的中心。我设法用下面的代码来做到这一点,但除了循环遍历每个单独的像素之外,我没有其他方法,这非常慢。
一个软件包可以在几秒钟内完成此操作,因此必须有其他方法......有吗?
这里的代码可以工作但非常慢......
import matplotlib.pyplot as plt
import gdal, gdalconst
import numpy as np
from skimage.feature import greycomatrix, greycoprops
filename = "//mnt//glaciology//RS2_20140101.jpg"
outfilename = "//home//max//Documents//GLCM_contrast.tif"
sarfile = gdal.Open(filename, gdalconst.GA_ReadOnly)
sarraster = sarfile.ReadAsArray()
#sarraster is satellite image, testraster will receive texture
testraster = np.copy(sarraster)
testraster[:] = 0
for i in range(testraster.shape[0] ):
print i,
for j in range(testraster.shape[1] ):
#windows needs to fit completely in image
if i <3 or j …
Run Code Online (Sandbox Code Playgroud) 我生成了这样的纹理图像
我必须比较两个纹理。我使用了直方图比较方法。
image_file = 'output_ori.png'
img_bgr = cv2.imread(image_file)
height, width, channel = img_bgr.shape
hist_lbp = cv2.calcHist([img_bgr], [0], None, [256], [0, 256])
print("second started")
image_fileNew = 'output_scan.png'
img_bgr_new = cv2.imread(image_fileNew)
height_new, width_new, channel_new = img_bgr_new.shape
print("second lbp")
hist_lbp_new = cv2.calcHist([img_bgr_new], [0], None, [256], [0, 256])
print("compar started")
compare = cv2.compareHist(hist_lbp, hist_lbp_new, cv2.HISTCMP_CORREL)
print(compare)
Run Code Online (Sandbox Code Playgroud)
但是这种方法无效。对于两种不同的图像纹理,它显示出相似的结果。同样,它并没有显示太多变化来识别打印和扫描效果。如何比较纹理?我想到分析GLCM特性。
import cv2
import numpy as np
from skimage.feature import greycomatrix
img = cv2.imread('images/noised_img1.jpg', 0)
image = np.array(img, dtype=np.uint8)
g = greycomatrix(image, [1, 2], [0, np.pi/2], levels=4, normed=True, …
Run Code Online (Sandbox Code Playgroud) 我必须在 Python 中找到基于纹理的图像特征,例如相关性、能量、同质性和对比度。我正在使用 python-opencv 执行其他操作,因为 python-opencv 将图像作为 numpy 数组返回。但是我没有找到任何使用 opencv 或 numpy 计算 GLCM 的好资源。此外,我不得不提取特征的d=1
和angle=[0,45,135,90]
,然后在SVM使用此功能。
我正在使用R中的glcm包在Landsat波段上从灰度共现矩阵(GLCM)运行图像纹理度量,我想知道mean'和'mean_ENVI'/'variance'和' variance_ENVI'。
这似乎是一个基本问题,但我找不到很好的解释。
library(glcm)
Feb2014_B2 <-raster ("Feb2014_band2x.tif")
Feb2014.B2.textures3x3 <- glcm(Feb2014_B2, window = c(3, 3), shift = c(1, 1),
statistics = c("mean", "mean_ENVI", "variance", "variance_ENVI",
"homogeneity", "contrast", "dissimilarity", "entropy", "second_moment",
"correlation"), na_opt="any", na_val=NA)
Run Code Online (Sandbox Code Playgroud) glcm ×9
python ×8
scikit-image ×6
numpy ×3
textures ×2
entropy ×1
gabor-filter ×1
mahotas ×1
opencv ×1
r ×1
tensorflow ×1