Skip to content

Commit 84937a1

Browse files
committed
files added
0 parents  commit 84937a1

File tree

7,979 files changed

+1939074
-0
lines changed

Some content is hidden

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

7,979 files changed

+1939074
-0
lines changed

ECE 558 FINAL PROJECT REPORT.docx

3.5 MB
Binary file not shown.

ECE 558 FINAL PROJECT REPORT.pdf

1.06 MB
Binary file not shown.

Project03-Final-Fall22.pdf

5.57 MB
Binary file not shown.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"# blob-detector"

ResultImages/blobs_butterfly.png

409 KB
Loading

ResultImages/blobs_earth.png

2.07 MB
Loading

ResultImages/blobs_einstein.png

544 KB
Loading

ResultImages/blobs_fishes.png

294 KB
Loading

ResultImages/blobs_lena.png

415 KB
Loading

ResultImages/blobs_naruto.png

2.33 MB
Loading

ResultImages/blobs_road.png

990 KB
Loading

ResultImages/blobs_sunflowers.png

273 KB
Loading

ResultImages/blobs_tiger.png

524 KB
Loading

TestImages4Project/butterfly.jpg

134 KB
Loading

TestImages4Project/einstein.jpg

92.1 KB
Loading

TestImages4Project/fishes.jpg

39.9 KB
Loading

TestImages4Project/own_earth.png

1.97 MB
Loading

TestImages4Project/own_lena.png

334 KB
Loading

TestImages4Project/own_naruto.jpg

145 KB
Loading

TestImages4Project/own_road.jpeg

133 KB
Loading

TestImages4Project/own_tiger.jpg

78.9 KB
Loading

TestImages4Project/sunflowers.jpg

141 KB
Loading
3.51 KB
Binary file not shown.
3.51 KB
Binary file not shown.

__pycache__/main.cpython-38.pyc

6.1 KB
Binary file not shown.

