Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Binary file added .github/img1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/img2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test.py
#enviroment
env
__pycache__
# images
images/*
enhanced/*
# building
guifinger.spec
build
dist
193 changes: 193 additions & 0 deletions GUI_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#! ./env/bin/python
import os
import subprocess
from os.path import join

import cv2
import tkinter as tk
from tkinter import *
from tkinter import ttk, filedialog

from main_enhancement import ROOT, IMG_FORMATS, SUFFIX, image_enhance_from

COLORS = {
'primary': '#1976D2',
'secondary': '#424242',
'accent': '#82B1FF',
'error': '#FF5252',
'info': '#2196F3',
'success': '#4CAF50',
'warning': '#FFC107'
}


class FingerprintImgEnhancer:
def __init__(self, master: Tk, title: str) -> None:
self.master = master
self.master.title(title)
# properties
self.inp_folder = 'images'
self.tar_folder = 'enhanced'
# labels
Label(
master=self.master,
text='Esta es una aplicacion para mejorar imagenes de huellas digitales').pack(pady=5)
Label(self.master, text='Imagenes seleccionadas').pack(pady=2)
# list box
self.dir_list_box = Listbox(self.master)
self.dir_list_box.pack(fill='x', padx=100)
# butons
self.select_dir_b = Button(
master=self.master,
text='Selecciona un directorio',
command=self.select_directory)
self.select_dir_b.pack(pady=5)
Button(
master=self.master,
text='Abrir carpeta destino',
command=self.open_enhance_dir
).pack(pady=5)
self.enhace_b = Button(
master=self.master,
text='Mejorar!',
command=self.start_enhance)
self.enhace_b.pack(fill=None, anchor="s",
side="left", padx=30, pady=30)
self.enhace_b['state'] = 'normal' if self.update_dir_list(
self.inp_folder) else 'disable'
self.exit_b = Button(
master=self.master,
bg=COLORS['error'],
text='Salir',
command=self.master.quit)
self.exit_b.pack(fill=None, anchor="s",
side="right", padx=30, pady=30)

def select_directory(self):
inp_folder = filedialog.askdirectory()
self.inp_folder = inp_folder if inp_folder else self.inp_folder
self.enhace_b['state'] = 'normal' if self.update_dir_list(
self.inp_folder) else 'disable'

def update_dir_list(self, inp_folder) -> bool:
self.files = [
filename for filename in os.listdir(inp_folder) if filename.split('.')[-1] in IMG_FORMATS]
self.dir_list_box.delete(0, 'end')
for i, filename in enumerate(self.files):
self.dir_list_box.insert(i+1, filename)
self.dir_list_box.update()
return bool(self.files)

def start_enhance(self):
dialog = EnhancerDialog(
self, self.master, 'Progress',
message='¿Desea mejorar estas imagenes?')
dialog.minsize(width=340, height=80)

def open_enhance_dir(self):
try:
subprocess.run(['open', 'enhanced'], check=True)
except Exception as e:
print(e)
try:
subprocess.run(['open', 'enhanced'], check=True)
except Exception as e:
print(e)


class EnhancerDialog(Toplevel):
def __init__(self, app: FingerprintImgEnhancer, master: Tk, title: str, message):
super().__init__(master)
# properties
self.app = app
self.title(title)
self.wm_attributes("-type", "dialog")
self.text = tk.StringVar()
self.text.set(message)
self.label = Label(self, textvariable=self.text)
self.label.pack(padx=10, pady=10)
# progress bar
self.progbar = ttk.Progressbar(
self, orient=HORIZONTAL, length=300, mode='determinate')
self.progbar.pack(pady=2)
# buttoms
self.frame = Frame(self)
self.frame.pack(side='bottom')
self.start_b = Button(
master=self.frame,
text='Iniciar',
bg=COLORS['primary'],
command=self.start)
self.start_b.pack(fill='y', anchor="s", side='left')
self.cancel_b = Button(
master=self.frame,
text='Cancel',
bg=COLORS['error'],
command=self.__cancel)
self.cancel_b.pack(fill='y', anchor="s", side='left')

def start(self):
self.__disable_buttoms()
self.master.update
self.update
step_size = 100 / len(self.app.files)
for img_name in self.app.files:
self.__update_dialog(img_name)
enhanced_img = image_enhance_from(
join(self.app.inp_folder, img_name))
enhanced_img_name = img_name.split('.')
enhanced_img_name = enhanced_img_name[0] + \
SUFFIX + enhanced_img_name[-1]
cv2.imwrite(join(self.app.tar_folder,
enhanced_img_name), enhanced_img)
self.__update_dialog(img_name)
self.progbar['value'] += step_size
self.__normal_buttoms()
self.text.set('Imagenes transformadas exitosamente.')
self.start_b.destroy()
self.cancel_b.destroy()
Button(
master=self.frame, text='Ok!',
command=self.destroy, padx=20
).pack(fill='y', anchor="s", side='left')
self.update()

def __disable_buttoms(self):
self.app.enhace_b['state'] = 'disable'
self.app.exit_b['state'] = 'disable'
self.app.select_dir_b['state'] = 'disable'
self.start_b['state'] = 'disable'
#self.cancel_b['state'] = 'disable'

def __normal_buttoms(self):
self.app.enhace_b['state'] = 'normal'
self.app.exit_b['state'] = 'normal'
self.app.select_dir_b['state'] = 'normal'
self.start_b['state'] = 'normal'
#self.cancel_b['state'] = 'normal'

def __update_dialog(self, img_name):
text_filename = f'{img_name[:10]}...' if len(
img_name) > 10 else img_name
self.text.set(f'Imagen: {text_filename:15} en progreso')
self.master.update()
self.update()

def __cancel(self):
self.__normal_buttoms()
self.update
self.master.update
self.destroy()


if __name__ == '__main__':
if not os.path.exists('images'):
os.mkdir('images')
if not os.path.exists('enhanced'):
os.mkdir('enhanced')
root = Tk()
root.minsize(width=600, height=440)
root.maxsize(width=600, height=440)
root.geometry('540x360')
feapp = FingerprintImgEnhancer(root, 'Fingerprint enhancer')
root.mainloop()
72 changes: 64 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,73 @@
# Fingerprint-Enhancement-Python

Using oriented gabor filters to enhance fingerprint images based on https://github.com/Utkarsh-Deshmukh/Fingerprint-Enhancement-Python
Using oriented gabor filters to enhance fingerprint images based on https://github.com/ylevalle/Fingerprint-Enhancement-Python

this version is written in python3

# Usage: python main_enhancement.py

The fingerprint image to enhance must be in the images directory, the default name is 1.jpg. The enhanced image will be located on the directory enhanced and the default name is enhanced.jpg
The images of the fingerprint for the enhancement must be in the "images" directory, the program will enhance all the images in that directory and they will be located in the "enhanced" directory with the same names and the suffix "_enhanced"

# Requirements
* [Python v3.9](https://www.python.org/downloads/release/python-398/)

## Installation of requirements

Execute installation.sh
```bash
./installation.sh
```

## Usage:
### Terminal
1. Copy your photos in png or jpg format to the images folder.
2. execute `execution` file:
```bash
./execution
```
Output:
```
Found 1 images in "images" folder
Processing images ...
Processing 1.jpg: (1/1)
All enhanced images saved in the "enhanced" folder.
done.
```
Results:
```
enhanced
└── 1_enhanced.jpg

0 directories, 1 file
```
### GUI
1. Execute `finger-print-enhancer-gui` file:
```bash
./finger-print-enhancer-gui
```
or
**Double click on this file**. Example:
![img1](.github/img1.png)
this window will appear
![img2](.github/img2.png)


This version doesn't work on Python 3 yet

# Requirements:

numpy
cv2
scipy
matplotlib
imageio
install [python](https://www.python.org/)

```r
numpy==1.21.2
opencv-python==4.5.3.56
scipy==1.7.1
```
Install it:
```sh
pip install -r requirements.txt
```
# Colaborators
* **Willy Samuel Paz Colque**
# Donations
If you want to help me be a better developer and continue collaborating in these projects, you can invite me a caffe, I would appreciate it. [Donate](https://paypal.me/WillyPaz95?country.x=UY&locale.x=es_XC)

Binary file added README.pdf
Binary file not shown.
Binary file removed enhanced/enhanced.jpg
Binary file not shown.
2 changes: 2 additions & 0 deletions execution
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#! /bin/bash
$(pwd)/main_enhancement.py
2 changes: 2 additions & 0 deletions finger-print-enhancer-gui
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#! /bin/bash
$(pwd)/GUI_main.py
Binary file added fpe-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/1.jpg
Binary file not shown.
23 changes: 23 additions & 0 deletions installation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /bin/bash
python3 -m venv env
source ./env/bin/activate
pip install -r requirements.txt
chmod +x ./main_enhancement.py

# creating desktop icon

rm fp-enhancer.desktop
touch fp-enhancer.desktop

chmod +x fp-enhancer.desktop

echo fp-enhancer.desktop fue creado, puede acceder a la aplicacion haciendo doble click en fp-enhancer.desktop
echo [Desktop Entry] >> fp-enhancer.desktop
echo Version=0.0.1 >> fp-enhancer.desktop
echo Name=FingerPrintEnhancer >> fp-enhancer.desktop
echo Comment=Interfaz grafica para el mejorador de huellas digitales >> fp-enhancer.desktop
echo Exec=$(pwd)/finger-print-enhancer-gui >> fp-enhancer.desktop
echo Icon=$(pwd)/fpe-icon.jpg >> fp-enhancer.desktop
echo Terminal=false >> fp-enhancer.desktop
echo Type=Application >> fp-enhancer.desktop
echo "Categories=Utility;Application;" >> fp-enhancer.desktop
59 changes: 59 additions & 0 deletions main_enhancement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#! ./env/bin/python3
import os
from os.path import abspath, dirname, join, exists

import cv2
import numpy as np
from numpy import ndarray as NumpyArray

from src import image_enhance

ROOT = abspath(dirname(__file__))
IMG_FORMATS = ['jpg', 'png', 'jpeg']
IMGS_PATH = join(ROOT, 'images')
ENHANCED_PATH = join(ROOT, 'enhanced')
SUFFIX = '_enhanced.'

def image_enhance_from(image_file:str):
img: NumpyArray = cv2.imread(image_file)
if(len(img.shape)>2):
img = np.dot(img[...,:3], [0.299, 0.587, 0.114])
rows, cols = img.shape
aspect_ratio = rows / cols
new_rows: int = 350
new_cols: int = int(new_rows / aspect_ratio)
img: NumpyArray = cv2.resize(img, (new_cols, new_rows))
enhanced_img: NumpyArray = image_enhance(img)
enhanced_img = ((1 - enhanced_img) * 255).astype(np.uint8)
return enhanced_img

def main():
image_names = os.listdir(IMGS_PATH)
image_names = list(filter(lambda fname: fname.split('.')
[-1] in IMG_FORMATS, image_names))

print(f'Found {len(image_names)} images in "images" folder')

print('Processing images ...')
images_processed = False
for i, img_name in enumerate(image_names):
enhanced_img_name = img_name.split('.')
enhanced_img_name = enhanced_img_name[0] + SUFFIX + enhanced_img_name[-1]
if exists(join(ENHANCED_PATH, enhanced_img_name)):
print(f'{img_name} is already processed: ({i+1}/{len(image_names)})')
continue # if an image exists its enhanced, nothing is done
images_processed = True
print(f'Processing {img_name}: ({i+1}/{len(image_names)})')
enhanced_img = image_enhance_from(join(IMGS_PATH, img_name))
cv2.imwrite(join(ENHANCED_PATH, enhanced_img_name), enhanced_img)

if images_processed:
print('\tAll enhanced images saved in the "enhanced" folder.')
else:
print('\tNo image was processed, it probably already exists')
print('\tits enhanced versions in the "enhanced" folder.')
print('done.')


if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy==1.21.2
opencv-python==4.5.3.56
scipy==1.7.1
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .image_enhance import image_enhance
Loading