-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database creator.py
65 lines (46 loc) · 1.43 KB
/
Database creator.py
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
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 19 11:04:32 2021
@author: tech crusaders
"""
import cv2 as cv
import os
import numpy as np
import csv
import matplotlib.pyplot as plt
import matplotlib.image as img
def rgb_histo(image):
histo= cv.calcHist([image],[0],None,[256],[0,256])
fv=np.array(histo)
for i in range(1,3):
histo= cv.calcHist([image],[i],None,[256],[0,256])
fv=np.append(fv,histo,0)
return fv
file="Images.csv"
def load_images_from_folder(folder):
images=[]
for filename in os.listdir(folder):
image = img.imread(os.path.join(folder,filename))
if image is not None:
images.append(image)
return images
folder='Task 2 Image Dataset'
images=load_images_from_folder(folder)
plt.imshow(images[0])
plt.show()
database="Database.csv"
def histo_data(folder):
for filename in os.listdir(folder):
image = cv.imread(os.path.join(folder,filename))
if image is not None:
fv=rgb_histo(image)
np.save(database,fv)
#histo_data(folder)
def csv_database(folder):
with open(database,'w') as csvfile:
for filename in os.listdir(folder):
image = img.imread(os.path.join(folder,filename))
fv=rgb_histo(image)
csvwriter = csv.writer(csvfile)
csvwriter.writerow(fv)
csv_database(folder)