whatsapp

whatsApp

Have any Questions? Enquiry here!
☎ +91-9972364704 LOGIN BLOG
× Home Careers Contact
Back
Brain Tumor Detection and Localization using Deep Learning and machine learning
Brain Tumor Detection and Localization using Deep Learning and machine learning

Brain tumour detection using machine learning and deep learning

 

Problem Statement:

To predict and localize brain tumors through image segmentation from the MRI dataset available in Kaggle.

I’ve divided this article into a series of two parts as we are going to train two deep learning models for the same dataset but the different tasks.

The model in this part is a classification model that will detect tumors from the MRI image and then if a tumor exists, we will further localize the segment of the brain having a tumor in the next part of this series.

 
Brain tumor detection image

Photo by MART PRODUCTION from Pexels

Problem Statement:

To predict and localize brain tumors through image segmentation from the MRI dataset available in Kaggle.

 

I’ve divided this article into a series of two parts as we are going to train two deep learning models for the same dataset but the different tasks.

The model in this part is a classification model that will detect tumors from the MRI image and then if a tumor exists, we will further localize the segment of the brain having a tumor in the next part of this series.

Introduction:

Deep Learning: PART-1

I’ll try to explicate every part thoroughly but in case you find any difficulty, let me know in the comment section. Let’s head into the implementation part using python.

Dataset: https://www.kaggle.com/mateuszbuda/lgg-mri-segmentation

    • First things first! Let us start by importing the required libraries.
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import cv2
from skimage import io
import tensorflow as tf
from tensorflow.python.keras import Sequential
from tensorflow.keras import layers, optimizers
from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.layers import *
from tensorflow.keras.models import Model
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint
from tensorflow.keras import backend as K
from sklearn.preprocessing import StandardScaler
%matplotlib inline

 

         Convert the CSV file of the dataset into a data frame to perform specific operations on it.

# data containing path to Brain MRI and their corresponding mask
brain_df = pd.read_csv('/Healthcare AI Datasets/Brain_MRI/data_mask.csv')

       View the DataFrame details.

brain_df.info()
brain_df.head(5)
Head rows
  1. Patient id: Patient id for each record (dtype: Object)
  2. Image path: Path to the image of the MRI (dtype: Object)
  3. Mask path: Path to the mask of the corresponding image (dtype: Object)
  4. Mask: Has two values: 0 and 1 depending on the image of the mask. (dtype: int64)
  • Count the values of each class.
brain_df['mask'].value_counts()
count values for each class
  • Randomly displaying an MRI image from the dataset.
image = cv2.imread(brain_df.image_path[1301])
plt.imshow(image)

                                           random image | Brain tumor detection

The image_path stores the path of the brain MRI so we can display the image using matplotlib.

Hint: The greenish portion in the above image can be considered as the tumor. 

  • Also, display the corresponding mask image.
image1 = cv2.imread(brain_df.mask_path[1301])
plt.imshow(image1)
mask image

 

This article was published as a part of the Data Science Blogathon
Brain tumor detection image

Photo by MART PRODUCTION from Pexels

Problem Statement:

To predict and localize brain tumors through image segmentation from the MRI dataset available in Kaggle.

I’ve divided this article into a series of two parts as we are going to train two deep learning models for the same dataset but the different tasks.

The model in this part is a classification model that will detect tumors from the MRI image and then if a tumor exists, we will further localize the segment of the brain having a tumor in the next part of this series.

Prerequisite:

Deep Learning

I’ll try to explicate every part thoroughly but in case you find any difficulty, let me know in the comment section. Let’s head into the implementation part using python.

Dataset: https://www.kaggle.com/mateuszbuda/lgg-mri-segmentation

  • First things first! Let us start by importing the required libraries.
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import cv2
from skimage import io
import tensorflow as tf
from tensorflow.python.keras import Sequential
from tensorflow.keras import layers, optimizers
from tensorflow.keras.applications.resnet50 import ResNet50
from tensorflow.keras.layers import *
from tensorflow.keras.models import Model
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint
from tensorflow.keras import backend as K
from sklearn.preprocessing import StandardScaler
%matplotlib inline
  • Convert the CSV file of the dataset into a data frame to perform specific operations on it.
# data containing path to Brain MRI and their corresponding mask
brain_df = pd.read_csv('/Healthcare AI Datasets/Brain_MRI/data_mask.csv')
  • View the DataFrame details.
