-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode12.py
More file actions
104 lines (77 loc) · 3.1 KB
/
code12.py
File metadata and controls
104 lines (77 loc) · 3.1 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
"""
# Code 1:
# Author: Mahdi Kashani
# mahdi@uga.edu
# Title: Libraries and reading the .csv file provided by doctor Hopkinson from the original dataset.
# I can preprocess the whole csv file here and calculate width, height using the lambda function.
"""
# Libraries
# % import matplotlib inline # It's not necessary cause I use conda and not Jupyter Notebook here.
# ? https://matplotlib.org/3.1.1/api/patches_api.html
from matplotlib import patches
import matplotlib.pyplot as plt
import pandas as pd
from PIL import Image # http://effbot.org/imagingbook/introduction.html
# CSV_PATH = "./Data/Annotations/FL_Keys_Coral-export.csv"
CSV_PATH = "/Users/mac7/Desktop/MS_Project/validationDF.csv"
def makeDF(csv_path):
""" Read a comma-separated values (.csv) file into DataFrame.
Arg: csv PATH:
Return: new DF.
"""
DF = pd.read_csv(csv_path)
DF['height'] = DF.apply(lambda DF: abs(DF['ymax'] - DF['ymin']), axis=1)
DF['width'] = DF.apply(lambda DF: abs(DF['xmax'] - DF['xmin']), axis=1)
DF['objArea'] = DF.apply(lambda DF: (DF['width'] * DF['height']), axis=1)
imageArea = 2704 * 1524
DF['objPortion'] = DF.apply(lambda DF: (DF['objArea'] / imageArea), axis=1)
# DF.to_csv('/NewDF.csv')
DF.to_json('json_annot_all.json')
# Looking at the first 5 rows to get the insigt on the data.
print(DF.head(5))
print(DF.info())
return DF
DF = makeDF(csv_path=CSV_PATH) # Test.
"""
# Code 2:
# Author: Mahdi Kashani
# mahdi@uga.edu
# Title: # reading single image using imread function of matplotlib
"""
JPGPATH = './Data/vott-csv-export/JPGImages/'
def _sortedImages():
return pd.DataFrame(DF['image'].value_counts()).reset_index()['index'].to_numpy(dtype=list)
top_5_list = _sortedImages()[0:5]
top_5to10_list = _sortedImages()[5:10]
top_10to15_list = _sortedImages()[10:15]
# TODO: Reading a random image from the above directory or just reading the first image.
jpg1_str = '3D_L0215_161.jpg'
jpgfile = Image.open(str(JPGPATH)+str(jpg1_str)) # .convert('RGBA') Code4.py
# Printing the size, shape and the format of each image. (in bits, (width,length), jpeg/png/jpg ... ?
print(jpgfile.bits, '= bits ||', jpgfile.size,
'= shape ||', jpgfile.format, '= imageType')
# jpgfile.show()
# How many images do I have?
print(DF['image'].nunique())
# How many objects in each images exist?
print(DF['image'].value_counts())
print(top_10to15_list)
# How many classes do we have in label?
print(DF['label'].value_counts()[:])
# Visualization:
cn = ['red', 'green', 'blue', 'tan', 'magenta',
'black', 'white', 'cyan', 'yellow', 'teal']
plt.figure(figsize=(18, 8))
plt.title('Number of differet objects')
plt.xlabel('Classes')
plt.ylabel('Numbers')
# https://stackoverflow.com/questions/51058053/how-to-plot-a-histogram-of-one-column-colored-by-another-in-python
# Build a histogram for the same class breaks as earlier chart
n, bins, patches = plt.hist(DF['label'], bins=len(cn))
# Apply the same color for each class to match the map
idx = 0
for c, p in zip(bins, patches):
plt.setp(p, 'facecolor', cn[idx])
idx += 1
plt.show()
# FIXME: Histogram needed to be right in the middle.