-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67909e7
commit 2d78432
Showing
41 changed files
with
615 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
|
||
|
||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BrainCancerConfig(AppConfig): | ||
name = 'brain_cancer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
|
Binary file added
BIN
+155 Bytes
tumour_detection/brain_cancer/migrations/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
27 changes: 27 additions & 0 deletions
27
tumour_detection/brain_cancer/templates/brain_cancer/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% if error_message %} | ||
<p><strong>{{error_message}}</strong></p> | ||
{%endif%} | ||
|
||
<h1>Brain Tumour Classification Model</h1> | ||
<h3>Project Developers:-</h3> | ||
<ul> | ||
<li><h4>Vansh Jain</h4></li> | ||
<li><h4>Chayan Dhaddha</h4></li> | ||
<li><h4>Anuraag Kansara</h4></li> | ||
<li><h4>Arpit Maheshwari</h4></li> | ||
|
||
<a href="/media/report/finalreport.pdf" target="_blank"> <button id="know_more"><label>Know More</label></button></a> | ||
|
||
</ul> | ||
|
||
<br> | ||
<h2>Please select the MRI of Brain as input (in Nifti(3-D) format) :-</h2> | ||
<form method="post" enctype="multipart/form-data" name="input_file" action="{%url 'brain_cancer:process'%}"> | ||
{% csrf_token %} | ||
<h3>Selected File :-</h3> | ||
<input type="file" id="input_image" name="input_image" required> | ||
<br><br><button type="reset" id="reset"><label>Reset</label></button> | ||
<button type="submit" id="submit"><label>Upload</label></button> | ||
</form> | ||
|
||
|
20 changes: 20 additions & 0 deletions
20
tumour_detection/brain_cancer/templates/brain_cancer/result.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Brain Cancer</title> | ||
</head> | ||
<body> | ||
{% if error_message %} | ||
<p><strong>{{error_message}}</strong></p> | ||
{%endif%} | ||
{% if str %} | ||
<h3>Output : {{ str }}</h3> | ||
{% endif %} | ||
{% if uploaded_file_url %} | ||
<h3>Image shown below:- </h3> | ||
<img src="{{uploaded_file_url}}.jpg"> | ||
{% endif %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.conf.urls import url | ||
from . import views | ||
app_name='brain_cancer' | ||
|
||
urlpatterns = [ | ||
#/brain_tumour/ | ||
url(r'^$',views.index,name='index'), | ||
url(r'^result/$',views.result,name='result'), | ||
url(r'^process/$',views.process,name='process') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.shortcuts import render | ||
from django.http import HttpResponse | ||
from django.template import loader | ||
from django.shortcuts import render | ||
from django.conf import settings | ||
from django.core.files.storage import FileSystemStorage | ||
from lib.test import * | ||
import os | ||
from lib.show_images import save_image_as_jpeg | ||
# Create your views here. | ||
def index(request): | ||
template = loader.get_template('brain_cancer/index.html') | ||
context = {} | ||
return HttpResponse(template.render(context, request)) | ||
|
||
|
||
def result(request): | ||
template = loader.get_template('brain_cancer/result.html') | ||
context = {} | ||
return HttpResponse(template.render(context, request)) | ||
|
||
|
||
def process(request): | ||
if request.method == 'POST' and request.FILES.get('input_image'): | ||
myfile = request.FILES.get('input_image') | ||
fs = FileSystemStorage() | ||
filename = fs.save(myfile.name, myfile) | ||
uploaded_file_url = fs.url(filename) | ||
path_img=os.getcwd()+uploaded_file_url | ||
save_image_as_jpeg(path_img) | ||
if output(path_img) == 0: | ||
str1 = 'Benign' | ||
else: | ||
str1 = 'Malignant' | ||
return render(request, 'brain_cancer/result.html/', {'str': str1, 'uploaded_file_url': uploaded_file_url}) | ||
return render(request, 'brain_cancer/result.html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Wed Jun 13 19:28:41 2018 | ||
@author: arpit | ||
""" | ||
|
||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue Jun 12 20:18:29 2018 | ||
@author: Chayan-Dhaddha | ||
""" | ||
|
||
import os # for doing directory operations | ||
#import pandas as pd | ||
|
||
import numpy as np | ||
from nipype.interfaces import fsl | ||
#import matplotlib.pyplot as plt | ||
|
||
file_path='/home/arpit/Desktop/Project' | ||
data_dir = file_path+'/NiFTiSegmentationsEdited/' | ||
patients = os.listdir(data_dir) | ||
#len(patients) | ||
|
||
|
||
for patient in patients[:]: | ||
#print(patient) | ||
path = data_dir + patient | ||
input_file = path + '/' + patient+'_T2.nii.gz' | ||
print(input_file) | ||
#Preprocessing | ||
#Skull Stripping /home/arpit/Desktop/Project/Skull _Stripped | ||
output_strip_file = "skull_stripping_"+patient+"_T2.nii.gz" | ||
skullstrip = fsl.BET(in_file=input_file, out_file=file_path+'/Skull_Stripped/'+output_strip_file,mask=True) | ||
skullstrip.run() | ||
|
||
#Inhomogeneity Correction(Smoothing) | ||
output_smooth_file = "smooth_"+patient+"_T2.nii.gz" | ||
smooth = fsl.IsotropicSmooth(in_file=file_path+'/Skull_Stripped/'+output_strip_file, out_file=file_path+'/Smooth/'+output_smooth_file,fwhm=4) | ||
smooth.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue Jun 12 20:18:29 2018 | ||
@author: Chayan-Dhaddha | ||
""" | ||
|
||
import os # for doing directory operations | ||
import pandas as pd | ||
|
||
import numpy as np | ||
|
||
from functions import * | ||
#from nipype.interfaces import fsl | ||
#import matplotlib.pyplot as plt | ||
|
||
#used to reshape and resize | ||
IMG_PX_SIZE = 64 | ||
NUM_SLICES = 20 | ||
|
||
|
||
|
||
#path of folders | ||
#file_path='/home/arpit/Desktop/Project' | ||
file_path = os.getcwd() | ||
|
||
#folder name | ||
data_dir = file_path+'/Smooth/' | ||
#listing of all folder in data_dir | ||
patients = os.listdir(data_dir) | ||
|
||
#resize & reshape all nifti file to 64*64*20 | ||
|
||
|
||
|
||
#get labels from xlsx file | ||
labels_df=pd.ExcelFile(file_path+"/TCIA_LGG_cases_159.xlsx") | ||
labels_df=labels_df.parse("Sheet1",index_col=0) | ||
labels_df=labels_df.drop(['1p/19q','Type'],axis=1) | ||
#print(labels_df) | ||
|
||
final_img=[] | ||
final_labels=[] | ||
for patient in patients[:]: | ||
print("hiii ",patient) | ||
|
||
img_data,label=preprocess_data(patient,labels_df,img_px_size=IMG_PX_SIZE, hm_slices=NUM_SLICES) | ||
#print(img_data,label) | ||
"""if label==2: | ||
file_out = file_path + "/final_data/benign/" | ||
elif label==3: | ||
file_out = file_path + "/final_data/malignant/" """ | ||
final_img.append([img_data]) | ||
|
||
final_labels.append(label-2) | ||
print(np.array(img_data).shape) | ||
#convert smooth_LGG-343_T2.nii.gz to LGG-343 | ||
#s_patient=str(patient) | ||
#split_patient=s_patient.split('_') | ||
#np.save(file_out+'final_img-{}-{}-{}-{}.npy'.format(split_patient[1],IMG_PX_SIZE,IMG_PX_SIZE,NUM_SLICES),final_img) | ||
np.save(file_path+'/final_img-{}-{}-{}.npy'.format(IMG_PX_SIZE,IMG_PX_SIZE,NUM_SLICES),final_img) | ||
np.save(file_path+'/final_labels.npy',final_labels) | ||
print(np.array(final_img).shape) | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sun Jun 17 04:26:41 2018 | ||
@author: arpit | ||
""" | ||
import os # for doing directory operations | ||
import pandas as pd | ||
import nibabel as nib | ||
import numpy as np | ||
import cv2 | ||
import math | ||
|
||
|
||
#path of folders | ||
#file_path='/home/arpit/Desktop/Project' | ||
file_path = os.getcwd() | ||
|
||
#folder name | ||
data_dir = file_path+'/Smooth/' | ||
#listing of all folder in data_dir | ||
patients = os.listdir(data_dir) | ||
#used in reshape to decrease fix size of slices eg:60->20 by chunk_size of 3 | ||
def chunks(l, n): | ||
"""Yield successive n-sized chunks from l.""" | ||
for i in range(0, len(l), n): | ||
yield l[i:i + n] | ||
|
||
#used to merge slices by taking mean of them | ||
def mean(l): | ||
return sum(l) / len(l) | ||
|
||
def preprocess_data(patient,labels_df,img_px_size=50, hm_slices=20, visualize=False): | ||
#patient of type smooth_LGG-343_T2.nii.gz | ||
path = data_dir + patient | ||
#print(path) | ||
|
||
#convert smooth_LGG-343_T2.nii.gz to LGG-343 | ||
s_patient=str(patient) | ||
split_patient=s_patient.split('_') | ||
#read label of LGG-343 | ||
label = labels_df.get_value(split_patient[1], 'Grade') | ||
|
||
#load nifti file as numpy array | ||
img = nib.load(path) | ||
img_data =img.get_data() | ||
shape=img_data.shape | ||
|
||
#resize slices from 256*256 to 64*64 | ||
slices = [cv2.resize(img_data[:,:,i],(img_px_size,img_px_size)) for i in range(0,shape[2])] | ||
|
||
#make slice no. = 20 | ||
new_slices = [] | ||
chunk_sizes = math.ceil(len(slices) / hm_slices) | ||
for slice_chunk in chunks(slices, chunk_sizes): | ||
slice_chunk = list(map(mean, zip(*slice_chunk))) | ||
new_slices.append(slice_chunk) | ||
#print(len(slices),len(new_slices)) | ||
empty_slice=list(np.zeros([img_px_size,img_px_size])) | ||
|
||
for i in range(0,hm_slices-len(new_slices)): | ||
new_slices.append(empty_slice) | ||
|
||
print(len(slices),len(new_slices)) | ||
|
||
return new_slices,label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Sun Jun 17 19:50:51 2018 | ||
@author: arpit | ||
""" | ||
|
||
import nibabel as nib | ||
import matplotlib.pyplot as plt | ||
import os,math | ||
import numpy as np | ||
import matplotlib.gridspec as gridspec | ||
|
||
|
||
'''def show_slices(slices,x): | ||
""" Function to display row of image slices """ | ||
fig, axes = plt.subplots(x/4,4) # changes as per the length of slice | ||
for i, slice in enumerate(slices): | ||
axes[i].imshow(slice.T, cmap="gray", origin="lower") | ||
''' | ||
|
||
|
||
def save_image_as_jpeg(input_file): | ||
#input_file = os.getcwd()+input_img | ||
img = nib.load(input_file) | ||
img_data = img.get_data() | ||
shape = img_data.shape | ||
slice_list=[] | ||
for i in range(0,shape[2]): #for different parts scanned during MRI | ||
slice_list.append(img_data[:, :, i]) # making a 3D matrix | ||
|
||
|
||
plt.suptitle("Original NIfTI Images") | ||
fig=plt.figure(figsize=(5,10)) | ||
plt.axis('off') | ||
columns = 5 | ||
rows = math.ceil((shape[2])/5) | ||
gs1 = gridspec.GridSpec(rows,columns) | ||
gs1.update(wspace=0.05, hspace=0.05) | ||
for i in range(0,shape[2]): | ||
#img = np.random.randint(10, size=(h,w)) | ||
fig.add_subplot(gs1[i],xticks=[],yticks=[]) | ||
plt.imshow(slice_list[i],cmap="gray",origin="upper",aspect="auto") | ||
fig.subplots_adjust(wspace=0,hspace=0) | ||
plt.savefig(input_file+'.jpg',bbox_inches='tight') | ||
#plt.show() | ||
|
||
|
Oops, something went wrong.