本文整理汇总了Python中skimage.feature.greycoprops函数的典型用法代码示例。如果您正苦于以下问题:Python greycoprops函数的具体用法?Python greycoprops怎么用?Python greycoprops使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了greycoprops函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: 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)
示例3: 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);
示例4: 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]
示例5: 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
示例6: 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
示例7: getSuperPixelTexture
def getSuperPixelTexture(superpixels, image):
texture = []
numSuperpixels = np.max(superpixels) + 1
greyImage = np.around(color.rgb2gray(image) * 255, 0)
for i in xrange(0,numSuperpixels):
indices = np.where(superpixels == i)
glcm = greycomatrix([greyImage[indices]], [5], [0], 256, symmetric=True, normed=True)
dissimilarity = greycoprops(glcm, 'dissimilarity')[0, 0]
correlation = greycoprops(glcm, 'correlation')[0, 0]
texture.append([dissimilarity, correlation])
return np.array(texture)
示例8: glcm_fe
def glcm_fe(f):
# 1 pixel, 6 pixesls, 20 pixels
grey = np.array(Image.open(f), 'uint8')
glcm = feature.greycomatrix(grey,[1,6,20],[np.pi])
cont = feature.greycoprops(glcm, 'contrast')
enrg = feature.greycoprops(glcm, 'energy')
hmgn = feature.greycoprops(glcm, 'homogeneity')
corr = feature.greycoprops(glcm, 'correlation')
for i in cont[:,0]: print i,
for i in enrg[:,0]: print "%.3f" % i,
for i in hmgn[:,0]: print "%.3f" % i,
for i in corr[:,0]:
if np.isnan(i): i = 1
print "%.6f" % i,
示例9: 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
示例10: plot_residuals
def plot_residuals():
numberOfImages = 12
residuals = []
featureList = np.zeros((numberOfImages, FEATURE_SIZE))
model = train()
# Get feautures
for i in range(1, numberOfImages):
# Load image
filename = "../Wheat_Images/{:03d}.jpg".format(i);
img = misc.imread(filename);
img_gray = img_as_ubyte(rgb2gray(img));
glcm = greycomatrix(img_gray, [5], [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])
featureList[i-1] = feature
# Apply model to data
predictions = model.predict(featureList)
# Compute residuals
for i in range(len(predictions)):
e = predictions[i] - COUNTS[i]
residuals.append(e)
# Plot residual graph
plt.figure(1)
plt.scatter(predictions, residuals, color='blue')
plt.axhline(0, color='black')
plt.xlabel('Predictions')
plt.ylabel('Residuals')
# Plot accuracy graph (ie predicted vs actual)
plt.figure(2)
plt.scatter(predictions, COUNTS, color='blue')
plt.plot(range(-500, 2500, 250), range(-500, 2500, 250), color='black', linestyle='dotted')
plt.xlim(xmin=0)
plt.ylim(ymin=0)
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.show()
示例11: 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
示例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
示例13: 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
示例14: train
def train():
'''
Builds linear regression from wheat images using GLCM properties.
Returns:
linear regression model
'''
if(Helper.unserialize(LIN_REGRESSION_MODEL_NAME) == None):
numberOfImages = 12;
# TODO: AUTOMATICALLY GET NUMBER OF IMAGES
# Get number of images. Remeber to divide by 2 as for every relevant image,
# theres also the comparison image.
# if ".DS_Store" in os.listdir("Wheat_ROIs"):
# numberOfImages = (len(os.listdir("Wheat_ROIs")) - 1)/2;
# else:
# numberOfImages = len(os.listdir("Wheat_ROIs"))/2;
featureList = np.zeros((numberOfImages, FEATURE_SIZE))
# For each ROI image in folder
for i in range(1, numberOfImages+1):
# Load image
filename = "../Wheat_Images/{:03d}.jpg".format(i);
img = misc.imread(filename);
img_gray = img_as_ubyte(rgb2gray(img));
glcm = greycomatrix(img_gray, [5], [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])
featureList[i-1] = feature
#print("{} = {}A + {}B + {}C + {}D".format(filename, dissimilarity, correlation, homogeneity, energy))
#print(feature)
# Build regression model
regression_model = linear_model.LinearRegression()
regression_model.fit(featureList, COUNTS[:numberOfImages])
Helper.serialize(LIN_REGRESSION_MODEL_NAME, regression_model)
print("COEFF: {}\nINTERCEPT: {}".format(regression_model.coef_, regression_model.intercept_))
print("SCORE: {}".format(regression_model.score(featureList, COUNTS[:numberOfImages])))
return regression_model
示例15: __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