diff --git a/Bone Fracture Detection/Web App/README.md b/Bone Fracture Detection/Web App/README.md new file mode 100644 index 000000000..c5c12f773 --- /dev/null +++ b/Bone Fracture Detection/Web App/README.md @@ -0,0 +1,58 @@ +# Bone Fracture Detection Web Application 💻 + +## Overview 🔍 + +This web application is designed to facilitate bone fracture detection using machine learning models. It provides an easy-to-use interface for users to upload X-ray images along with their name, and receive predictions on whether the image contains a bone fracture or not. Additionally, the application draws bounding boxes around detected fractures and provides information about the type of fracture detected. The application is built using Flask, a lightweight WSGI web application framework. + +## Features + +- **Upload X-ray Images**: Users can upload X-ray images of bone scans along with their name directly through the web interface. +- **Fracture Detection**: The uploaded images are processed using pre-trained machine learning models to detect fractures. +- **Bounding Box Visualization**: Detected fractures are highlighted with bounding boxes overlaid on the original X-ray image. +- **Fracture Type Information**: Users receive information about the type of fracture detected (e.g., transverse, oblique, comminuted). +- **User-Friendly Interface**: The web application features a simple and intuitive user interface for seamless interaction. + +## Installation + +To run the application locally, follow these steps: + +1. Clone this repository to your local machine. + ``` + git clone https://github.com/abhisheks008/DL-Simplified.git + ``` +2. Navigate to the project directory. + ``` + cd DL-Simplified/Bone\ Fracture\ Detection/Web App + ``` +3. Install the required dependencies. + ``` + pip install -r requirements.txt + ``` +4. Run the Flask application. + ``` + python3 app.py + ``` +5. Access the application in your web browser at `http://localhost:5000`. + +## Usage + +1. Open the web application in your browser. +2. Enter your name in the designated field. +3. Click on the "Choose File" button to upload an X-ray image and upload it. +5. Wait for the prediction result to appear on the screen, including the bounding box around detected fractures and information about the fracture type. +6. Return back to upload additional images or repeat the process as needed. + +## Sample Usage +[![Watch the video](https://img.youtube.com/vi/YNMzmSki_Xg/0.jpg)](https://www.youtube.com/watch?v=YNMzmSki_Xg) + +## Model Details + +The bone fracture detection models used in this application are trained on a dataset of X-ray images labeled with fracture and non-fracture classes. The models are implemented using deep learning techniques and are capable of accurately identifying fractures in bone scans. + +## Contributors + +`Bingumalla Likith | +GSSoC 24 Contributor| +Issue Number #650` + +[![LinkedIn](https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white)](www.linkedin.com/in/bingumalla-likith-2633392b9) [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/binguliki) diff --git a/Bone Fracture Detection/Web App/REC-20240528160557.mp4 b/Bone Fracture Detection/Web App/REC-20240528160557.mp4 new file mode 100644 index 000000000..9e365952d Binary files /dev/null and b/Bone Fracture Detection/Web App/REC-20240528160557.mp4 differ diff --git a/Bone Fracture Detection/Web App/Uploads/Sample1.jpg b/Bone Fracture Detection/Web App/Uploads/Sample1.jpg new file mode 100644 index 000000000..391e9ef5d Binary files /dev/null and b/Bone Fracture Detection/Web App/Uploads/Sample1.jpg differ diff --git a/Bone Fracture Detection/Web App/Uploads/Sample2.jpg b/Bone Fracture Detection/Web App/Uploads/Sample2.jpg new file mode 100644 index 000000000..886e9bdb0 Binary files /dev/null and b/Bone Fracture Detection/Web App/Uploads/Sample2.jpg differ diff --git a/Bone Fracture Detection/Web App/Uploads/Sample3.jpg b/Bone Fracture Detection/Web App/Uploads/Sample3.jpg new file mode 100644 index 000000000..d86b28c42 Binary files /dev/null and b/Bone Fracture Detection/Web App/Uploads/Sample3.jpg differ diff --git a/Bone Fracture Detection/Web App/app.py b/Bone Fracture Detection/Web App/app.py new file mode 100644 index 000000000..df327bcda --- /dev/null +++ b/Bone Fracture Detection/Web App/app.py @@ -0,0 +1,61 @@ +from flask import Flask , render_template , request , redirect , url_for , send_from_directory +import os +import cv2 +import json +from ultralytics import YOLO + +model = YOLO('best_model.pt') +app = Flask(__name__) +app.config['UPLOAD_FILES'] = 'Uploads/' + +@app.route("/" , methods = ['GET' , 'POST']) +def Home_page(): + if request.method == "GET": + return render_template('home.html') + else: + file = request.files['Input Image'] + path = os.path.join(app.config['UPLOAD_FILES'] , file.filename) + name = request.form['Name'] + with open('./static/Users.csv' , 'at') as docs: + docs.write(name + '\n') + file.save(path) + return redirect(url_for('prediction' , class_name = predict(path) , filename = file.filename)) + + +def predict(path): + img = cv2.imread(path) + results = model.predict(img) + try: + class_index = int(results[0].boxes.cls[0]) + class_name = results[0].names[class_index] + x , y , w , h = list(map(int ,results[0].boxes.xywh[0])) + + if class_name == "humerus": + class_name += " fracture" + + font = cv2.FONT_HERSHEY_SIMPLEX + font_scale = 0.7 + font_thickness = 2 + + cv2.rectangle(img, (x-w//2, y-h//2), ((x-w//2)+ w ,(y-h//2)+ h), (0, 0, 255),2) + cv2.putText(img , class_name , (x-w//2, y-h//2-5) , font , font_scale ,(0, 0, 255), font_thickness) + cv2.imwrite(path , img) + except IndexError: + return "No Fracture" + return class_name + +@app.route("/prediction//" , methods = ['GET']) +def prediction(class_name , filename): + with open('./static/data.json' , 'rt') as file: + data = json.load(file) + desc = data[class_name.title()]['Description'] + symptoms = data[class_name.title()]['Symptoms'] + + return render_template('result.html' , class_name = class_name , filename = filename , desc = desc , sympt = symptoms) + +@app.route('/serve_image/' , methods = ['GET']) +def serve_image(filename): + return send_from_directory(app.config['UPLOAD_FILES'] , filename) + +if __name__ == "__main__": + app.run(debug = True) \ No newline at end of file diff --git a/Bone Fracture Detection/Web App/best_model.pt b/Bone Fracture Detection/Web App/best_model.pt new file mode 100644 index 000000000..e40b8d407 Binary files /dev/null and b/Bone Fracture Detection/Web App/best_model.pt differ diff --git a/Bone Fracture Detection/Web App/requirements.txt b/Bone Fracture Detection/Web App/requirements.txt new file mode 100644 index 000000000..6878b5957 --- /dev/null +++ b/Bone Fracture Detection/Web App/requirements.txt @@ -0,0 +1,3 @@ +Flask==3.0.3 +opencv_python==4.9.0.80 +ultralytics==8.1.47 \ No newline at end of file diff --git a/Bone Fracture Detection/Web App/static/Users.csv b/Bone Fracture Detection/Web App/static/Users.csv new file mode 100644 index 000000000..631b39ebb --- /dev/null +++ b/Bone Fracture Detection/Web App/static/Users.csv @@ -0,0 +1,8 @@ +Name +Likith +Likth +sfgd +Bingumalla Likith +Bingumalla Likith +Likith - 2 +Divya diff --git a/Bone Fracture Detection/Web App/static/data.json b/Bone Fracture Detection/Web App/static/data.json new file mode 100644 index 000000000..68165f37c --- /dev/null +++ b/Bone Fracture Detection/Web App/static/data.json @@ -0,0 +1,31 @@ +{ + "Elbow Fracture": { + "Description": "An elbow fracture involves a break in one or more of the bones that constitute the elbow joint, such as the humerus, radius, or ulna. These fractures typically result from direct trauma, falls, or high-impact sports injuries.", + "Symptoms": "Significant pain, swelling, bruising, and restricted movement of the elbow. In severe cases, the joint may appear deformed." + }, + "Finger Fracture": { + "Description": "A finger fracture is a break in one of the bones of the fingers, known as the phalanges. These fractures commonly occur from direct impact, crushing injuries, or hyperextension.", + "Symptoms": "Pain, swelling, bruising, and difficulty moving the affected finger. In some cases, there may be visible deformity or shortening of the finger." + }, + "Forearm Fracture": { + "Description": "A forearm fracture involves a break in one or both of the forearm bones, the radius and ulna. Such fractures often result from falls, direct blows, or twisting injuries.", + "Symptoms": "Severe pain, swelling, bruising, limited range of motion, and possible deformity if the bones are displaced." + }, + "Humerus Fracture": { + "Description": "A humerus fracture is a break in the upper arm bone. It can occur at the proximal end near the shoulder, mid-shaft, or distal end near the elbow. These fractures are usually caused by falls, direct impacts, or high-energy trauma.", + "Symptoms": "Severe pain, swelling, bruising, inability to move the shoulder or elbow properly, and potential numbness if nerves are affected." + }, + "Shoulder Fracture": { + "Description": "A shoulder fracture typically refers to a break in the clavicle (collarbone), scapula (shoulder blade), or the proximal humerus. These fractures often result from falls, direct trauma, or sports injuries.", + "Symptoms": "Pain, swelling, and bruising around the shoulder, along with difficulty moving the arm. In some cases, there may be a visible deformity." + }, + "Wrist Fracture": { + "Description": "A wrist fracture is a break in one or more of the bones that form the wrist joint, primarily the radius and ulna, but it can also involve the carpal bones. These fractures commonly occur from falls onto an outstretched hand or direct impacts.", + "Symptoms": "Pain, swelling, tenderness, bruising, and difficulty moving the wrist or hand. In severe cases, a deformity may be visible." + }, + "No Fracture": { + "Description": "A fracture is a medical condition in which there is a break in the continuity of the bone. This can occur in any bone and can vary in severity, from a thin crack to a complete break that splits the bone into two or more pieces. Fractures commonly result from high-impact injuries such as falls, car accidents, or sports injuries, but can also occur from less severe trauma in individuals with weakened bones due to conditions like osteoporosis.", + "Symptoms": "Symptoms of a fracture typically include intense pain at the site of the break, which may worsen with movement. Swelling and bruising around the injured area are common, along with tenderness to touch. The affected limb or area may appear deformed or out of place, and there may be an inability to move the affected limb or bear weight on it. In some cases, a grating sensation or sound (crepitus) can be felt or heard when the broken bone ends rub together. In severe cases, such as open fractures, the bone may be visible through the skin." + } + } + \ No newline at end of file diff --git a/Bone Fracture Detection/Web App/static/home.css b/Bone Fracture Detection/Web App/static/home.css new file mode 100644 index 000000000..50cbc8ddb --- /dev/null +++ b/Bone Fracture Detection/Web App/static/home.css @@ -0,0 +1,59 @@ +*{ + margin:0; + padding:0; + box-sizing: border-box; +} +body{ + min-height: 100vh; + background-image: url('./image.png'); + display: flex; + font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace; +} +.container{ + margin : auto; + width: 500px; + max-width: 90%; +} +.container form{ + width: 100%; + height: 100%; + padding: 20px; + background: transparent; + color : white; + backdrop-filter: blur(90px); + border-radius: 4px; + box-shadow: 0 8px 16px rgba(255, 255, 255, 0.3); +} +.container form h1{ + text-align: center; + margin-bottom: 24px; + color: white; +} +.container form .form-control{ + width: 100%; + height: 40px; + background: transparent; + border-radius: 4px; + border: 1px solid silver; + margin: 10px 0 18px 0; + padding: 10px; + color : white; +} +.container form .btn{ + margin-left: 50%; + transform: translate(-50%); + width: 120px; + height: 34px; + outline: none; + background: transparent; + border-color: 1px solid silver; + border-width: 2px; + cursor: pointer; + font-size: 16px; + text-transform: uppercase; + color: white; + border-radius: 5px; +} +.container form .btn:hover{ + opacity: 0.2; +} \ No newline at end of file diff --git a/Bone Fracture Detection/Web App/static/image.png b/Bone Fracture Detection/Web App/static/image.png new file mode 100644 index 000000000..3166e2030 Binary files /dev/null and b/Bone Fracture Detection/Web App/static/image.png differ diff --git a/Bone Fracture Detection/Web App/static/result.css b/Bone Fracture Detection/Web App/static/result.css new file mode 100644 index 000000000..1fac90c0d --- /dev/null +++ b/Bone Fracture Detection/Web App/static/result.css @@ -0,0 +1,63 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} +body { + min-height: 100vh; + background: radial-gradient(white, black); + display: flex; + font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace; +} +.container { + margin: auto; + width: 700px; + max-width: 90%; + padding: 20px; + backdrop-filter: blur(20px); + background: rgba(255, 255, 255, 0.3); + box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3); + border-radius: 5px; +} +.container .image { + display: flex; + justify-content: center; + margin: auto; + margin-bottom: 10px; +} +.container .image img { + max-width: 50%; + max-height: 50%; +} +.container .information { + margin: auto; + text-align: center; + width: 100%; + height: 80%; + border-color: black; + margin-bottom: 20px; +} +.container .information .h1 { + text-align: center; + font-weight: bold; + margin-bottom: 10px; +} +.container .button { + margin-left: 50%; + transform: translate(-50%); + width: 120px; + height: 34px; + outline: none; + background: transparent; + border-color: black; + border-width: 2px; + cursor: pointer; + font-size: 16px; + text-transform: uppercase; + color: black; + border-radius: 5px; + transition: .3s; +} +.container .button:hover { + opacity: 0.3; +} diff --git a/Bone Fracture Detection/Web App/templates/home.html b/Bone Fracture Detection/Web App/templates/home.html new file mode 100644 index 000000000..494dc900c --- /dev/null +++ b/Bone Fracture Detection/Web App/templates/home.html @@ -0,0 +1,25 @@ + + + + + + Bone Fracture Detection + + + +
+
+

Upload Image

+
+ + +
+
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/Bone Fracture Detection/Web App/templates/result.html b/Bone Fracture Detection/Web App/templates/result.html new file mode 100644 index 000000000..b2de2200e --- /dev/null +++ b/Bone Fracture Detection/Web App/templates/result.html @@ -0,0 +1,23 @@ + + + + + + Results + + + +
+
+ +
+
+

{{class_name}}

+

{{desc}}

+
+

{{sympt}}

+
+ +
+ + diff --git a/Bone Fracture Detection/Web App/thumbnail.png b/Bone Fracture Detection/Web App/thumbnail.png new file mode 100644 index 000000000..a358e19c6 Binary files /dev/null and b/Bone Fracture Detection/Web App/thumbnail.png differ