0% found this document useful (0 votes)
5 views6 pages

Texture Classification Using GLCM and ML

Uploaded by

harshit
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Texture Classification Using GLCM and ML

Uploaded by

harshit
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PRCV

PROJECT BASED LEARNING

Submitted in partial fulfillment of the requirements for the award of the degree of

BACHELOR OF TECHNOLOGY
In

COMPUTER SCIENCE & ENGINEERING


by

Harshit Agarwal(06811502721)

Objective:
Classify images based on texture patterns (e.g., distinguishing between a brick wall and sand texture).

Guided by
Gargi Mishra

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


BHARATI VIDYAPEETH’S COLLEGE OF ENGINEERING
(AFFILIATED TO GURU GOBIND SINGH INDRAPRASTHA UNIVERSITY, DELHI)
Introduction
Texture classification is a key area in image processing that focuses on identifying patterns and characteristics
in images, enabling machines to distinguish one texture from another. For this project, the goal is to classify
images based on texture patterns such as brick walls, sand, fabric, etc., using features extracted through the
Gray-Level Co-occurrence Matrix (GLCM). Texture classification can be applied in various fields, including
quality control in manufacturing, medical imaging, remote sensing, and more, where understanding surface
patterns is essential for interpreting visual data.

The Gray-Level Co-occurrence Matrix (GLCM) is a popular statistical method for texture analysis, particularly
because it captures the spatial relationship between pixel intensities in grayscale images. By analyzing these
relationships, we can derive texture properties like contrast, correlation, energy, and homogeneity, which
collectively describe the structural arrangement in an image. These properties offer a quantitative way to
distinguish between textures that may look similar at first glance but have underlying differences in pattern and
intensity. For example, the texture of a brick wall may exhibit high contrast and regularity, while sand might
have low contrast and more randomness.

Once we have extracted these texture features using GLCM, we can use them as inputs for a machine learning
classifier. In this project, we’ll use a Random Forest classifier, which is well-suited for this task due to its
robustness and ability to handle various feature types. The classifier will be trained on a dataset of labeled
images, where each label corresponds to a specific texture category. The model will learn patterns in these
extracted features that differentiate textures, allowing it to predict the texture class of new, unseen images.

For dataset preparation, we’ll organize images into folders, each representing a different texture class. The
image processing workflow involves converting each image to grayscale, calculating its GLCM, and then
extracting the relevant texture features. By feeding these features into our classifier, we aim to create a model
that accurately distinguishes between texture types. We’ll then evaluate the model using accuracy, precision,
recall, and F1 scores to assess its effectiveness in classifying textures on a held-out test set.

Ultimately, this project will provide practical experience in combining image processing with machine learning,
highlighting how GLCM-based feature extraction aids in interpreting texture patterns. It will also reinforce
skills in Python programming, utilizing libraries like scikit-image for feature extraction and scikit-learn for
classification. This integration of image analysis with predictive modeling is a valuable approach for anyone
looking to advance in fields such as computer vision or machine learning, where the ability to interpret and
classify visual data is essential.

Tools:
- Python: The primary language for coding.
- scikit-image: For GLCM and texture feature extraction.
- scikit-learn: For building and evaluating a machine learning classifier.
### **Step 1: Setup and Import Libraries**

### **Step 2: Texture Feature Extraction Using GLCM**

GLCM can be used to compute different texture properties, including contrast, correlation, energy, and homogeneity.
We’ll use these properties to characterize the textures in each image.

```python
def extract_glcm_features(image):
# Convert to grayscale
gray_image = [Link](image, cv2.COLOR_BGR2GRAY)

# Compute GLCM
glcm = greycomatrix(gray_image, distances=[1], angles=[0], symmetric=True, normed=True)

# Extract texture features


contrast = greycoprops(glcm, 'contrast')[0, 0]
correlation = greycoprops(glcm, 'correlation')[0, 0]
energy = greycoprops(glcm, 'energy')[0, 0]
homogeneity = greycoprops(glcm, 'homogeneity')[0, 0]

return [contrast, correlation, energy, homogeneity]


```

---

### **Step 3: Loading the Dataset**

You'll need a dataset with labeled images showing different textures (e.g., brick, sand). Organize images in folders where
each folder corresponds to a texture category.

```python
def load_dataset(dataset_path):
features = []
labels = []

for label in [Link](dataset_path):


label_path = [Link](dataset_path, label)

if [Link](label_path):
for img_file in [Link](label_path):
img_path = [Link](label_path, img_file)
image = [Link](img_path)

# Extract GLCM features


feature = extract_glcm_features(image)
[Link](feature)
[Link](label)

return [Link](features), [Link](labels)

# Example path
dataset_path = 'path/to/your/dataset'
X, y = load_dataset(dataset_path)
```

---

### **Step 4: Train-Test Split**

Split the dataset for training and testing the classifier.

```python
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
```

---

### **Step 5: Train the Classifier**

Using a Random Forest Classifier as an example, which generally performs well with GLCM features.

```python
# Initialize the classifier
classifier = RandomForestClassifier(n_estimators=100, random_state=42)

# Train the classifier


[Link](X_train, y_train)
```

---
### **Step 6: Evaluate the Classifier**

Check the classifier's performance on the test set.

```python
# Predict on the test set
y_pred = [Link](X_test)

# Print the accuracy and classification report


print("Accuracy:", accuracy_score(y_test, y_pred))
print("Classification Report:\n", classification_report(y_test, y_pred))
```

---

### **Step 7: Test with New Images**

To test the classifier on new images, use the same feature extraction function (`extract_glcm_features`) and feed it into the
classifier.

```python
def classify_image(image_path):
image = [Link](image_path)
features = [Link](extract_glcm_features(image)).reshape(1, -1)
prediction = [Link](features)
return prediction[0]

# Example usage
test_image_path = 'path/to/new/[Link]'
print("Predicted Texture:", classify_image(test_image_path))
```

---

### **Expected Output**

- **Accuracy**: Shows how well the classifier is performing on the test set.
- **Classification Report**: Includes precision, recall, and F1-score for each texture class.
- **Prediction on New Image**: Outputs the predicted texture category for a given input image.

---

### **Possible Extensions**

For further enhancement, consider:


- **Data Augmentation**: Apply transformations like rotation, scaling, or flipping to increase the dataset size.
- **Hyperparameter Tuning**: Use grid search or randomized search to optimize classifier parameters.
This project will give you hands-on experience with image processing, feature extraction, and machine learning,
specifically for texture classification! Let me know if you'd like further assistance with specific steps or code adjustments.

You might also like