0% found this document useful (0 votes)
19 views10 pages

931 943 957 Report DIP Brain Cancer Detection

This document proposes a project for brain cancer detection and classification using deep learning techniques, specifically focusing on the development of a Computer-Aided Diagnosis (CAD) system. The project aims to improve diagnostic accuracy and efficiency by utilizing Convolutional Neural Networks (CNNs) and other advanced architectures for analyzing MRI images. The proposed solution includes data preprocessing, model architecture design, training, and evaluation, with a focus on scalability and consistency in cancer detection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views10 pages

931 943 957 Report DIP Brain Cancer Detection

This document proposes a project for brain cancer detection and classification using deep learning techniques, specifically focusing on the development of a Computer-Aided Diagnosis (CAD) system. The project aims to improve diagnostic accuracy and efficiency by utilizing Convolutional Neural Networks (CNNs) and other advanced architectures for analyzing MRI images. The proposed solution includes data preprocessing, model architecture design, training, and evaluation, with a focus on scalability and consistency in cancer detection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

COMPLEX ENGINEERING PROBLEM PROPOSAL

Brain Cancer Detection and Classification using Deep Learning

Submitted By

Abdullah Jahangir 931-FET/BSEE/F21


Ubaid Siddiqui 943-FET/BSEE/F21
Mohaz Zulfiqar 957-FET/BSEE/F21

Course Name: Digital Image Processing


Course Code: CS407
Teacher: Dr. Ihsan Ul Haq

Department of Electrical and Computer Engineering


Faculty of Engineering and Technology
International Islamic University, Islamabad

Fall, 2024

1
Table of Contents

1. Introduction ............................................................................................................................. 3
2. Motivation ............................................................................................................................... 3
3. Literature Review .................................................................................................................... 3
3.1 Convolutional Neural Networks (CNNs) .......................................................................... 3
3.2 Transfer Learning ................................................................................................................. 3
3.3 U-Net Architecture ............................................................................................................... 3
3.4 Capsule Networks ................................................................................................................ 3
3.5 Hybrid Models ...................................................................................................................... 4

4. Problem Statement ................................................................................................................... 4


5. References ............................................................................................................................... 4
6. Solution.................................................................................................................................... 4

2
1. Introduction
Although brain cancers are relatively rare, there are few forms of cancers as deadly and aggressive than
brain cancers due to fast growth and their critical placement in the brain. Given the complexity involved
in MRI or CT scans, the interpretation tends to be by experts, leaving much room for variability among
the results obtained. On imaging techniques, we come up with systems that provide the support required
by experts like radiologists to improve efficiencies in diagnosis and accuracy. This project is concerned
with developing a modular CAD system using deep learning architectures.

Figure 1

2. Motivation

This project is motivated by:

 Scalability: Many hospitals in poor areas don’t have enough skilled doctors. A CAD system can
provide reliable cancer detection to everyone.
 Consistency: Systems avoid errors caused by human judgment and give accurate, repeatable
results.
 Future Potential: The system's design can easily be updated to work with new imaging
technologies and datasets.

3. Literature Review

3.1 Convolutional Neural Networks (CNNs)


CNNs are the most popular spatial feature extractors in medical imaging. Pereira et al. (2016) had excellent
results when using a CNN for brain tumor segmentation; the model was able to accurately distinguish
between tumor regions. However, CNNs need a lot of labeled data for good performance.

3.2 Transfer Learning


Transfer learning enables the use of pre-trained models such as VGG16 or ResNet50 in feature extraction.
Afshar et al. (2019) utilized a custom ResNet architecture to classify brain tumors with high accuracy on the
BRATS dataset. Although it is a powerful tool, transfer learning may not handle domain-specific features in
medical imaging so well.

3.3 U-Net Architecture


Biomedical Image Segmentation by Ronneberger et al. Introduced U-Net in 2015. Its adaptation was
successfully applied for brain tumour segmentation with high accuracy in tumour boundary delineation. In
terms of computation, its requirements are relatively high.

3.4 Capsule Networks


Capsule networks like Afshar et al. (2018) aim at reducing the limitations of a CNN by capturing spatial
relationship among features. They have showed improvement in accuracy for cancer classification tasks, but
the problem complexity increases the training time as well.

3
3.5 Hybrid Models
Hybrids of deep learning with the traditional machine learning that also make use of hybrids as described by
Fabian Isensee et al. in 2020 achieve improvements in performance. Hybrid U-Net and random forest
combined brain tumor segmentation, achieved the best results on BRATS at high computational cost.

