Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kidney Stone Detection Model (Image Classification)

WARNING: THIS PROJECT IS NOT YET COMPLETED AND COULD HAVE ERRORS.

Project Overview

This project implements a Convolutional Neural Network (CNN) for binary image classification, aiming to determine whether a given medical image contains kidney stones. The system is designed to preprocess images, prepare them for the deep learning model, and then use the trained model to make predictions.

Key Features

  • Automated Preprocessing: Includes a function to prepare raw images by performing:
    • Black border cropping.
    • Proportional scaling.
    • Squaring with padding to ensure all images have a uniform square size without distortion.
    • Grayscale conversion.
  • CNN Classification Model: A deep neural network trained to classify images as "Stone" (containing a stone) or "NoStone" (no stone).
  • Data Augmentation: Utilizes ImageDataGenerator during training to apply random transformations to images, helping the model generalize better and prevent overfitting.
  • Pixel Normalization: Images are automatically normalized to the 0−1 range before being fed into the model.
  • Model Saving and Loading: Allows saving the trained model for future inference.
  • Simple Inference: Includes a script to load the model and predict the class of new images.

Core Scripts

  1. preprocess_and_save_all_images.py
  • Function: Preprocesses all images from your_original_dataset/ and saves them into processed_kidney_stone_dataset/.
  • Configuration:
    • SOURCE_DATA_DIR: Path to your original dataset.
    • DEST_DATA_DIR: Path where processed images will be saved.
    • scalar: Initial scaling factor.
    • TARGET_SQUARE_DIM: Final (square) dimension of the processed images (e.g., 96, 128).
  • Execution:
    • Bash : python preprocess_and_save_all_images.py
  • Output: Processed images ready for training and an indication of the TARGET_SQUARE_DIM used.
  1. train_model_with_image_datagen.py
  • Function: Trains the CNN model using the preprocessed images and ImageDataGenerator for data augmentation and normalization.
  • Configuration:
    • PREPROCESSED_DATA_DIR: Path to the folder with processed images.
    • TARGET_DIM: Automatically detected by reading the size of the first image in PREPROCESSED_DATA_DIR.
    • BATCH_SIZE, EPOCHS, VALIDATION_SPLIT: Training parameters.
  • Execution:
    • Bash : python train_model_with_image_datagen.py
  • Output: Displays training progress, accuracy/loss plots, and saves the trained model as renal_calculus_detection_model.h5.
  1. predict_calculus.py
  • Function: Loads the trained model and makes a prediction on a new image.
  • Configuration:
    • MODEL_PATH: Path to the trained model.
    • IMAGE_TO_PREDICT_PATH: Path to the new image (original or unprocessed) you want to classify.
    • TARGET_DIM: Must be the same size used for model training.
    • Includes a copy of the preprocessing function to prepare the input image in the exact same way as the training images.
  • Execution:
    • Bash : python predict_calculus.py
  • Output: Displays the predicted probability and class ('Stone' or 'NoStone'), along with the image and its result.

Requirements

  • Python 3.x
  • TensorFlow / Keras
  • NumPy
  • Pillow (PIL)
  • OpenCV (cv2)
  • Matplotlib (for visualization)

Getting Started

1.- Organize Your Dataset: Place your original kidney stone images into the expected folder structure (your_original_dataset/Stone/ and your_original_dataset/NoStone/).

2.- Update Paths: Open preprocess_and_save_all_images.py, train_model_with_image_datagen.py, and predict_calculus.py. Update the path variables (SOURCE_DATA_DIR, DEST_DATA_DIR, PREPROCESSED_DATA_DIR, MODEL_PATH, IMAGE_TO_PREDICT_PATH) to match your setup.

3.- Preprocessing: Run preprocess_and_save_all_images.py. This will create the prepared images.

4.- Training: Run train_model_with_image_datagen.py. The model will train and save.

5.- Prediction: Run predict_calculus.py to test your model with new images.

About

This project uses CNNs to classify medical images, detecting kidney stones. It streamlines detection through image preprocessing and model training, aiming for an efficient diagnostic aid.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages