本文整理汇总了Python中skimage.feature.greycomatrix函数的典型用法代码示例。如果您正苦于以下问题:Python greycomatrix函数的具体用法?Python greycomatrix怎么用?Python greycomatrix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了greycomatrix函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_output_empty
def test_output_empty(self):
result = greycomatrix(self.image, [10], [0], 4)
np.testing.assert_array_equal(result[:, :, 0, 0],
np.zeros((4, 4), dtype=np.uint32))
result = greycomatrix(self.image, [10], [0], 4, normed=True)
np.testing.assert_array_equal(result[:, :, 0, 0],
np.zeros((4, 4), dtype=np.uint32))
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_texture.py
示例2: get_textural_features
def get_textural_features(img, isMultidirectional=False, distance=1):
'''Extract GLCM feature vector from image
Args:
img: input image.
isMultidirectional: Controls whether co-occurence should be calculated
in other directions (ie 45 degrees, 90 degrees and 135 degrees).
distance: Distance between pixels for co-occurence.
Returns:
features: if isMultidirectional=False, this is a 4 element vector of
[dissimilarity, correlation,homogeneity, energy]. If not it is a 16
element vector containing each of the above properties in each direction.
'''
if(isMultidirectional):
img = img_as_ubyte(rgb2gray(img))
glcm = greycomatrix(img, [distance], [0, 0.79, 1.57, 2.36], 256, symmetric=True, normed=True)
dissimilarity_1 = greycoprops(glcm, 'dissimilarity')[0][0]
dissimilarity_2 = greycoprops(glcm, 'dissimilarity')[0][1]
dissimilarity_3 = greycoprops(glcm, 'dissimilarity')[0][2]
dissimilarity_4 = greycoprops(glcm, 'dissimilarity')[0][3]
correlation_1 = greycoprops(glcm, 'correlation')[0][0]
correlation_2 = greycoprops(glcm, 'correlation')[0][1]
correlation_3 = greycoprops(glcm, 'correlation')[0][2]
correlation_4 = greycoprops(glcm, 'correlation')[0][3]
homogeneity_1 = greycoprops(glcm, 'homogeneity')[0][0]
homogeneity_2 = greycoprops(glcm, 'homogeneity')[0][1]
homogeneity_3 = greycoprops(glcm, 'homogeneity')[0][2]
homogeneity_4 = greycoprops(glcm, 'homogeneity')[0][3]
energy_1 = greycoprops(glcm, 'energy')[0][0]
energy_2 = greycoprops(glcm, 'energy')[0][1]
energy_3 = greycoprops(glcm, 'energy')[0][2]
energy_4 = greycoprops(glcm, 'energy')[0][3]
feature = np.array([dissimilarity_1, dissimilarity_2, dissimilarity_3,\
dissimilarity_4, correlation_1, correlation_2, correlation_3, correlation_4,\
homogeneity_1, homogeneity_2, homogeneity_3, homogeneity_4, energy_1,\
energy_2, energy_3, energy_4])
return feature
else:
img = img_as_ubyte(rgb2gray(img))
glcm = greycomatrix(img, [distance], [0], 256, symmetric=True, normed=True)
dissimilarity = greycoprops(glcm, 'dissimilarity')[0][0]
correlation = greycoprops(glcm, 'correlation')[0][0]
homogeneity = greycoprops(glcm, 'homogeneity')[0][0]
energy = greycoprops(glcm, 'energy')[0][0]
feature = np.array([dissimilarity, correlation, homogeneity, energy])
return feature
开发者ID:oduwa,项目名称:Wheat-Count,代码行数:48,代码来源:Helper.py
示例3: matriz_coocorrencia
def matriz_coocorrencia(self):
"""
Extraí atributos de textura baseados em matrizes de coocorrência (GLCM). São utilizadas matrizes 4x4
nas distäncias 1 e 2 e com ângulos 0, 45 e 90.
"""
g = feature.greycomatrix(self.imagemTonsDeCinza, [1, 2], [0, np.pi / 4, np.pi / 2], glcmNiveis,normed=True, symmetric=True)
contrastes = feature.greycoprops(g, 'contrast').tolist()
dissimilaridades = feature.greycoprops(g, 'dissimilarity').tolist()
homogeneidades = feature.greycoprops(g, 'homogeneity').tolist()
asm = feature.greycoprops(g, 'ASM').tolist()
energias = feature.greycoprops(g, 'energy').tolist()
correlacoes = feature.greycoprops(g, 'correlation').tolist()
nomes = [
'glcm_cont_1_0', 'glcm_cont_1_45', 'glcm_cont_1_90', 'glcm_cont_2_0', 'glcm_cont_2_45', 'glcm_cont_2_90',
'glcm_diss_1_0', 'glcm_diss_1_45', 'glcm_diss_1_90', 'glcm_diss_2_0', 'glcm_diss_2_45', 'glcm_diss_2_90',
'glcm_homo_1_0', 'glcm_homo_1_45', 'glcm_homo_1_90', 'glcm_homo_2_0', 'glcm_homo_2_45', 'glcm_homo_2_90',
'glcm_asm_1_0', 'glcm_asm_1_45', 'glcm_asm_1_90', 'glcm_asm_2_0', 'glcm_asm_2_45', 'glcm_asm_2_90',
'glcm_ener_1_0', 'glcm_ener_1_45', 'glcm_ener_1_90', 'glcm_ener_2_0', 'glcm_ener_2_45', 'glcm_ener_2_90',
'glcm_corr_1_0', 'glcm_corr_1_45', 'glcm_corr_1_90', 'glcm_corr_2_0', 'glcm_corr_2_45', 'glcm_corr_2_90',
]
tipos = [numerico] * len(nomes)
valores = contrastes[0] + contrastes[1] + dissimilaridades[0] + dissimilaridades[1] + homogeneidades[0] + \
homogeneidades[1] + asm[0] + asm[1] + energias[0] + energias[1] + correlacoes[0] + correlacoes[1]
return nomes, tipos, valores
开发者ID:fernandovieiraf02,项目名称:superpixel,代码行数:32,代码来源:extratores.py
示例4: GLCM
def GLCM(im):
"""Calculate the grey level co-occurrence matrices and output values for
contrast, dissimilarity, homogeneity, energy, correlation, and ASM in a list"""
newIm = im.convert('L') #Conver to a grey scale image
glcm = greycomatrix(newIm, [5], [0]) #calcualte the glcm
#Compute all of the grey co occurrence features.
contrast = greycoprops(glcm, 'contrast')[0][0]
if numpy.isnan(contrast): #Make sure that no value is recorded as NAN.
contrast = 0 #if it is replace with 0.
dissim = greycoprops(glcm, 'dissimilarity')[0][0]
if numpy.isnan(dissim):
dissim = 0
homog = greycoprops(glcm, 'homogeneity')[0][0]
if numpy.isnan(homog):
homog = 0
energy = greycoprops(glcm, 'energy')[0][0]
if numpy.isnan(energy):
energy = 0
corr = greycoprops(glcm, 'correlation')[0][0]
if numpy.isnan(corr):
corr = 0
ASM = greycoprops(glcm, 'ASM')[0][0]
if numpy.isnan(ASM):
ASM = 0
return numpy.concatenate(([contrast], [dissim], [homog], [energy], [corr], [ASM]), 0) #concatenate into one list along axis 0 and return
开发者ID:cassieburgess,项目名称:Flower-Classification,代码行数:27,代码来源:ImageProcess.py
示例5: glide
def glide(image, w, d, theta, levels=16, step=2):
image = np.pad(image, int(w/2), mode='reflect')
M, N = image.shape
# map_homo = np.zeros((M, N))
# map_iner = np.zeros((M, N))
# map_clsh = np.zeros((M, N))
map_Q1 = np.zeros((M, N))
map_Q2 = np.zeros((M, N))
map_Q4 = np.zeros((M, N))
for m in xrange(0, M, step):
print m
for n in xrange(0, N, step):
window = image[m:m+w, n:n+w]
P = greycomatrix(
window, d, theta*np.pi/180, levels,
symmetric=True, normed=True,
).mean(axis=(2,3)) / float(len(d) * len(theta))
mu = np.mean(window)
# map_homo[m:m+step, n:n+step] = homogeneity(P)
# map_iner[m:m+step, n:n+step] = inertia(P)
# map_clsh[m:m+step, n:n+step] = clustershade(P)
map_Q1[m:m+step, n:n+step] = Q1(P)
map_Q2[m:m+step, n:n+step] = Q2(P)
map_Q4[m:m+step, n:n+step] = Q4(P)
# return map_homo, map_iner, map_clsh
return map_Q1, map_Q2, map_Q4
开发者ID:PaulMag,项目名称:INF4300_project,代码行数:29,代码来源:glcm.py
示例6: test_uniform_properties
def test_uniform_properties(self):
im = np.ones((4, 4), dtype=np.uint8)
result = greycomatrix(im, [1, 2, 8], [0, np.pi / 2], 4, normed=True,
symmetric=True)
for prop in ['contrast', 'dissimilarity', 'homogeneity',
'energy', 'correlation', 'ASM']:
greycoprops(result, prop)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:7,代码来源:test_texture.py
示例7: compute_feats
def compute_feats(image, distances, angles):
"""
compute the texture feature by grey level co-occurrence matrices
:param image: is just numpy array
:param distances: List of pixel pair distance offsets
:param angles: List of pixel pair angles in radians for the offsets
:return: [[diss1, corr1], [diss2, corr2], [diss3, corr3], [diss4, corr4]... ] stand for dissimilarity and correlation attribute of co-occurrence matrix by different input parameters combinations [[dis1, ang1], [dis1, ang2],[dis2, ang1],[dis2, ang2]]. So there are totally len(distances) * len(angles) pairs of return features, wrapped by pandas.Series
"""
glcm = greycomatrix(image, distances, angles, 256, symmetric=True, normed=True)
dissimilarities = greycoprops(glcm, 'dissimilarity').flat
correlations = greycoprops(glcm, 'correlation').flat
energy = greycoprops(glcm, 'energy').flat
data = []
label_l2 = []
for idx, (d, c, e) in enumerate(zip(dissimilarities, correlations, energy)):
data.append(d)
label_l2.append(feature_name_dissimilarity.format(idx))
data.append(c)
label_l2.append(feature_name_correlation.format(idx))
data.append(e)
label_l2.append(feature_name_energy.format(idx))
label_l1 = [feature_method_name] * len(data)
index = pd.MultiIndex.from_tuples(list(zip(label_l1, label_l2)), names=['method', 'attr'])
return pd.Series(data, index)
开发者ID:erdincay,项目名称:ScoreGrass,代码行数:29,代码来源:GLCM.py
示例8: GLCM_features
def GLCM_features(img):
gray = rgb2gray(img)
gmatr = greycomatrix(gray, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4])
contrast = greycoprops(gmatr, 'contrast')
correlation = greycoprops(gmatr, 'correlation')
energy = greycoprops(gmatr, 'energy')
homogeneity = greycoprops(gmatr, 'homogeneity')
return [contrast, correlation, energy, homogeneity]
开发者ID:HackKPV,项目名称:GimmeEmotionData,代码行数:8,代码来源:texture_features.py
示例9: texture_prop
def texture_prop(region,patch_size = 2):
_mean_min = region_props[0][region]-patch_size;
_mean_max = region_props[0][region]+patch_size;
glcm = greycomatrix(gray_frame[_mean_min[0]:_mean_max[0],_mean_min[1]:_mean_max[1]],
[3], [0], 256, symmetric=True, normed=True)
_dis = greycoprops(glcm, 'dissimilarity')[0, 0];
_cor = greycoprops(glcm, 'correlation')[0, 0];
return (_dis,_cor);
开发者ID:sudhargk,项目名称:video-annotator,代码行数:8,代码来源:__init__.py
示例10: calc_texture
def calc_texture(inputs):
inputs = np.reshape(a=inputs, newshape=[ksize, ksize])
inputs = inputs.astype(np.uint8)
# Greycomatrix takes image, distance offset, angles (in radians), symmetric, and normed
# http://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.greycomatrix
glcm = greycomatrix(inputs, [offset], [0], 256, symmetric=True, normed=True)
diss = greycoprops(glcm, texture_method)[0, 0]
return diss
开发者ID:danforthcenter,项目名称:plantcv,代码行数:8,代码来源:threshold_methods.py
示例11: get_features
def get_features(img):
grey_m = greycomatrix(img, [5], [0, np.pi/4, np.pi/2, 3*np.pi/4], levels=256)
# grey_props = ['contrast', 'dissimilarity', 'homogeneity', 'ASM', 'energy', 'correlation']
grey_props = ['contrast', 'dissimilarity', 'homogeneity', 'ASM', 'energy']
grey_feas = []
for prop in grey_props:
grey_fea = greycoprops(grey_m, prop)
grey_feas.extend(list(grey_fea))
return grey_props, grey_feas
开发者ID:brianchan1024,项目名称:cervical_img_clf,代码行数:9,代码来源:glcm_features.py
示例12: texture_moving_window
def texture_moving_window(input_band_list,window_dimension,index,quantization_factor):
'''Compute the desired spectral feature from each window
:param input_band_list: list of 2darrays (list of numpy arrays)
:param window_dimension: dimension of the processing window (integer)
:param index: string with index to compute (contrast, energy, homogeneity, correlation, dissimilarity, ASM) (string)
:param quantization_factor: number of levels to consider (suggested 64) (integer)
:returns: list of 2darrays corresponding to computed index per-band (list of numpy arrays)
:raises: AttributeError, KeyError
Author: Daniele De Vecchi - Mostapha Harb
Last modified: 19/03/2014
'''
#TODO: Please explain better what this function does. I assume it calculates GLCM derived features from a moving window.
#TODO: Always provide full list of options in function description (e.g. which features are supported here?)
#TODO: Output should be array. Only dissimilarity and only 3 bands?
band_list_q = linear_quantization(input_band_list,quantization_factor)
output_list = []
feat1 = 0.0
rows,cols=input_band_list[0].shape
output_ft_1 = np.zeros((len(input_band_list),rows,cols)).astype(np.float32)
print input_band_list[0].shape
if (rows%window_dimension)!=0:
rows_w = rows-1
else:
rows_w = rows
if (cols%window_dimension)!=0:
cols_w = cols-1
else:
cols_w = cols
print rows,cols
#
# rows_w = 10
for i in range(0,rows_w):
print str(i+1)+' of '+str(rows_w)
for j in range(0,cols_w):
for b in range(0,len(input_band_list)):
data_glcm_1 = band_list_q[0][i:i+window_dimension,j:j+window_dimension] #extract the data for the glcm
if (i+window_dimension<rows_w) and (j+window_dimension<cols_w):
glcm1 = greycomatrix(data_glcm_1, [1], [0, np.pi/4, np.pi/2, np.pi*(3/4)], levels=quantization_factor, symmetric=False, normed=True)
feat1 = greycoprops(glcm1, index)[0][0]
index_row = i+1 #window moving step
index_col = j+1 #window moving step
output_ft_1[b][index_row][index_col]=float(feat1) #stack to store the results for different bands
for b in range(0,len(input_band_list)):
output_list.append(output_ft_1[b][:][:])
return output_list
开发者ID:SENSUM-project,项目名称:sensum_rs,代码行数:57,代码来源:features.py
示例13: compute
def compute(self, image):
glcm = feature.greycomatrix(image, self.distance, self.angle, 256,
symmetric = True, normed = True)
#Calculating and normalizing the histogram
x = itemfreq(glcm.ravel())
hist = x[:, 1]/sum(x[:, 1])
return hist
开发者ID:kevin-george,项目名称:surface-characterization,代码行数:9,代码来源:gray_level_cooccurrence_matrix.py
示例14: get_textural_features
def get_textural_features(img):
img = img_as_ubyte(rgb2gray(img))
glcm = greycomatrix(img, [1], [0], 256, symmetric=True, normed=True)
dissimilarity = greycoprops(glcm, 'dissimilarity')[0, 0]
correlation = greycoprops(glcm, 'correlation')[0, 0]
homogeneity = greycoprops(glcm, 'homogeneity')[0, 0]
energy = greycoprops(glcm, 'energy')[0, 0]
feature = np.array([dissimilarity, correlation, homogeneity, energy])
return feature
开发者ID:oduwa,项目名称:Wheat-Count,代码行数:9,代码来源:build_classifier.py
示例15: parallel_me
def parallel_me(Z, dissim, correl, contrast, energy, mn):
try:
glcm = greycomatrix(Z, [5], [0], 256, symmetric=True, normed=True)
if (greycoprops(glcm, 'dissimilarity')[0, 0] < dissim) and (greycoprops(glcm, 'correlation')[0, 0] < correl) and (greycoprops(glcm, 'contrast')[0, 0] < contrast) and (greycoprops(glcm, 'energy')[0, 0] > energy) and (np.mean(Z)<mn):
return 1
else:
return 0
except:
return 0
开发者ID:dbuscombe-usgs,项目名称:PyHum,代码行数:9,代码来源:_pyhum_rmshadows.py
示例16: glcm
def glcm(imagem,mask,grayLevels,d):
imagem = cv2.equalizeHist(imagem)
imagem = categorizar(imagem,8)
imagem = cv2.bitwise_and(imagem,mask)
matrix0 = greycomatrix(imagem, [d], [0], levels=grayLevels)
matrix1 = greycomatrix(imagem, [d], [np.pi/4], levels=grayLevels)
matrix2 = greycomatrix(imagem, [d], [np.pi/2], levels=grayLevels)
matrix3 = greycomatrix(imagem, [d], [3*np.pi/4], levels=grayLevels)
matrix = (matrix0+matrix1+matrix2+matrix3)/4 #isotropic glcm
if mask != []:
matrix[0,0,0,0] = 0 #remove 0->0 (mask)
props = np.zeros((5))
props[0] = greycoprops(matrix,'contrast')
props[1] = greycoprops(matrix,'dissimilarity')
props[2] = greycoprops(matrix,'homogeneity')
props[3] = greycoprops(matrix,'energy')
props[4] = greycoprops(matrix,'ASM')
return props
开发者ID:flavio86,项目名称:useR,代码行数:18,代码来源:glcm.py
示例17: glcm
def glcm(image, angles, dists):
"""
Extract features from the image.
Args:
image: An image read in by cv2.imread(...)
angles: A list containing angles, e.g. [0, 45, 90, 135]
dists: A list containing pixel distances, e.g. [0, 1, 2, 3]
Returns:
A gray-level co-occurrence matrix.
"""
if isinstance(image, list):
glcms = []
for i in range(0, len(image)):
glcms.append(greycomatrix(image[i], angles, dists, 256, symmetric=True, normed=True))
return glcms
else:
return greycomatrix(image, angles, dists, 256, symmetric=True, normed=True)
开发者ID:charlienewey,项目名称:penumbra-python,代码行数:18,代码来源:glcm.py
示例18: test_output_symmetric_1
def test_output_symmetric_1(self):
result = greycomatrix(self.image, [1], [np.pi / 2], 4,
symmetric=True)
assert result.shape == (4, 4, 1, 1)
expected = np.array([[6, 0, 2, 0],
[0, 4, 2, 0],
[2, 2, 2, 2],
[0, 0, 2, 0]], dtype=np.uint32)
np.testing.assert_array_equal(result[:, :, 0, 0], expected)
开发者ID:TheArindham,项目名称:scikit-image,代码行数:9,代码来源:test_texture.py
示例19: __call__
def __call__(self):
global res
check = 1
print str(self.i+1)+' of '+str(self.rows_w)
for j in range(0,self.cols_w):
data_glcm_1 = self.band_list_q[0][self.i:self.i+self.window_dimension,j:j+self.window_dimension] #extract the data for the glcm
data_glcm_2 = self.band_list_q[1][self.i:self.i+self.window_dimension,j:j+self.window_dimension] #extract the data for the glcm
data_glcm_3 = self.band_list_q[2][self.i:self.i+self.window_dimension,j:j+self.window_dimension] #extract the data for the glcm
if (self.i+self.window_dimension<self.rows_w) and (j+self.window_dimension<self.cols_w):
glcm1 = greycomatrix(data_glcm_1, [1], [0, np.pi/4, np.pi/2, np.pi*(3/4)], levels=self.quantization_factor, symmetric=False, normed=True)
feat1 = greycoprops(glcm1, self.index)[0][0]
glcm2 = greycomatrix(data_glcm_2, [1], [0, np.pi/4, np.pi/2, np.pi*(3/4)], levels=self.quantization_factor, symmetric=False, normed=True)
feat2 = greycoprops(glcm2, self.index)[0][0]
glcm3 = greycomatrix(data_glcm_3, [1], [0, np.pi/4, np.pi/2, np.pi*(3/4)], levels=self.quantization_factor, symmetric=False, normed=True)
feat3 = greycoprops(glcm3, self.index)[0][0]
index_row = self.i+1
index_col = j+1
if (check):
res = []
check = 0
tmp1 = np.array([0,index_row,index_col,feat1])
tmp2 = np.array([1,index_row,index_col,feat2])
tmp3 = np.array([2,index_row,index_col,feat3])
res = np.append(res,tmp1)
res = np.append(res,tmp2)
res = np.append(res,tmp3)
'''
for b in range(0,len(self.input_band_list)):
data_glcm_1 = self.band_list_q[b][self.i:self.i+self.window_dimension,j:j+self.window_dimension] #extract the data for the glcm
if (self.i+self.window_dimension<self.rows_w) and (j+self.window_dimension<self.cols_w):
glcm1 = greycomatrix(data_glcm_1, [1], [0, np.pi/4, np.pi/2, np.pi*(3/4)], levels=self.quantization_factor, symmetric=False, normed=True)
feat1 = greycoprops(glcm1, self.index)[0][0]
index_row = self.i+1 #window moving step
index_col = j+1 #window moving step
#FIX IT NOOB
if (check):
res = []
check = 0
tmp = np.array([b,index_row,index_col,feat1])
res = np.append(res,tmp)
'''
if (check):
res = np.zeros(1)
return res
开发者ID:SENSUM-project,项目名称:sensum_rs,代码行数:44,代码来源:features.py
示例20: test_normed_symmetric
def test_normed_symmetric(self):
result = greycomatrix(self.image, [1, 2, 3],
[0, np.pi / 2, np.pi], 4,
normed=True, symmetric=True)
for d in range(result.shape[2]):
for a in range(result.shape[3]):
np.testing.assert_almost_equal(result[:, :, d, a].sum(),
1.0)
np.testing.assert_array_equal(result[:, :, d, a],
result[:, :, d, a].transpose())
开发者ID:TheArindham,项目名称:scikit-image,代码行数:10,代码来源:test_texture.py
注:本文中的skimage.feature.greycomatrix函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论