|
|
@ -8,6 +8,8 @@ import argparse as ap
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import numpy as np
|
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
import cv2 as cv
|
|
|
|
|
|
|
|
|
|
|
|
# Import custom image filter library
|
|
|
|
# Import custom image filter library
|
|
|
|
import filters as flt
|
|
|
|
import filters as flt
|
|
|
@ -20,6 +22,7 @@ class apply_filters:
|
|
|
|
self.output_file = self.args.output_file
|
|
|
|
self.output_file = self.args.output_file
|
|
|
|
self.dpi = self.args.dpi # should be around 500-1000dpi
|
|
|
|
self.dpi = self.args.dpi # should be around 500-1000dpi
|
|
|
|
self.filters = self.args.filters
|
|
|
|
self.filters = self.args.filters
|
|
|
|
|
|
|
|
self.flip = self.args.flip
|
|
|
|
|
|
|
|
|
|
|
|
# Read input image, save its dimensions
|
|
|
|
# Read input image, save its dimensions
|
|
|
|
self.img = plt.imread(self.input_file)
|
|
|
|
self.img = plt.imread(self.input_file)
|
|
|
@ -33,13 +36,18 @@ class apply_filters:
|
|
|
|
self.apply_filter()
|
|
|
|
self.apply_filter()
|
|
|
|
|
|
|
|
|
|
|
|
def parse_arguments(self):
|
|
|
|
def parse_arguments(self):
|
|
|
|
parser = ap.ArgumentParser(prog = 'main.py', description = 'loads and stores image')
|
|
|
|
parser = ap.ArgumentParser(prog = 'main.py', description = 'Program for processing a 2D image into 3D fingerprint.')
|
|
|
|
parser.add_argument("-i", "--input_file", help = "Input file", required = True)
|
|
|
|
|
|
|
|
parser.add_argument("-o", "--output_file", help = "Output file", required = True)
|
|
|
|
# positional arguments
|
|
|
|
parser.add_argument('-d', "--dpi", type = int, required = True)
|
|
|
|
parser.add_argument("input_file", type = str, help = "Location with input file")
|
|
|
|
|
|
|
|
parser.add_argument("output_file", type = str, help = "Output file location")
|
|
|
|
|
|
|
|
parser.add_argument("dpi", type = int, help = "Scanner dpi")
|
|
|
|
|
|
|
|
parser.add_argument('-f', "--flip", help="Flip input image",
|
|
|
|
|
|
|
|
type = bool, action = ap.BooleanOptionalAction) # boolean switch
|
|
|
|
|
|
|
|
|
|
|
|
# file with default presets
|
|
|
|
# file with default presets
|
|
|
|
#parser.add_argument('-pf', "--preset_file")
|
|
|
|
parser.add_argument('-pf', "--preset_file", help = "File with presets")
|
|
|
|
parser.add_argument('filters', type = str, nargs = '*')
|
|
|
|
parser.add_argument('filters', type = str, nargs = '*', help = "List of filter names")
|
|
|
|
self.args = parser.parse_args()
|
|
|
|
self.args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def convert_dpi(self):
|
|
|
|
def convert_dpi(self):
|
|
|
@ -59,12 +67,15 @@ class apply_filters:
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
raise ValueError("Invalid filter name")
|
|
|
|
raise ValueError("Invalid filter name")
|
|
|
|
|
|
|
|
|
|
|
|
def resize_img(self):
|
|
|
|
def process_image(self):
|
|
|
|
# resize img to the new width
|
|
|
|
# resize img to the new width
|
|
|
|
if(False):
|
|
|
|
# flip image when mirroring is needed
|
|
|
|
print('')
|
|
|
|
if self.flip:
|
|
|
|
|
|
|
|
print("Flipping image")
|
|
|
|
|
|
|
|
self.img = cv.flip(self.img, 1)
|
|
|
|
|
|
|
|
|
|
|
|
def apply_filter(self):
|
|
|
|
def apply_filter(self):
|
|
|
|
|
|
|
|
self.process_image()
|
|
|
|
if len(self.filters) == 0:
|
|
|
|
if len(self.filters) == 0:
|
|
|
|
# save original image
|
|
|
|
# save original image
|
|
|
|
filter = flt.filter_none
|
|
|
|
filter = flt.filter_none
|
|
|
@ -78,7 +89,6 @@ class apply_filters:
|
|
|
|
def print_debug(self, dimensions):
|
|
|
|
def print_debug(self, dimensions):
|
|
|
|
print("Height: " + str(dimensions[0]))
|
|
|
|
print("Height: " + str(dimensions[0]))
|
|
|
|
print("Width: " + str(dimensions[1]))
|
|
|
|
print("Width: " + str(dimensions[1]))
|
|
|
|
#print("Channels: " + str(dimensions[2]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_image(self):
|
|
|
|
def save_image(self):
|
|
|
|
''' Save processed image. '''
|
|
|
|
''' Save processed image. '''
|
|
|
|