0% found this document useful (0 votes)
9 views5 pages

20BCS3370

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

20BCS3370

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

Course Name: Computer Vision Lab Course Code: CSP-422

Experiment: 1

Aim:
Write a program to implement various feature extraction techniques for image
classification.

Software Required:
 PC/Laptop
 Jupyter Notebook
 Python 3 or above

Description:
There are several feature extraction techniques commonly used in image
classification tasks. These techniques aim to capture relevant information from
images and transform them into meaningful representations that can be used by
machine learning algorithms for classification. Some popular feature extraction
techniques are:
Histogram of Oriented Gradients (HOG): HOG computes the distribution of
gradient orientations in an image. It captures the shape and edge information
and has been particularly successful in object detection and pedestrian
recognition tasks.
Local Binary Patterns (LBP): LBP encodes the texture information by comparing
each pixel's intensity value with its neighbouring pixels. It is commonly used in
texture analysis tasks and has shown good performance in various image
classification applications.

Pseudo code/Algorithms/Flowchart/Steps:
1. Import necessary libraries
2. Load the dataset
3. Preprocess the images

Name: MEHUL UID: 20BCS3370


Course Name: Computer Vision Lab Course Code: CSP-422

4. Extract features using a specific technique


5. Split the dataset into training and testing sets
6. Train a classifier using the extracted features and labels
7. Evaluate the performance of the classifier on the testing set
8. Compare the performance of different techniques
9. Repeat steps 4-8 for other techniques
10. Document the observations and conclusions

Implementation:

import cv2 import numpy as np import


matplotlib.pyplot as plt from skimage import
feature, exposure from skimage.io import imread,
imshow image = cv2.imread('D:\\Chhota
Bheem.png') gray = cv2.cvtColor(image,
cv2.COLOR_BGR2GRAY) (H, hogImage) =
feature.hog(gray, orientations=9,
pixels_per_cell=(8, 8),
cells_per_block=(2, 2), transform_sqrt=True,
block_norm="L1",
visualize=True)
hogImage = exposure.rescale_intensity(hogImage,
out_range=(0, 255))
hogImage = hogImage.astype("uint8")
# Compute the local binary pattern (LBP) feature vector
radius = 3 n_points = 8 * radius
lbp = feature.local_binary_pattern(gray, n_points, radius,
method="uniform")

Name: MEHUL UID: 20BCS3370


Course Name: Computer Vision Lab Course Code: CSP-422

(hist, _) = np.histogram(lbp.ravel(), bins=np.arange(0, n_points +


3),
range=(0, n_points + 2)) #
Normalize the histogram hist
= hist.astype("float") hist /=
(hist.sum() + 1e-7) features =
np.hstack([H, hist])
print(features)

imshow(image)

image.shape

Name: MEHUL UID: 20BCS3370


Course Name: Computer Vision Lab Course Code: CSP-422

# Display the LBP image


plt.imshow(lbp, cmap='gray') plt.show()

Output:

Name: MEHUL UID: 20BCS3370


Course Name: Computer Vision Lab Course Code: CSP-422

Name: MEHUL UID: 20BCS3370

You might also like