Skip to content

Commit 6ee03ac

Browse files
Restructure project code and modules
1 parent 2665623 commit 6ee03ac

File tree

34,043 files changed

+175
-863
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

34,043 files changed

+175
-863
lines changed

classifier-elghalaba.ipynb

+1-28
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,7 @@
2323
"source": [
2424
"# Get paths of scaned and captured test cases #\n",
2525
"scanned_path = './test-cases/test-set-scanned/scanned'\n",
26-
"captured_path = './test-cases/test-set-camera-captured/captured'\n",
27-
"\n",
28-
"img_filenames = os.listdir(scanned_path)\n",
29-
"for i, fn in enumerate(img_filenames):\n",
30-
" test_number = fn.split('.')[0]"
31-
]
32-
},
33-
{
34-
"cell_type": "code",
35-
"execution_count": 3,
36-
"metadata": {},
37-
"outputs": [],
38-
"source": [
39-
"def preprocess_img(img_path, output_path):\n",
40-
" # 1. Read desired image #\n",
41-
" img = cv2.imread(img_path, 0)\n",
42-
" \n",
43-
" # 2. Remove noise (odd pixels) from the image and save it #\n",
44-
" img = cv2.fastNlMeansDenoising(img, None, 10, 7, 21)\n",
45-
" cv2.imwrite('testing-output/{}/1. noise_removed.png'.format(output_path), img)\n",
46-
"\n",
47-
" # 3. Binarize image using combination of (global + otsu) thresholding and save it #\n",
48-
" threshold, img = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)\n",
49-
" cv2.imwrite('testing-output/{}/2. binarized.png'.format(output_path), img)\n",
50-
"\n",
51-
" # 4. Return image shape (width, height) and processed image # \n",
52-
" n, m = img.shape\n",
53-
" return n, m, img"
26+
"captured_path = './test-cases/test-set-camera-captured/captured'"
5427
]
5528
},
5629
{

classifier.py

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import random
1111
from skimage.transform import rotate
1212
from sklearn.model_selection import train_test_split
13+
import pickle
14+
import matplotlib.pyplot as plt
1315

1416

1517
########## Variables ##########

dilated.png

-7.7 KB
Binary file not shown.

download.png

-6.39 KB
Binary file not shown.

helper_methods.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import cv2
33

4+
# List of maps and needed variables #
45
direct_labels = ['x', 'b', 'clef', 'dot', 'hash', 'd', 't_2', 't_4', 'symbol_bb', 'barline']
56
direct_texts = {'x':'##', 'b':'&', 'hash':'#', 'd':'', 'symbol_bb':'&&', 'dot':'.', 'clef':'', 't_2':'2', 't_4':'4', 'barline':''}
67

@@ -30,10 +31,7 @@ def clean_and_cut(img):
3031
img = 255 - img
3132
return img
3233

33-
3434
def get_a_character(distance, line_spacing, flipped = 0):
35-
# TODO: change it to chars array manipluation
36-
3735
if flipped and distance < 4.25 * line_spacing:
3836
return 'b1'
3937
if distance < flipped * (4.5 * line_spacing) + .25 * line_spacing:
@@ -50,7 +48,7 @@ def get_a_character(distance, line_spacing, flipped = 0):
5048
return 'a' + (1 - flipped) * '1' + (flipped) * '2'
5149
if distance < flipped * (4.5 * line_spacing) + 3.25 * line_spacing:
5250
return 'b2'
53-
return 'Adel_3abet'
51+
return 'b1'
5452

5553
def get_nxt(chord_type, char):
5654
pos = chords_order.find(char)
@@ -81,21 +79,14 @@ def get_a_chord(chord_type, distance, line_spacing, flipped = 0):
8179
return get_nxt(chord_type, 'a')
8280
if distance < 3.25 * line_spacing:
8381
return get_nxt(chord_type, 'b')
84-
return 'Hemdan_3abet'
82+
return get_nxt(chord_type, 'b')
8583

8684
def text_operation(label, ref_line, line_spacing, y1, y2):
8785
if label in direct_labels:
88-
if direct_texts[label] == None:
89-
print("LOL - 1")
90-
9186
return direct_texts[label]
9287

9388
if label.startswith('chord_'):
9489
distance = ref_line - y2
95-
96-
if get_a_chord(label, distance, line_spacing) == None:
97-
print("LOL - 2")
98-
9990
return get_a_chord(label, distance, line_spacing)
10091

10192
if not(label.endswith('flipped')):
@@ -104,19 +95,13 @@ def text_operation(label, ref_line, line_spacing, y1, y2):
10495
distance = ref_line - y2
10596
character = get_a_character(distance, line_spacing)
10697

107-
if f'{character}{direct_a[label]}' == None:
108-
print("LOL - 3")
109-
11098
return f'{character}{direct_a[label]}'
11199
else: # flipped
112100
distance = 0
113101
if label.startswith('a_'):
114102
distance = ref_line - y1
115103
character = get_a_character(distance, line_spacing, 1)
116104

117-
if character + direct_a[label] == None:
118-
print("LOL - 4")
119-
120105
return character + direct_a[label]
121106

122107
def cut_boundaries(cur_symbol, no_of_cuts, y2):
@@ -141,3 +126,17 @@ def cut_boundaries(cur_symbol, no_of_cuts, y2):
141126
cutted_boundaries.append(ret_boundary)
142127

143128
return cutted_boundaries
129+
130+
def preprocess_img(img_path):
131+
# 1. Read desired image #
132+
img = cv2.imread(img_path, 0)
133+
134+
# 2. Remove noise (odd pixels) from the image and save it #
135+
img = cv2.fastNlMeansDenoising(img, None, 10, 7, 21)
136+
137+
# 3. Binarize image using combination of (global + otsu) thresholding and save it #
138+
threshold, img = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
139+
140+
# 4. Return image shape (width, height) and processed image #
141+
n, m = img.shape
142+
return n, m, img
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)