Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to Python3 #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions alyn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" Import required modules"""
from deskew import *
from skew_detect import *
from .deskew import *
from .skew_detect import *
3 changes: 3 additions & 0 deletions alyn/__init__.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
""" Import required modules"""
from deskew import *
from skew_detect import *
2 changes: 1 addition & 1 deletion alyn/deskew.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import matplotlib.pyplot as plt

from skew_detect import SkewDetect
from .skew_detect import SkewDetect
from skimage import io
from skimage.transform import rotate

Expand Down
90 changes: 90 additions & 0 deletions alyn/deskew.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
""" Deskews file after getting skew angle """
import optparse
import numpy as np
import matplotlib.pyplot as plt

from skew_detect import SkewDetect
from skimage import io
from skimage.transform import rotate


class Deskew:

def __init__(self, input_file, display_image, output_file, r_angle):

self.input_file = input_file
self.display_image = display_image
self.output_file = output_file
self.r_angle = r_angle
self.skew_obj = SkewDetect(self.input_file)

def deskew(self):

img = io.imread(self.input_file)
res = self.skew_obj.process_single_file()
angle = res['Estimated Angle']

if angle >= 0 and angle <= 90:
rot_angle = angle - 90 + self.r_angle
if angle >= -45 and angle < 0:
rot_angle = angle - 90 + self.r_angle
if angle >= -90 and angle < -45:
rot_angle = 90 + angle + self.r_angle

rotated = rotate(img, rot_angle, resize=True)

if self.display_image:
self.display(rotated)

if self.output_file:
self.saveImage(rotated*255)

def saveImage(self, img):
path = self.skew_obj.check_path(self.output_file)
io.imsave(path, img.astype(np.uint8))

def display(self, img):

plt.imshow(img)
plt.show()

def run(self):

if self.input_file:
self.deskew()


if __name__ == '__main__':

parser = optparse.OptionParser()

parser.add_option(
'-i',
'--input',
default=None,
dest='input_file',
help='Input file name')
parser.add_option(
'-d', '--display',
default=None,
dest='display_image',
help="display the rotated image")
parser.add_option(
'-o', '--output',
default=None,
dest='output_file',
help='Output file name')
parser.add_option(
'-r', '--rotate',
default=0,
dest='r_angle',
help='Rotate the image to desired axis',
type=int)
options, args = parser.parse_args()
deskew_obj = Deskew(
options.input_file,
options.display_image,
options.output_file,
options.r_angle)

deskew_obj.run()
4 changes: 2 additions & 2 deletions alyn/skew_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def compare_sum(self, value):
def display(self, data):

for i in data:
print i + ": " + str(data[i])
print(i + ": " + str(data[i]))

def calculate_deviation(self, angle):

Expand All @@ -104,7 +104,7 @@ def run(self):
if self.batch_path:
self.batch_process()
else:
print "Invalid input, nothing to process."
print("Invalid input, nothing to process.")
else:
self.process_single_file()

Expand Down
Loading