This project focuses on detecting defects in fruits using image processing and machine learning techniques. By automating the quality assessment process, this system identifies and classifies defects in fruit images.
-
Data Collection:
- Utilizes fruit images sourced from local mango orchards for training and testing.
- The dataset is organized in the
data
folder.
-
Image Preprocessing:
- Enhances image quality and prepares data for analysis.
- Preprocessing scripts are located in the
preprocessing
folder.
-
Feature Extraction:
- Extracts color and texture features from RGB and thermal images.
-
Classification Models:
- Implements traditional machine learning models, such as KNN, Random Forest (RF), Support Vector Machines (SVM), and Linear Discriminant Analysis (LDA).
- Incorporates Convolutional Neural Networks (CNN) for advanced defect detection.
-
Evaluation:
- Evaluates models using metrics such as accuracy, precision, recall, and F1-score.
- Languages & Libraries:
- Python
- OpenCV
- TensorFlow/Keras
- NumPy
- Pandas
Ensure you have the following installed:
- Python 3.x
- pip (Python package manager)
-
Clone the repository:
git clone https://github.com/susrithasabbini/fruit-defect-detection.git cd fruit-defect-detection
Use the following commands to extract features and save them to respective CSV files for RGB and thermal images:
-
GLCM Features Only
- RGB:
python glcm_RGB.py
- Thermal:
python glcm.py
- RGB:
-
Color Features Only
- RGB:
python colorFeatures_RGB.py
- Thermal:
python colorFeatures.py
- RGB:
-
Combined GLCM and Color Features
- RGB:
python glcmAndColor_RGB.py
- Thermal:
python glcmAndColor.py
- RGB:
-
Combined GLCM and Color Features with Histogram Equalization
- RGB:
python histogramGLCMAndColor_RGB.py
- Thermal:
python histogramGLCMAndColor.py
- RGB:
-
Combined GLCM and Color Features with OTSU Thresholding
- RGB:
python glcmAndColorOTSU_RGB.py
- Thermal:
python glcmAndColorOTSU.py
- RGB:
Once features are extracted and saved to CSV files (train_RGB.csv
, test_RGB.csv
, train.csv
, test.csv
), use the following commands to classify the images and save accuracy metrics to the results
folder:
-
Classification
- RGB:
python classification_RGB.py
- Thermal:
python classification.py
- RGB:
-
Confusion Matrix Display
- RGB:
python classificationConfusion_RGB.py
- Thermal:
python classificationConfusion.py
- RGB:
-
Classification using CNN
- RGB Images:
python CNN_RGB.py
- Thermal Images:
python CNN.py
Results, including accuracies, will be saved to the
results
folder. - RGB Images:
- Model performance metrics such as accuracy, precision, recall, and F1-score are saved in the
results
folder. - Confusion matrices for each classification run can be generated as needed.