8
main.py
8
main.py
@@ -1,6 +1,14 @@
|
||||
from utils.path import scanHorizontal, scanVertical, twoTooMany
|
||||
from utils.pbmformator import formatPbm
|
||||
from utils.savetofile import matrixToFile
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Usage example
|
||||
matrixToFile(formatPbm('resources/original/test1ascii.pbm'), 'resources/reformatted/test1.csv')
|
||||
|
||||
#matrixToFile(scanHorizontal(formatPbm('resources/original/test1ascii.pbm'), 4), 'resources/reformatted/testhori.csv')
|
||||
#matrixToFile(scanVertical(formatPbm('resources/original/test1ascii.pbm'), 4 ), 'resources/reformatted/testvert.csv')
|
||||
#matrixToFile(twoTooMany(scanVertical(scanHorizontal(formatPbm('resources/original/test1ascii.pbm'), 4),4),4), 'resources/reformatted/testfinal.csv')
|
||||
matrixToFile(twoTooMany(scanVertical(scanHorizontal(formatPbm('resources/original/imagestest-11.pbm'), 4),4),4), 'resources/reformatted/testimagestest-11.csv')
|
||||
matrixToFile(twoTooMany(scanVertical(scanHorizontal(formatPbm('resources/original/imagestest-22.pbm'), 4),4),4), 'resources/reformatted/testimagestest-22.csv')
|
||||
matrixToFile(twoTooMany(scanVertical(scanHorizontal(formatPbm('resources/original/imagestest-33.pbm'), 4),4),4), 'resources/reformatted/testimagestest-33.csv')
|
||||
|
||||
59
utils/path.py
Normal file
59
utils/path.py
Normal file
@@ -0,0 +1,59 @@
|
||||
def scanHorizontal(image, rTool):
|
||||
|
||||
width = len(image[0])
|
||||
height = len(image)
|
||||
|
||||
for line in range(height):
|
||||
for column in range(width):
|
||||
|
||||
if image[line][column] == 1 and image[line][ column - 1] == 0:
|
||||
for px in range(2 * rTool):
|
||||
if image[line - rTool + px][column - rTool] == 0:
|
||||
image[line - rTool + px][column - rTool] = 2
|
||||
|
||||
if image[line][column] == 1 and image[line][ column + 1] == 0:
|
||||
for px in range(2 * rTool):
|
||||
if image[line - rTool + px][column + rTool] == 0:
|
||||
image[line - rTool + px][column + rTool] = 2
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def scanVertical(image, rTool):
|
||||
|
||||
width = len(image[0])
|
||||
height = len(image)
|
||||
|
||||
for line in range(height):
|
||||
for column in range(width):
|
||||
|
||||
if image[line][column] == 1 and image[line - 1][ column] == 0:
|
||||
for px in range(2 * rTool):
|
||||
if image[line - rTool][column - rTool + px] == 0:
|
||||
image[line - rTool][column - rTool + px] = 2
|
||||
|
||||
elif image[line][column] == 1 and image[line + 1][column] == 0:
|
||||
for px in range(2 * rTool):
|
||||
if image[line + rTool][column - rTool + px] == 0:
|
||||
image[line + rTool][column - rTool + px] = 2
|
||||
|
||||
return image
|
||||
|
||||
def twoRemoving(image, rTool):
|
||||
|
||||
rTool -= 1
|
||||
width = len(image[0])
|
||||
height = len(image)
|
||||
|
||||
for line in range(height):
|
||||
for column in range(width):
|
||||
|
||||
if image[line][column] == 1:
|
||||
for px in range(2 * rTool + 1):
|
||||
if image[line - rTool + px][column] == 2:
|
||||
image[line - rTool + px][column] = 0
|
||||
if image[line][column - rTool + px] == 2:
|
||||
image[line][column - rTool + px] = 0
|
||||
|
||||
return image
|
||||
|
||||
Reference in New Issue
Block a user