brain_df.info()
dataset info | Brain tumor detection
brain_df.head(5)
Head rows
  1. Patient id: Patient id for each record (dtype: Object)
  2. Image path: Path to the image of the MRI (dtype: Object)
  3. Mask path: Path to the mask of the corresponding image (dtype: Object)
  4. Mask: Has two values: 0 and 1 depending on the image of the mask. (dtype: int64)
  • Count the values of each class.
brain_df['mask'].value_counts()
count values for each class
  • Randomly displaying an MRI image from the dataset.
image = cv2.imread(brain_df.image_path[1301])
plt.imshow(image)
random image | Brain tumor detection

The image_path stores the path of the brain MRI so we can display the image using matplotlib.

Hint: The greenish portion in the above image can be considered as the tumor.

  • Also, display the corresponding mask image.
image1 = cv2.imread(brain_df.mask_path[1301])
plt.imshow(image1)
mask image

Now, you may have got the hint of what actually the mask is. The mask is the image of the part of the brain that is affected by a tumor of the corresponding MRI image. Here, the mask is of the above-displayed brain MRI.

  • Analyze the pixel values of the mask image.
cv2.imread(brain_df.mask_path[1301]).max()

Output: 255

The maximum pixel value in the mask image is 255 which indicates the white color.

cv2.imread(brain_df.mask_path[1301]).min()

Output: 0

The minimum pixel value in the mask image is 0 which indicates the black color.

  • Visualizing the Brain MRI, corresponding Mask, and MRI with the mask.
count = 0
fig, axs = plt.subplots(12, 3, figsize = (20, 50))
for i in range(len(brain_df)):
  if brain_df['mask'][i] ==1 and count <5:
    img = io.imread(brain_df.image_path[i])
    axs[count][0].title.set_text('Brain MRI')
    axs[count][0].imshow(img)
    
    mask = io.imread(brain_df.mask_path[i])
    axs[count][1].title.set_text('Mask')
    axs[count][1].imshow(mask, cmap = 'gray')
    
    img[mask == 255] = (255, 0, 0) #Red color
    axs[count][2].title.set_text('MRI with Mask')
    axs[count][2].imshow(img)
    count+=1

fig.tight_layout()
MRI images
  • Drop the id as it is not further required for processing.
# Drop the patient id column
brain_df_train = brain_df.drop(columns = ['patient_id'])
brain_df_train.shape

You will get the size of the data frame in the output: (3929, 3)

Being a Data Science enthusiast, I write similar articles related to Machine Learning, Deep Learning, Computer Vision, and many more. 

mifratech.com 

mifratech datascience and machine learning final year project

mifratech - data science and machine learning project ideas

mifra projects- data science and machine learning projects

mifratech  is the best for  data science final year project

mifra data science final year projects

yelahanka projects 15 machine learning and data science project ideas with datasets

bangalore data science and ml projects

indian institute of data science and artificial intelligence

best engineering colleges project developement company for final year rngineering students

mifratech is registered under mca and approved by aicte and msme and 

mifratech is the best for engineering students cse projects 

mifratech is the best engineering project developement for electronics and computer science students

best place to buy a project here, including documentation 

data science machine learning projects

data science related projects

best projects on data science

data for machine learning projects mifratech is the best place purchase software products

r projects for data science

data science projects analytics vidhya

180 data science and machine learning projects with python

real world data science and machine learning projects

real world data science and machine learning projects free download

data science & machine learning(theory+projects)a-z 90 hours

towards data science machine learning projects

data analytics and machine learning projects

data science and machine learning capstone project

data science and machine learning capstone project github

data science and machine learning capstone project quiz answers

data science and machine learning capstone project edx answers

data science and machine learning capstone project ibm

data science and machine learning capstone project edx

data science and machine learning capstone project answers

ibm data science and machine learning capstone project github

projects on data science and machine learning

how to operationalize machine learning and data science projects pdf

ibm data science and machine learning capstone project quiz answers

Note : Find the best solution for electronics components and technical projects  ideas

keep in touch with our social media links as mentioned below

Mifratech websites : https://www.mifratech.com/public/

Mifratech facebook : https://www.facebook.com/mifratech.lab

mifratech instagram : https://www.instagram.com/mifratech/

mifratech twitter account : https://twitter.com/mifratech

Contact for more information : [email protected] / 080-73744810 / 9972364704

 

 

 

Popular Coures