Skip to content

Commit 14265db

Browse files
committed
Commented Image Search
1 parent 456e1d9 commit 14265db

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

FeatureVectors.py

+13
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66

77
class FeatureVectors():
8+
"""Extracts various feature vectors from image """
89

910
def __init__(self, image):
1011
self.filter = NoiseReduction(image)
1112
self.image = self.filter.applyGaussianBlur()
1213

1314
def __getMeanIntensity(self):
15+
# Returns the mean intensity of image
16+
1417
meanIntensity = []
1518
for channel in range(3):
1619
channel_mean = np.average(self.image[:, :, channel])
@@ -19,6 +22,8 @@ def __getMeanIntensity(self):
1922
return meanIntensity
2023

2124
def __getStdIntensity(self):
25+
# Returns the standard deviation of intensity of image
26+
2227
stdIntensity = []
2328
for channel in range(3):
2429
channel_std = np.std(self.image[:, :, channel])
@@ -27,6 +32,8 @@ def __getStdIntensity(self):
2732
return stdIntensity
2833

2934
def __getRGBHistogramVector(self):
35+
# Returns the 3-D(RGB) Histogram vector of image
36+
3037
histogram_3d = cv2.calcHist([self.image], [0, 1, 2], None,
3138
[12, 12, 12], [0, 256, 0, 256, 0, 256])
3239
histogram_3d = histogram_3d.ravel()
@@ -35,13 +42,19 @@ def __getRGBHistogramVector(self):
3542
return RGBHistogram
3643

3744
def __getHuMoments(self):
45+
# Returns Hu-Moments vector of image
46+
3847
filter = ConvolutionFilter(self.image)
3948
canny_filtered = filter.applyCannyEdge()
4049
canny_huMoments = cv2.HuMoments(cv2.moments(canny_filtered)).flatten()
4150
huVector = list(canny_huMoments.ravel())
4251
return huVector
4352

4453
def getFeatureVector(self):
54+
""" Return a python list of complete feature vectors
55+
Extracts Statistics, 3-D Histogram, HuMoments from image and appends into single list
56+
"""
57+
4558
featureVectors = []
4659
meanIntensity = self.__getMeanIntensity()
4760
stdIntensity = self.__getStdIntensity()

ImageSearch_Serial.py

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88

99
def extractFeatureVectors(image_path):
10+
# Extracts feature vectors for input image
11+
1012
image = cv2.imread(image_path)
1113
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
1214
image = cv2.resize(image, (500, 500))
@@ -18,6 +20,7 @@ def extractFeatureVectors(image_path):
1820

1921

2022
def ImageSearch(queryImage):
23+
# Performs Image Search using Query image
2124

2225
image_db_path = "Image_Database/"
2326
image_paths = []

ImageSearch_parallel.py

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
def extractFeatureVectors(image_path):
13+
# Extracts feature vectors for input image
1314

1415
image = cv2.imread(image_path)
1516
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
@@ -22,6 +23,8 @@ def extractFeatureVectors(image_path):
2223

2324

2425
def ThreadedFeatureExtraction(images_list):
26+
# Performing feature extraction of databse images using multithreading
27+
2528
features = {}
2629
with concurrent.futures.ThreadPoolExecutor() as executor:
2730
results = [executor.submit(extractFeatureVectors, image_path)
@@ -42,6 +45,7 @@ def getImg(img):
4245

4346

4447
def ImageSearch(queryImage):
48+
# Performs Image Search using Query image
4549

4650
image_db_path = "Image_Database/"
4751
image_paths = []

QuerySearch.py

+9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33

44
class QuerySearch:
5+
""" Searches similarity of query image vector with extracted vectors from database"""
56

67
def __init__(self, queryFeature, features):
78

89
self.features = features
910
self.queryFeature = queryFeature
1011

1112
def __cosine_similarity(self, queryVector, vector):
13+
# Computes cosine similarity between two vectors
14+
1215
eps = 1e-10
1316
dot_product = sum(q*v for q, v in zip(queryVector, vector))
1417

@@ -23,6 +26,8 @@ def __cosine_similarity(self, queryVector, vector):
2326
return cosine_similarity
2427

2528
def __chi2_distance(self, queryVector, vector):
29+
# Computes chi-square distance between two vectors
30+
2631
eps = 1e-10
2732
dists = [((q - v) ** 2) / (q + v + eps)
2833
for (q, v) in zip(queryVector, vector)]
@@ -31,11 +36,15 @@ def __chi2_distance(self, queryVector, vector):
3136
return chi2_distance
3237

3338
def __SAD_distance(self, queryVector, vector):
39+
# Computes SAD distance between two vectors
40+
3441
dists = [abs(q-v) for (q, v) in zip(queryVector, vector)]
3542
SAD_distance = sum(dists)
3643
return SAD_distance
3744

3845
def performSearch(self):
46+
# Return similarity indices of queryVector and databse images
47+
3948
searchSimilarityScores = []
4049

4150
for image in self.features:

0 commit comments

Comments
 (0)