Video Explaination of the Project : YouTube Link
The provided code implements a signature forgery detection system using a neural network. The system processes signature images, extracts various features from them, and then trains a neural network to distinguish between genuine and forged signatures. The features include ratio, centroid, eccentricity, solidity, skewness, and kurtosis.
numpy: For numerical operations.os: For interacting with the operating system (file paths, folder creation).matplotlib: For image visualization.scipy.ndimage: For image processing operations.skimage.measure.regionprops: For extracting region properties from binary images.skimage.io: For reading images.skimage.filters.threshold_otsu: For thresholding images.tensorflow: For creating and training neural networks.pandas: For handling CSV files.
-
rgbgrey(img)- Converts RGB images to grayscale.
-
greybin(img)- Converts grayscale images to binary using Otsu's thresholding.
-
preproc(path, img=None, display=True)- Preprocesses the signature image by converting it to grayscale, binary, and extracting the signature part using a bounding box.
-
Ratio(img)- Computes the ratio of white pixels to the total number of pixels in the binary image.
-
Centroid(img)- Computes the centroid (center of mass) of the white pixels in the binary image.
-
EccentricitySolidity(img)- Computes the eccentricity and solidity of the signature using region properties.
-
SkewKurtosis(img)- Computes the skewness and kurtosis of the signature.
-
getFeatures(path, img=None, display=False)- Extracts various features from the signature image using the above functions.
-
getCSVFeatures(path, img=None, display=False)- Extracts features and formats them for saving to a CSV file.
-
makeCSV()- Creates CSV files for training and testing data, containing features and corresponding labels (genuine or forged).
-
testing(path)- Creates a CSV file for a test image containing its features.
-
readCSV(train_path, test_path, type2=False)- Reads data from CSV files, returning training and testing data.
-
multilayer_perceptron(x)- Defines the structure of the neural network model.
-
evaluate(train_path, test_path, type2=False)- Trains the neural network and evaluates its performance on training and testing data.
-
trainAndTest(rate=0.001, epochs=1700, neurons=7, display=False)- Trains and tests the model with specified hyperparameters and returns average accuracy.
-
Image Preprocessing:
- Convert RGB image to grayscale.
- Convert grayscale image to binary using Otsu's thresholding.
- Extract the signature part using a bounding box.
-
Feature Extraction:
- Extract various features such as ratio, centroid, eccentricity, solidity, skewness, and kurtosis from the preprocessed image.
-
Data Preparation:
- Create CSV files for training and testing data, including features and labels.
-
Neural Network Training:
- Train a neural network using the extracted features as input and labels as output.
-
Evaluation:
- Evaluate the trained model on both training and testing datasets.
-
Training Data Preparation:
- Images of genuine and forged signatures are stored in the "real" and "forged" folders, respectively.
- Running
makeCSV()will create CSV files with features and labels for training and testing.
-
Model Training and Evaluation:
- Run
trainAndTest()to train and evaluate the model with specified hyperparameters. - The function outputs average training accuracy, testing accuracy, and time taken for evaluation.
- Run
-
Testing a Single Image:
- Run
testing(path)to create a CSV file with features for a single test image.
- Run
-
Customization:
- The neural network architecture and hyperparameters can be adjusted in the code for experimentation.
-
Note:
- The code uses TensorFlow v1, as indicated by
tf.compat.v1. Consider updating to the latest TensorFlow version if necessary.
- The code uses TensorFlow v1, as indicated by
# Set genuine and forged image paths
genuine_image_paths = "real"
forged_image_paths = "forged"
# Create CSV files for training and testing
makeCSV()
# Provide training person's id and test image path
train_person_id = input("Enter person's id : ")
test_image_path = input("Enter path of signature image : ")
# Set paths for training and testing CSV files
train_path = 'Features/Training/training_' + train_person_id + '.csv'
testing(test_image_path)
test_path = 'TestFeatures/testcsv.csv'
# Evaluate the trained model
train_accuracy, test_accuracy, evaluation_time = trainAndTest()
print("Training Accuracy:", train_accuracy)
print("Testing Accuracy:", test_accuracy)
print("Time taken for evaluation:", evaluation_time)This documentation provides an overview of the signature forgery detection system, including its code structure, functions, workflow, and example usage. Users can utilize this system for signature forgery detection with customization options for neural network hyperparameters.