forked from alymostafa1/ContentBasedRetrivalSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCBIR_Layout.py
More file actions
105 lines (73 loc) · 2.13 KB
/
CBIR_Layout.py
File metadata and controls
105 lines (73 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import cv2
import numpy as np
from CBIR_Hist import *
# from histogram import *
from CBIR_Layout import *
def sliceImage_Vect(Image_path,divisions):
'''
Original img
'''
img = cv2.imread(Image_path)
height = img.shape[0]
width = img.shape[1]
'''
Transforming into grey image
'''
d1, d2, d3= img.shape
# gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray_image = img
new_height = height/np.sqrt(divisions)
new_width = width/np.sqrt(divisions)
d1_1, d2_2, d3_3 = gray_image.shape
pre_img = np.split(gray_image, (d2_2/new_width))
img = []
for arr in pre_img:
img.extend(np.split(arr, arr.shape[1]/(new_width), axis=1))
# for i in range(len(img)):
# new_image_path = "DataSet\Images\Image" + str(i) + '.jpg'
# cv2.imwrite(new_image_path, img[i])
return img
def SliceImage_X_Vect(image_input,divisions):
'''
Original img
'''
# img = cv2.imread(Image_path)
img = image_input
height = img.shape[0]
width = img.shape[1]
h_2 = height/np.sqrt(divisions)
w_2 = width/np.sqrt(divisions)
_img =[]
#image cropping
i=0
x=0
y=0
for i in range(int(np.sqrt(divisions))):
y=0
for j in range(int(np.sqrt(divisions))):
image= img[ int(y): int(h_2+y), int(x) :int(w_2+x) , : ]
# cv2.imwrite("image"+ str(i) + str(j) + ".jpg",image)
y += h_2
_img.append(image)
x += w_2
return _img
'''
Test for Image Slicer
'''
# divisions= 16
# path="image.jpg"
# sliced_img = sliceImage(path,divisions)
'''
Test for Hist computation for sliced images
'''
def Slicer_hist(image_input,divisions):
Dict = {}
image_hist = []
images = SliceImage_X_Vect(image_input,divisions)
for image in images:
image_hist.append(hist_computation(image))
return image_hist
# divisions= 16
# path="DataSet\Images\image.jpg"
# image = cv2.imread(path)
# Image_Hists = Slicer_hist(image,divisions)