How to use the mahotas.features.haralick function in mahotas

To help you get started, we’ve selected a few mahotas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollos / opencv-practice / haralick_texture / classify_texture.py View on Github external
data.append(features)
	labels.append(texture)

# train the classifier
print "[INFO] training model..."
model = LinearSVC(C=10.0, random_state=42)
model.fit(data, labels)
print "[INFO] classifying..."

# loop over the test images
for imagePath in glob.glob(args["test"] + "/*.png"):
	# load the image, convert it to grayscale, and extract Haralick
	# texture from the test image
	image = cv2.imread(imagePath)
	gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
	features = mahotas.features.haralick(gray).mean(axis=0)

	# classify the test image
	pred = model.predict(features.reshape(1, -1))[0]
	cv2.putText(image, pred, (20, 30), cv2.FONT_HERSHEY_SIMPLEX, 1.0,
		(0, 255, 0), 3)

	# show the output image
	cv2.imshow("Image", image)
	cv2.waitKey(0)
github apollos / opencv-practice / haralick_texture / classify_texture.py View on Github external
# initialize the data matrix and the list of labels
print "[INFO] extracting features..."
data = []
labels = []

# loop over the dataset of images
for imagePath in glob.glob(args["training"] + "/*.png"):
	# load the image, convert it to grayscale, and extract the texture
	# name from the filename
	image = cv2.imread(imagePath)
	image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
	texture = imagePath[imagePath.rfind("/") + 1:].split("_")[0]

	# extract Haralick texture features in 4 directions, then take the
	# mean of each direction
	features = mahotas.features.haralick(image).mean(axis=0)

	# update the data and labels
	data.append(features)
	labels.append(texture)

# train the classifier
print "[INFO] training model..."
model = LinearSVC(C=10.0, random_state=42)
model.fit(data, labels)
print "[INFO] classifying..."

# loop over the test images
for imagePath in glob.glob(args["test"] + "/*.png"):
	# load the image, convert it to grayscale, and extract Haralick
	# texture from the test image
	image = cv2.imread(imagePath)
github luispedro / BuildingMachineLearningSystemsWithPython / ch10 / features.py View on Github external
def texture(im):
    '''Compute features for an image

    Parameters
    ----------
    im : ndarray

    Returns
    -------
    fs : ndarray
        1-D array of features
    '''
    im = im.astype(np.uint8)
    return mh.features.haralick(im).ravel()
github luispedro / BuildingMachineLearningSystemsWithPython / ch10 / large_classification.py View on Github external
def features_for(im):
    from features import chist
    im = mh.imread(im)
    img = mh.colors.rgb2grey(im).astype(np.uint8)
    return np.concatenate([mh.features.haralick(img).ravel(),
                                chist(im)])