Technique Accuracy Dataset used Limitations


CNNs 78% BraTS Dataset Requires Extensive Data.
Transfer Learning 94% BraTS Dataset May not generalize to unseen data.
U-Net Segmentation 91% Brain MRI Dataset Computationally Expensive
Capsule Networks 92% Custom Dataset Increased Training Complexity.
Hybrid Models 96% BraTS Dataset High Computational Cost.

4. Problem Statement
The detection of brain cancer is still not easy due to the complication of medical images, and this requires
manual experience. The existing methods are usually dominated by computational inefficiencies or
overfitting. This work is intended to be a CAD system that uses deep learning for the detection and
classification of brain tumors from MRI/CT scans.

5. References
[1]. Pereira, S., et al. "Brain tumor segmentation using convolutional neural networks in MRI images." IEEE
Transactions on Medical Imaging, 2016.
[2]. Ronneberger, O., et al. "U-Net: Convolutional networks for biomedical image segmentation." Medical
Image Computing and Computer-Assisted Intervention – MICCAI 2015. Springer, 2015.
[3]. Afshar, P., et al. "Capsule networks for brain tumor classification based on MRI images and coarse
tumor boundaries." Expert Systems with Applications, 2019.
[4]. Afshar, P., et al. "Using ResNet for brain tumor classification on MRI images." Proceedings of the IEEE
International Symposium on Biomedical Imaging, 2018.
[5]. Isensee, F., et al. "Automated design of deep learning methods for biomedical image segmentation."
Nature Methods, 2020.

Solution:

The solution is the use of CNN for classifying brain MRI images into two categories: "tumor" and "no
tumor". The steps in this process are:

 Data Preprocessing: Resize the images to 128x128 pixels, normalize them and apply one-hot
encoding of labels.
 Model Architecture: The model has three convolutional layers that are used for feature extraction,
max-pooling layers for downsampling, and dense layers for classification. Dropout is applied to
prevent overfitting.
 Training: The model was trained on categorical cross-entropy loss with the Adam optimizer for 20
Epochs.
 Prediction: The model predicts whether the new MRI image contains a tumor or not.

4
Code:

Mount Google Drive:


from google.colab import drive
drive.mount('/content/drive')
import os
print(os.listdir('/content/drive/MyDrive'))

Import Libraries:
import cv2
import numpy as np
import os
from sklearn.model_selection import train_test_split
from tensorflow.keras.utils import to_categorical
import matplotlib.pyplot as plt
Define Constants and Load Data:
# Define constants
IMG_SIZE = 128 # Resize all images to 128x128
CATEGORIES = ["no", "yes"] # Subfolders for classes (no tumor, tumor)

# Load images using OpenCV


def load_data(dataset_dir):
data = []
labels = []
for category in CATEGORIES:
folder_path = os.path.join(dataset_dir, category)
label = CATEGORIES.index(category) # 0 for 'no', 1 for 'yes'
for img_name in os.listdir(folder_path):
img_path = os.path.join(folder_path, img_name)
try:
# Read and preprocess image
img = cv2.imread(img_path, cv2.IMREAD_COLOR) # Read in color
img = cv2.resize(img, (IMG_SIZE, IMG_SIZE)) # Resize to 128x128
data.append(img)
labels.append(label)
except Exception as e:
print(f"Error loading image {img_name}: {e}")
return np.array(data), np.array(labels)

# Path to your extracted dataset


dataset_dir = '/content/drive/MyDrive/brain_tumor_dataset' # Update this if your
dataset path is different
X, y = load_data(dataset_dir)
X = X / 255.0 # Normalize image data to range [0, 1]
y = to_categorical(y, num_classes=2) # One-hot encode labels

# Split dataset into train, validation, and test sets

5
X_train, X_temp, y_train, y_temp = train_test_split(X, y, test_size=0.3,
random_state=42)
X_val, X_test, y_val, y_test = train_test_split(X_temp, y_temp, test_size=0.5,
random_state=42)

