started text filter
This commit is contained in:
commit
598c823d5d
3 files changed
+290
No files matched your search
@@ -0,0 +1,77 @@
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
FILENAME = "circle.png"
|
||||
|
||||
name, ext = FILENAME.split('.')
|
||||
|
||||
image = Image.open(FILENAME)
|
||||
|
||||
|
||||
|
||||
l_image = image.convert("L")
|
||||
|
||||
l_image.save(name + '-L.' + ext)
|
||||
|
||||
edges_image = l_image.filter(ImageFilter.FIND_EDGES)
|
||||
|
||||
edges_image.save(name + "-edges." + ext)
|
||||
|
||||
|
||||
# Get Edge Directions
|
||||
rgb_edge = edges_image.convert('RGB')
|
||||
w, h = rgb_edge.size
|
||||
|
||||
rgb_edge.save("rgb.png")
|
||||
|
||||
CHAR_PIXEL_SIZE = 8
|
||||
|
||||
edge_pixels = []
|
||||
y_count = 0
|
||||
for pixel_y in range(0, h):
|
||||
|
||||
x_count = 0
|
||||
for pixel_x in range(0, w):
|
||||
rgb = rgb_edge.getpixel((pixel_x, pixel_y))
|
||||
|
||||
print(rgb)
|
||||
|
||||
if rgb != (0, 0, 0):
|
||||
edge_pixels.append((pixel_x, pixel_y))
|
||||
|
||||
x_count += 1
|
||||
|
||||
if x_count >= CHAR_PIXEL_SIZE:
|
||||
break
|
||||
|
||||
y_count += 1
|
||||
if y_count >= CHAR_PIXEL_SIZE:
|
||||
x_count = 0
|
||||
y_count = 0
|
||||
|
||||
def calculate_slope(points: list[tuple]) -> int:
|
||||
count: int = len(points)
|
||||
|
||||
sumX = 0
|
||||
sumY = 0
|
||||
sumX2 = 0
|
||||
sumXY = 0
|
||||
for p in points:
|
||||
x = p[0]
|
||||
y = p[1]
|
||||
|
||||
sumX += x
|
||||
sumY += y
|
||||
sumX2 += x ** 2
|
||||
sumXY += x * y
|
||||
|
||||
meanX = sumX / count
|
||||
meanY = sumY / count
|
||||
|
||||
if (sumX2 - sumX * meanX) == 0:
|
||||
return 0
|
||||
|
||||
return (sumXY - sumX * meanY) / (sumX2 - sumX * meanX)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user