convolution.py

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Function to implement the Convolution of the Image with 4 types of padding and kernels as required.
2+
import numpy as np
3+
import pandas as pd
4+
import cv2
5+
import matplotlib.pyplot as plt
6+
import math
7+
8+
# Padding Function
9+
def add_padding(f: np.array,wr: int,wc: int, pad: int) -> np.array:
10+
"""
11+
Adds padding to the Input Matrix
12+
Args:
13+
1) Input Image -> f
14+
2) Kernel Size -> w
15+
3) Padding type -> 0 for clip/zero-padding (Default)
16+
1 for wrap padding
17+
2 for copy edge
18+
3 for reflect across edge
19+
Returns:
20+
Padded Matrix (np.array)
21+
"""
22+
fr = f.shape[0]
23+
fc = f.shape[1]
24+
#Padding around the edges according to size of Kernel
25+
topmost= int(math.ceil((wr-1)/2))
26+
downmost = int(math.floor((wr-1)/2))
27+
leftmost = int(math.ceil((wc-1)/2))
28+
rightmost = int(math.floor((wc-1)/2))
29+
30+
#Zero Padding
31+
extended_padding = (fr + topmost + downmost, fc + leftmost + rightmost)
32+
padded_image = np.zeros(extended_padding)
33+
#Fitting original image into zero padded matrix
34+
padded_image[topmost : topmost + fr, leftmost : leftmost + fc] = f
35+
36+
#Warp
37+
if pad == 1:
38+
if topmost != 0:
39+
padded_image[0:topmost,:]=padded_image[-1*(topmost + downmost):topmost+f.shape[0],:]
40+
if downmost != 0:
41+
padded_image[-1*(downmost) : , : ] = padded_image[topmost : topmost + downmost, :]
42+
if rightmost != 0:
43+
padded_image[ : ,-1*(rightmost) : ] = padded_image[ : ,leftmost : leftmost + rightmost]
44+
if leftmost != 0:
45+
padded_image[ : ,0 : leftmost] = padded_image[ : ,-1*(leftmost+rightmost) : leftmost + f.shape[1]]
46+
47+
#Copy Edge
48+
elif pad == 2:
49+
if topmost != 0:
50+
padded_image[0 : topmost, : ] = padded_image[[topmost], : ]
51+
if downmost != 0:
52+
padded_image[-1*(downmost): , : ] = padded_image[[-1*downmost-1], :]
53+
if rightmost != 0:
54+
padded_image[ : ,-1*(rightmost) : ] = padded_image[ : ,[-1*(rightmost)-1]]
55+
if leftmost != 0:
56+
padded_image[ : ,0 : leftmost] = padded_image[ : ,[leftmost]]
57+
#
58+
elif pad == 3:
59+
if topmost != 0:
60+
padded_image[0 : topmost, : ] = np.flip(padded_image[topmost : 2*topmost, :],axis = 0)
61+
if downmost != 0:
62+
padded_image[-1*(downmost) : , : ] = np.flip(padded_image[-2*(downmost) : -1*(downmost), : ], axis = 0)
63+
if rightmost != 0:
64+
padded_image[ : ,-1*(rightmost) : ] = np.flip(padded_image[ : , -2*(rightmost) : -1*(rightmost)], axis = 1)
65+
if leftmost != 0:
66+
padded_image[ : ,0 : leftmost] = np.flip(padded_image[ : ,leftmost : 2* leftmost],axis = 1)
67+
68+
return padded_image
69+
70+
71+
# Convolution Function
72+
def conv2(f: np.array,w: np.array,pad: int) -> np.ndarray:
73+
"""
74+
Adds padding to the Input Matrix
75+
Args:
76+
1) Input Image -> f
77+
2) Kernel -> w
78+
3) Padding type -> 0 for clip/zero-padding (Default)
79+
1 for wrap padding
80+
2 for copy edge
81+
3 for reflect across edge
82+
Returns:
83+
Convoluted Image (np.array)
84+
85+
Gray Image is a two component Image. In case of three component images i.e. RGB, we need to split each component
86+
and apply convolution seperately. Once the convolution is applied, we will merge the components together and return
87+
the convoluted RGB image.
88+
"""
89+
# FOR GRAY IMAGES
90+
if len(f.shape) < 3:
91+
f_padded = add_padding(f,w.shape[0],w.shape[1], pad)
92+
convolved_matrix = np.zeros((f.shape[0], f.shape[1]))
93+
for r in range(convolved_matrix.shape[0]):
94+
for c in range(convolved_matrix.shape[1]):
95+
convolved_matrix[r][c]= np.sum(np.multiply(f_padded[r:r+w.shape[0],c:c+w.shape[1]],w))
96+
97+
# FOR RGB IMAGES
98+
elif len(f.shape) == 3:
99+
100+
b,g,r = cv2.split(f)
101+
102+
fb_padded = add_padding(b, w.shape[0], w.shape[1], pad)
103+
fg_padded = add_padding(g, w.shape[0], w.shape[1], pad)
104+
fr_padded = add_padding(r, w.shape[0], w.shape[1], pad)
105+
106+
convolved_bmatrix = np.zeros((b.shape[0],b.shape[1]))
107+
convolved_gmatrix = np.zeros((g.shape[0],g.shape[1]))
108+
convolved_rmatrix = np.zeros((r.shape[0],r.shape[1]))
109+
110+
for r in range(convolved_bmatrix.shape[0]):
111+
112+
for c in range(convolved_bmatrix.shape[1]):
113+
convolved_bmatrix[r][c]= np.sum(np.multiply(fb_padded[r:r+w.shape[0],c:c+w.shape[1]],w))
114+
convolved_gmatrix[r][c]= np.sum(np.multiply(fg_padded[r:r+w.shape[0],c:c+w.shape[1]],w))
115+
convolved_rmatrix[r][c]= np.sum(np.multiply(fr_padded[r:r+w.shape[0],c:c+w.shape[1]],w))
116+
117+
convolved_matrix = cv2.merge((convolved_bmatrix,convolved_gmatrix,convolved_rmatrix)).astype(np.uint8)
118+
else:
119+
print("\nInput out of bounds")
120+
121+
return convolved_matrix
+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#
2+
# The Python Imaging Library
3+
# $Id$
4+
#
5+
# bitmap distribution font (bdf) file parser
6+
#
7+
# history:
8+
# 1996-05-16 fl created (as bdf2pil)
9+
# 1997-08-25 fl converted to FontFile driver
10+
# 2001-05-25 fl removed bogus __init__ call
11+
# 2002-11-20 fl robustification (from Kevin Cazabon, Dmitry Vasiliev)
12+
# 2003-04-22 fl more robustification (from Graham Dumpleton)
13+
#
14+
# Copyright (c) 1997-2003 by Secret Labs AB.
15+
# Copyright (c) 1997-2003 by Fredrik Lundh.
16+
#
17+
# See the README file for information on usage and redistribution.
18+
#
19+
20+
"""
21+
Parse X Bitmap Distribution Format (BDF)
22+
"""
23+
24+
25+
from . import FontFile, Image
26+
27+
bdf_slant = {
28+
"R": "Roman",
29+
"I": "Italic",
30+
"O": "Oblique",
31+
"RI": "Reverse Italic",
32+
"RO": "Reverse Oblique",
33+
"OT": "Other",
34+
}
35+
36+
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}
37+
38+
39+
def bdf_char(f):
40+
# skip to STARTCHAR
41+
while True:
42+
s = f.readline()
43+
if not s:
44+
return None
45+
if s[:9] == b"STARTCHAR":
46+
break
47+
id = s[9:].strip().decode("ascii")
48+
49+
# load symbol properties
50+
props = {}
51+
while True:
52+
s = f.readline()
53+
if not s or s[:6] == b"BITMAP":
54+
break
55+
i = s.find(b" ")
56+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
57+
58+
# load bitmap
59+
bitmap = []
60+
while True:
61+
s = f.readline()
62+
if not s or s[:7] == b"ENDCHAR":
63+
break
64+
bitmap.append(s[:-1])
65+
bitmap = b"".join(bitmap)
66+
67+
[x, y, l, d] = [int(p) for p in props["BBX"].split()]
68+
[dx, dy] = [int(p) for p in props["DWIDTH"].split()]
69+
70+
bbox = (dx, dy), (l, -d - y, x + l, -d), (0, 0, x, y)
71+
72+
try:
73+
im = Image.frombytes("1", (x, y), bitmap, "hex", "1")
74+
except ValueError:
75+
# deal with zero-width characters
76+
im = Image.new("1", (x, y))
77+
78+
return id, int(props["ENCODING"]), bbox, im
79+
80+
81+
class BdfFontFile(FontFile.FontFile):
82+
"""Font file plugin for the X11 BDF format."""
83+
84+
def __init__(self, fp):
85+
super().__init__()
86+
87+
s = fp.readline()
88+
if s[:13] != b"STARTFONT 2.1":
89+
raise SyntaxError("not a valid BDF file")
90+
91+
props = {}
92+
comments = []
93+
94+
while True:
95+
s = fp.readline()
96+
if not s or s[:13] == b"ENDPROPERTIES":
97+
break
98+
i = s.find(b" ")
99+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
100+
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
101+
if s.find(b"LogicalFontDescription") < 0:
102+
comments.append(s[i + 1 : -1].decode("ascii"))
103+
104+
while True:
105+
c = bdf_char(fp)
106+
if not c:
107+
break
108+
id, ch, (xy, dst, src), im = c
109+
if 0 <= ch < len(self.glyph):
110+
self.glyph[ch] = xy, dst, src, im

0 commit comments

Comments
 (0)