print(f"Train samples: {len(X_train)}, Validation samples: {len(X_val)}, Test


samples: {len(X_test)}")

Build CNN Model:


from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout
from tensorflow.keras.optimizers import Adam

# Build CNN model


model = Sequential([
Conv2D(32, (3, 3), activation='relu', input_shape=(IMG_SIZE, IMG_SIZE, 3)),
MaxPooling2D(pool_size=(2, 2)),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D(pool_size=(2, 2)),
Conv2D(128, (3, 3), activation='relu'),
MaxPooling2D(pool_size=(2, 2)),
Flatten(),
Dense(128, activation='relu'),
Dropout(0.5),
Dense(2, activation='softmax') # 2 output classes ('no', 'yes')
])

Compile the Model:


# Compile the model
model.compile(optimizer=Adam(learning_rate=0.001),
loss='categorical_crossentropy',
metrics=['accuracy'])
# Model summary
model.summary()

Train the Model:


# Train the model
EPOCHS = 20
history = model.fit(
X_train, y_train,
validation_data=(X_val, y_val),
epochs=EPOCHS,
batch_size=32,
verbose=1
)

6
Evaluate Model on Test Set:
# Evaluate model on the test set
test_loss, test_accuracy = model.evaluate(X_test, y_test, verbose=1)
print(f"Test Accuracy: {test_accuracy * 100:.2f}%")

Visualize Accuracy and Loss:


# Visualize accuracy and loss
plt.figure(figsize=(12, 4))

# Accuracy plot
plt.subplot(1, 2, 1)
plt.plot(history.history['accuracy'], label='Train Accuracy')
plt.plot(history.history['val_accuracy'], label='Validation Accuracy')
plt.title('Model Accuracy')
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend()

# Loss plot
plt.subplot(1, 2, 2)
plt.plot(history.history['loss'], label='Train Loss')
plt.plot(history.history['val_loss'], label='Validation Loss')
plt.title('Model Loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()

plt.show()

7
Upload New MRI Image for Prediction with Probability:
# Upload New MRI Image for Prediction with Probability

from google.colab import files


from tensorflow.keras.preprocessing import image
import numpy as np
import matplotlib.pyplot as plt

# Allow user to upload a new image


uploaded = files.upload()

# Process the uploaded image and predict


for filename in uploaded.keys():
img_path = filename
print(f"Image uploaded: {img_path}")

# Preprocess the image: resize it to the same size used for training (128x128)
img = image.load_img(img_path, target_size=(IMG_SIZE, IMG_SIZE))
img_array = image.img_to_array(img) # Convert to array
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
img_array = img_array / 255.0 # Normalize the image

# Predict the class and the probabilities


prediction = model.predict(img_array)
predicted_class = CATEGORIES[np.argmax(prediction)]
predicted_prob = np.max(prediction) # Maximum probability for the predicted
class
predicted_probs = prediction[0] # Probabilities for both classes

# Display the uploaded image and the prediction result


plt.imshow(img)
plt.title(f"Predicted: {predicted_class}\nProbability: {predicted_prob:.2f}")
plt.axis('off')
plt.show()

# Display the class probabilities for both 'no' and 'yes'


print(f"Prediction: The uploaded image is classified as: {predicted_class}")
print(f"Class probabilities: No Tumor: {predicted_probs[0]:.2f}, Tumor:
{predicted_probs[1]:.2f}")

8
Output:

If tumor is present,

If there is no tumor,

9
For running this program, we used Google Colab because when training the Model it takes GPU as well, my
advice is to upload the brain_tumor_dateset.zip in Google drive then unzipped it first using this given code
below:

import zipfile
import os

# Path to the .zip file in Google Drive


zip_path = '/content/drive/MyDrive/brain_tumor_dataset.zip'

# Path where you want to extract the dataset


extract_path = '/content/drive/MyDrive/'

# Extract the files


with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(extract_path)

print("Dataset extracted to:", extract_path)


Results Discussion:
 Training and Validation: The model's accuracy improves over each epochs, with the validation
accuracy reflecting how well it generalizes to new data.
 Test Accuracy: After training, the model is evaluated on a test set and the Test accuracy we got is
92.11%.
 Overfitting: Dropout helps prevent overfitting by randomly deactivating neurons during training.
 New Image Prediction: When a new MRI image is uploaded, the model predicts the class (tumor or
no tumor) and outputs the probability of the prediction.

For Improvement of our Model we can do these:


 Data Augmentation: Applying transformations like rotation or zooming to increase the dataset
size and improve generalization.
 Hyperparameter Tuning: Adjusting learning rates and batch sizes could improve model
performance.
 Advanced Models: Trying more advanced architectures like ResNet or VGG could enhance
accuracy.

10

You might also like