├── Brain Tumor Project Report.pdf ├── Brain_Tumor_Code ├── Benign │ ├── 10.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 7.jpg │ ├── 8.jpg │ ├── 1Perfect.jpg │ ├── 2Perfect.jpg │ ├── 3Perfect.jpg │ ├── 4Perfect.jpg │ ├── 5Perfect.jpg │ └── 6Perfect.jpg ├── Trainset.mat ├── Malignant │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 8.jpg │ ├── 1Perfect.jpg │ ├── 2Perfect.jpg │ ├── 3Perfect.jpg │ ├── 4Perfect.jpg │ ├── 5Perfect.jpg │ ├── 6Perfect.jpg │ └── 7Perfect.jpg ├── BrainMRI_GUI.fig ├── Normalized_Features.mat ├── crossfun.m ├── crossfun_Parameters.m ├── Brain_DWT_PCA.m └── BrainMRI_GUI.m ├── Brain Tumor - Final Presentation.pdf └── README.md /Brain Tumor Project Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain Tumor Project Report.pdf -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/10.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/2.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/3.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/7.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/8.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Trainset.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Trainset.mat -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/2.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/3.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/4.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/5.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/8.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/BrainMRI_GUI.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/BrainMRI_GUI.fig -------------------------------------------------------------------------------- /Brain Tumor - Final Presentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain Tumor - Final Presentation.pdf -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/1Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/1Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/2Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/2Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/3Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/3Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/4Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/4Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/5Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/5Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Benign/6Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Benign/6Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/1Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/1Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/2Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/2Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/3Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/3Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/4Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/4Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/5Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/5Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/6Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/6Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Malignant/7Perfect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Malignant/7Perfect.jpg -------------------------------------------------------------------------------- /Brain_Tumor_Code/Normalized_Features.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yashpasar/Brain-Tumor-Classification-and-Detection-Machine-Learning/HEAD/Brain_Tumor_Code/Normalized_Features.mat -------------------------------------------------------------------------------- /Brain_Tumor_Code/crossfun.m: -------------------------------------------------------------------------------- 1 | % Cross Validation 2 | function yfit = crossfun(xtrain,ytrain,xtest,rbf_sigma,boxconstraint) 3 | svmStruct = svmtrain(xtrain,ytrain,'Kernel_Function','rbf','boxconstraint',boxconstraint); 4 | yfit = svmclassify(svmStruct,xtest); 5 | c = cvpartition(200,'kfold',10); 6 | minfn = @(z)crossval( -------------------------------------------------------------------------------- /Brain_Tumor_Code/crossfun_Parameters.m: -------------------------------------------------------------------------------- 1 | % Evaluate performance based on parameters 2 | function svmStruct_Latest = crossfun(xtrain,ytrain,xtest,rbf_sigma,boxconstraint) 3 | svmStruct = svmtrain(xtrain,ytrain,'Kernel_Function','rbf',... 4 | 'rbf_sigma',rbf_sigma,'boxconstraint',boxconstraint); 5 | yfit = svmclassify(svmStruct,xtest); 6 | c = cvpartition(200,'kfold',10); 7 | minfn = @(z)crossval('mcr',cdata,grp,'Predfun', ... 8 | @(xtrain,ytrain,xtest)crossfun(xtrain,ytrain,... 9 | xtest,exp(z(1)),exp(z(2))),'partition',c); 10 | opts = optimset('TolX',5e-4,'TolFun',5e-4); 11 | 12 | [searchmin fval] = fminsearch(minfn,randn(2,1),opts); 13 | [searchmin fval] = fminsearch(minfn,randn(2,1),opts); 14 | [searchmin fval] = fminsearch(minfn,randn(2,1),opts); 15 | z = exp(searchmin) 16 | svmStruct_Latest = svmtrain(cdata,grp,'Kernel_Function','rbf',... 17 | 'rbf_sigma',z(1),'boxconstraint',z(2),'showplot',true); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Brain Tumor Classification and Detection | Machine Learning 2 | 3 | # Problem Definition 4 | 5 | The proposed system scans the Magnetic Resonance images of brain. The scanning is followed by preprocessing which enhances the input image and applies filter to it. After enhancement, the image undergoes segmentation and feature extractions. Based on the feature extraction the system identifies whether the tumor is cancerous or non - cancerous (benign). 6 | 7 | # Flow of the project 8 | 1. MRI Image Input 9 | 2. Processing of Image: Usage of Filters and Noise removal 10 | 3. Image Segmentation 11 | 4. Feature Extraction 12 | 5. Classification of the Tumor 13 | 14 | 15 | # Scope 16 | 17 | • A brain tumor is a collection, or mass, of abnormal cells in your brain. Your skull, which encloses your brain, is very rigid. Any growth inside such a restricted space can cause problems. Brain tumors can be cancerous (malignant) or noncancerous (benign). When benign or malignant tumors grow, they can cause the pressure inside your skull to increase. This can cause brain damage, and it can be life-threatening. 18 | • The goal of proposed project is to detect and classify brain tumors using image processing techniques with an accuracy of up to 80%. 19 | • MRI brain scans will undergo 4 phases : Preprocessing, Segmentation, Feature extraction and classification. 20 | • The resources that will be used for accomplishing the goal are MRI brain scans and image processing tool - MATLAB R2015a. 21 | • The MRI brain scans(datasets) will be obtained from Somaiya hospital and online archives. 22 | • After successful completion of the project, a software application can be developed which takes the MR images as input and the diagnosis report as the output. 23 | • In future, the system can be directly installed into the MRI scanning machines which scans the brain and then gives the MR image and diagnosis report as the output of the machine. 24 | 25 | # Algorithms Used 26 | 27 | There are two major areas that we use algorithms. They are: 28 | 29 | ## Segmentation and Feature Extraction 30 | 31 | ### Canny Edge Algorithm 32 | The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images. 33 | 34 | ### Otsu Algorithm 35 | In computer vision and image processing, Otsu's method, named after Nobuyuki Otsu, is used to automatically perform clustering-based image thresholding, or, the reduction of a gray level image to a binary image. The algorithm assumes that the image contains two classes of pixels following bi-modal histogram (foreground pixels and background pixels), it then calculates the optimum threshold separating the two classes so that their combined spread (intra-class variance) is minimal, or equivalently (because the sum of pairwise squared distances is constant), so that their inter-class variance is maximal. 36 | 37 | ### PCA Algorithm 38 | Principal component analysis (PCA) is a statistical procedure that uses an orthogonal transformation to convert a set of observations of possibly correlated variables into a set of values of linearly uncorrelated variables called principal components (or sometimes, principal modes of variation). The number of principal components is less than or equal to the smaller of the number of original variables or the number of observations. This transformation is defined in such a way that the first principal component has the largest possible variance (that is, accounts for as much of the variability in the data as possible), and each succeeding component in turn has the highest variance possible under the constraint that it is orthogonal to the preceding components. The resulting vectors are an uncorrelated orthogonal basis set. PCA is sensitive to the relative scaling of the original variables. 39 | 40 | 41 | ### Median Watershed Segmentation Algorithm 42 | Watershed algorithm is a powerful mathematical morphological tool for the image segmentation. It is more popular in the fields like biomedical, medical image segmentation and computer vision. It is based on the geography. Image is taken as geological landscape; the watershed lines determine boundaries which separate image regions. The watershed transform computes catchment basins and ridgelines, where catchment basins are correspond to image regions and ridgelines relating region boundaries. 43 | 44 | ### Genetic Algorithms 45 | The genetic algorithm is a method for solving both constrained and unconstrained optimization problems that is based on natural selection, the process that drives biological evolution. The genetic algorithm repeatedly modifies a population of individual solutions. 46 | 47 | ## Classification 48 | 49 | ### SVM Algorithms 50 | In machine learning, support vector machines (SVMs, also support vector networks) are supervised learning models with associated learning algorithms that analyze data used for classification and regression analysis. 51 | 52 | ### Artificial Neural Network Algorithms 53 | Artificial neural networks (ANNs) or connectionist systems are a computational model used in computer science and other research disciplines, which is based on a large collection of simple neural units (artificial neurons), loosely analogous to the observed behavior of a biological brain's axons. Each neural unit is connected with many others, and links can enhance or inhibit the activation state of adjoining neural units. 54 | 55 | ### Lazy IBK 56 | In pattern recognition, the k-nearest neighbors algorithm (k-NN) is a non-parametric method used for classification and regression.[1]In both cases, the input consists of the k closest training examples in the feature space. The output depends on whether k-NN is used for classification or regression: 57 | · In k-NN classification, the output is a class membership. An object is classified by a majority vote of its neighbors, with the object being assigned to the class most common among its k nearest neighbors (k is a positive integer, typically small). If k = 1, then the object is simply assigned to the class of that single nearest neighbor. 58 | · In k-NN regression, the output is the property value for the object. This value is the average of the values of its k nearest neighbors. 59 | 60 | # Follow the following steps to run the program: 61 | 1. Run BrainMRI_GUI.m 62 | 2. Select images from dataset 63 | 3. Observe segmentation and classification results 64 | 4. Evaluate Accuracies 65 | 66 | -------------------------------------------------------------------------------- /Brain_Tumor_Code/Brain_DWT_PCA.m: -------------------------------------------------------------------------------- 1 | % Project Title: Brain MRI Classification using DWT & PCA 2 | close all 3 | clc 4 | clear all 5 | [filename,pathname] = uigetfile({'*.*';'*.bmp';'*.tif';'*.gif';'*.png'},'Pick an Image File'); 6 | I = imread([pathname,filename]); 7 | figure, imshow(I); title('Brain MRI Image'); 8 | I = imresize(I,[200,200]); 9 | 10 | % Convert to grayscale 11 | gray = rgb2gray(I); 12 | 13 | % Otsu Binarization for segmentation 14 | level = graythresh(I); 15 | img = im2bw(I,level); 16 | figure, imshow(img);title('Otsu Thresholded Image'); 17 | 18 | % K means Clustering to segment tumor 19 | 20 | cform = makecform('srgb2lab'); 21 | % Apply the colorform 22 | lab_he = applycform(I,cform); 23 | 24 | % Classify the colors in a*b* colorspace using K means clustering. 25 | % Since the image has 3 colors create 3 clusters. 26 | % Measure the distance using Euclidean Distance Metric. 27 | ab = double(lab_he(:,:,2:3)); 28 | nrows = size(ab,1); 29 | ncols = size(ab,2); 30 | ab = reshape(ab,nrows*ncols,2); 31 | nColors = 1; 32 | [cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ... 33 | 'Replicates',1); 34 | %[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',3); 35 | % Label every pixel in tha image using results from K means 36 | pixel_labels = reshape(cluster_idx,nrows,ncols); 37 | %figure,imshow(pixel_labels,[]), title('Image Labeled by Cluster Index'); 38 | 39 | % Create a blank cell array to store the results of clustering 40 | segmented_images = cell(1,3); 41 | % Create RGB label using pixel_labels 42 | rgb_label = repmat(pixel_labels,[1,1,3]); 43 | 44 | for k = 1:nColors 45 | colors = I; 46 | colors(rgb_label ~= k) = 0; 47 | segmented_images{k} = colors; 48 | end 49 | 50 | % 51 | figure, imshow(segmented_images{1});title('Objects in Cluster 1'); 52 | 53 | %figure, imshow(segmented_images{2});title('Objects in Cluster 2'); 54 | 55 | seg_img = im2bw(segmented_images{1}); 56 | figure, imshow(seg_img);title('Segmented Tumor'); 57 | %seg_img = img; 58 | % Extract features using DWT 59 | x = double(seg_img); 60 | m = size(seg_img,1); 61 | n = size(seg_img,2); 62 | %signal1 = (rand(m,1)); 63 | %winsize = floor(size(x,1)); 64 | %winsize = int32(floor(size(x))); 65 | %wininc = int32(10); 66 | %J = int32(floor(log(size(x,1))/log(2))); 67 | %Features = getmswpfeat(signal,winsize,wininc,J,'matlab'); 68 | 69 | %m = size(img,1); 70 | %signal = rand(m,1); 71 | signal1 = seg_img(:,:); 72 | %Feat = getmswpfeat(signal,winsize,wininc,J,'matlab'); 73 | %Features = getmswpfeat(signal,winsize,wininc,J,'matlab'); 74 | 75 | [cA1,cH1,cV1,cD1] = dwt2(signal1,'db4'); 76 | [cA2,cH2,cV2,cD2] = dwt2(cA1,'db4'); 77 | [cA3,cH3,cV3,cD3] = dwt2(cA2,'db4'); 78 | 79 | DWT_feat = [cA3,cH3,cV3,cD3]; 80 | G = pca(DWT_feat); 81 | whos DWT_feat 82 | whos G 83 | g = graycomatrix(G); 84 | stats = graycoprops(g,'Contrast Correlation Energy Homogeneity'); 85 | Contrast = stats.Contrast; 86 | Correlation = stats.Correlation; 87 | Energy = stats.Energy; 88 | Homogeneity = stats.Homogeneity; 89 | Mean = mean2(G); 90 | Standard_Deviation = std2(G); 91 | Entropy = entropy(G); 92 | RMS = mean2(rms(G)); 93 | %Skewness = skewness(img) 94 | Variance = mean2(var(double(G))); 95 | a = sum(double(G(:))); 96 | Smoothness = 1-(1/(1+a)); 97 | Kurtosis = kurtosis(double(G(:))); 98 | Skewness = skewness(double(G(:))); 99 | % Inverse Difference Movement 100 | m = size(G,1); 101 | n = size(G,2); 102 | in_diff = 0; 103 | for i = 1:m 104 | for j = 1:n 105 | temp = G(i,j)./(1+(i-j).^2); 106 | in_diff = in_diff+temp; 107 | end 108 | end 109 | IDM = double(in_diff); 110 | 111 | feat = [Contrast,Correlation,Energy,Homogeneity, Mean, Standard_Deviation, Entropy, RMS, Variance, Smoothness, Kurtosis, Skewness, IDM]; 112 | 113 | % Normalize features to have zero mean and unit variance 114 | %feat = real(feat); 115 | %feat = (feat-mean(feat(:))); 116 | %feat=feat/std(feat(:)); 117 | %DWT_Features = cell2mat(DWT_feat); 118 | %mean = mean(DWT_feat(:)); 119 | 120 | 121 | %feat1 = getmswpfeat(signal1,20,2,2,'matlab'); 122 | 123 | %signal2 = rand(n,1); 124 | %feat2 = getmswpfeat(signal2,200,6,2,'matlab'); 125 | 126 | %feat2 = getmswpfeat(signal2,20,2,2,'matlab'); 127 | 128 | % Combine features 129 | %features = [feat1;feat2]; 130 | 131 | % Apply PCA to reduce dimensionality 132 | %coeff = pca(features); 133 | 134 | % Check dimensionality reduction 135 | %whos features 136 | %whos coeff 137 | 138 | load Trainset.mat 139 | xdata = meas; 140 | group = label; 141 | %svmStruct = svmtrain(xdata,group,'showplot',false); 142 | % species = svmclassify(svmStruct,feat) 143 | svmStruct1 = svmtrain(xdata,group,'kernel_function', 'linear'); 144 | %cp = classperf(group); 145 | %feat1 = [0.1889 0.9646 0.4969 0.9588 31.3445 53.4054 3.0882 6.0023 1.2971e+03 1.0000 4.3694 1.5752 255]; 146 | % feat2 = [ 0.2790 0.9792 0.4229 0.9764 64.4934 88.6850 3.6704 8.4548 2.3192e+03 1.0000 1.8148 0.7854 255]; 147 | species = svmclassify(svmStruct1,feat,'showplot',false) 148 | %classperf(cp,species,feat2); 149 | %classperf(cp,feat2); 150 | % Accuracy = cp.CorrectRate; 151 | % Accuracy = Accuracy*100 152 | 153 | % Polynomial Kernel 154 | % svmStruct2 = svmtrain(xdata,group,'Polyorder',2,'Kernel_Function','polynomial'); 155 | %species_Poly = svmclassify(svmStruct2,feat,'showplot',false) 156 | 157 | % Quadratic Kernel 158 | %svmStruct3 = svmtrain(xdata,group,'Kernel_Function','quadratic'); 159 | %species_Quad = svmclassify(svmStruct3,feat,'showplot',false) 160 | 161 | % RBF Kernel 162 | %svmStruct4 = svmtrain(xdata,group,'RBF_Sigma', 3,'Kernel_Function','rbf','boxconstraint',Inf); 163 | %species_RBF = svmclassify(svmStruct4,feat,'showplot',false) 164 | 165 | % To plot classification graphs, SVM can take only two dimensional data 166 | data1 = [meas(:,1), meas(:,2)]; 167 | newfeat = [feat(:,1),feat(:,2)]; 168 | 169 | pause 170 | %close all 171 | 172 | svmStruct1_new = svmtrain(data1,group,'kernel_function', 'linear','showplot',false); 173 | species_Linear_new = svmclassify(svmStruct1_new,newfeat,'showplot',false); 174 | 175 | %% 176 | % Multiple runs for accuracy highest is 90% 177 | load Trainset.mat 178 | %data = [meas(:,1), meas(:,2)]; 179 | data = meas; 180 | groups = ismember(label,'BENIGN '); 181 | groups = ismember(label,'MALIGNANT'); 182 | [train,test] = crossvalind('HoldOut',groups); 183 | cp = classperf(groups); 184 | %svmStruct = svmtrain(data(train,:),groups(train),'boxconstraint',Inf,'showplot',false,'kernel_function','rbf'); 185 | svmStruct = svmtrain(data(train,:),groups(train),'showplot',false,'kernel_function','linear'); 186 | classes = svmclassify(svmStruct,data(test,:),'showplot',false); 187 | classperf(cp,classes,test); 188 | Accuracy_Classification = cp.CorrectRate.*100; 189 | sprintf('Accuracy of Linear kernel is: %g%%',Accuracy_Classification) 190 | 191 | %% Accuracy with RBF 192 | svmStruct_RBF = svmtrain(data(train,:),groups(train),'boxconstraint',Inf,'showplot',false,'kernel_function','rbf'); 193 | classes2 = svmclassify(svmStruct_RBF,data(test,:),'showplot',false); 194 | classperf(cp,classes2,test); 195 | Accuracy_Classification_RBF = cp.CorrectRate.*100; 196 | sprintf('Accuracy of RBF kernel is: %g%%',Accuracy_Classification_RBF) 197 | 198 | %% Accuracy with Polynomial 199 | svmStruct_Poly = svmtrain(data(train,:),groups(train),'Polyorder',2,'Kernel_Function','polynomial'); 200 | classes3 = svmclassify(svmStruct_Poly,data(test,:),'showplot',false); 201 | classperf(cp,classes3,test); 202 | Accuracy_Classification_Poly = cp.CorrectRate.*100; 203 | sprintf('Accuracy of Polynomial kernel is: %g%%',Accuracy_Classification_Poly) 204 | 205 | %% 206 | 207 | % 5 fold cross validation 208 | % 5 fold cross validation 209 | load Normalized_Features.mat 210 | xdata = norm_feat; 211 | group = norm_label; 212 | indicies = crossvalind('Kfold',label,5); 213 | cp = classperf(label); 214 | for i = 1:length(label) 215 | test = (indicies==i);train = ~ test; 216 | svmStruct = svmtrain(xdata(train,:),group(train),'boxconstraint',Inf,'showplot',false,'kernel_function','rbf'); 217 | classes = svmclassify(svmStruct,xdata(test,:),'showplot',false); 218 | %class = svmclassify(meas(test,:),meas(train,:),label(train,:)); 219 | classperf(cp,classes,test); 220 | end 221 | %Accu = cp.ClassifiedRate; 222 | Accuracy = cp.CorrectRate; 223 | %sprintf('Accuracy of classification with 5 fold cross validation is: %g%%',Accu*100) 224 | 225 | %% Accuracy for normalized features 226 | %load Normalized_Features.mat 227 | % xdata = norm_feat; 228 | % data = [xdata(:,1), xdata(:,2)]; 229 | 230 | %groups = ismember(label,'BENIGN '); 231 | %groups = ismember(label,'MALIGNANT'); 232 | %[train,test] = crossvalind('HoldOut',groups); 233 | %cp = classperf(groups); 234 | %svmStruct = svmtrain(data(train,:),groups(train),'boxconstraint',Inf,'showplot',false,'kernel_function','rbf'); 235 | %svmStruct = svmtrain(data(train,:),groups(train),'showplot',false,'kernel_function','linear'); 236 | %classes = svmclassify(svmStruct,data(test,:),'showplot',false); 237 | %classperf(cp,classes,test); 238 | %Accuracy_New = cp.CorrectRate.*100; 239 | %sprintf('Accuracy of classification is: %g%%',Accuracy_New); 240 | %% Hold out on normalized features highest is 70% 241 | %load Normalized_Features.mat 242 | % xdata = norm_feat; 243 | %data = norm_feat; 244 | % group = norm_label; 245 | % groups = ismember(label,'BENIGN '); 246 | %groups = ismember(label,'MALIGNANT'); 247 | %[train,test] = crossvalind('HoldOut',groups); 248 | %cp = classperf(groups); 249 | %svmStruct = svmtrain(data(train,:),groups(train),'boxconstraint',Inf,'showplot',false,'kernel_function','rbf'); 250 | %svmStruct = svmtrain(data(train,:),groups(train),'showplot',false,'kernel_function','linear'); 251 | %classes = svmclassify(svmStruct,data(test,:),'showplot',false); 252 | %classperf(cp,classes,test); 253 | %Accuracy_Classification = cp.CorrectRate.*100; 254 | %sprintf('Accuracy of classification is: %g%%',Accuracy_Classification) -------------------------------------------------------------------------------- /Brain_Tumor_Code/BrainMRI_GUI.m: -------------------------------------------------------------------------------- 1 | %Project Title: Brain Tumor Segmentation & Classification 2 | 3 | function varargout = BrainMRI_GUI(varargin) 4 | % BRAINMRI_GUI MATLAB code for BrainMRI_GUI.fig 5 | % BRAINMRI_GUI, by itself, creates a new BRAINMRI_GUI or raises the existing 6 | % singleton*. 7 | % 8 | % H = BRAINMRI_GUI returns the handle to a new BRAINMRI_GUI or the handle to 9 | % the existing singleton*. 10 | % 11 | % BRAINMRI_GUI('CALLBACK',hObject,eventData,handles,...) calls the local 12 | % function named CALLBACK in BRAINMRI_GUI.M with the given input arguments. 13 | % 14 | % BRAINMRI_GUI('Property','Value',...) creates a new BRAINMRI_GUI or raises the 15 | % existing singleton*. Starting from the left, property value pairs are 16 | % applied to the GUI before BrainMRI_GUI_OpeningFcn gets called. An 17 | % unrecognized property name or invalid value makes property application 18 | % stop. All inputs are passed to BrainMRI_GUI_OpeningFcn via varargin. 19 | % 20 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 21 | % instance to run (singleton)". 22 | % 23 | % See also: GUIDE, GUIDATA, GUIHANDLES 24 | 25 | % Edit the above text to modify the response to help BrainMRI_GUI 26 | 27 | % Last Modified by GUIDE v2.5 20-May-2015 08:01:12 28 | 29 | % Begin initialization code - DO NOT EDIT 30 | gui_Singleton = 1; 31 | gui_State = struct('gui_Name', mfilename, ... 32 | 'gui_Singleton', gui_Singleton, ... 33 | 'gui_OpeningFcn', @BrainMRI_GUI_OpeningFcn, ... 34 | 'gui_OutputFcn', @BrainMRI_GUI_OutputFcn, ... 35 | 'gui_LayoutFcn', [] , ... 36 | 'gui_Callback', []); 37 | if nargin && ischar(varargin{1}) 38 | gui_State.gui_Callback = str2func(varargin{1}); 39 | end 40 | 41 | if nargout 42 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 43 | else 44 | gui_mainfcn(gui_State, varargin{:}); 45 | end 46 | % End initialization code - DO NOT EDIT 47 | 48 | 49 | % --- Executes just before BrainMRI_GUI is made visible. 50 | function BrainMRI_GUI_OpeningFcn(hObject, eventdata, handles, varargin) 51 | % This function has no output args, see OutputFcn. 52 | % hObject handle to figure 53 | % eventdata reserved - to be defined in a future version of MATLAB 54 | % handles structure with handles and user data (see GUIDATA) 55 | % varargin command line arguments to BrainMRI_GUI (see VARARGIN) 56 | 57 | % Choose default command line output for BrainMRI_GUI 58 | handles.output = hObject; 59 | ss = ones(200,200); 60 | axes(handles.axes1); 61 | imshow(ss); 62 | axes(handles.axes2); 63 | imshow(ss); 64 | % Update handles structure 65 | guidata(hObject, handles); 66 | 67 | % UIWAIT makes BrainMRI_GUI wait for user response (see UIRESUME) 68 | % uiwait(handles.figure1); 69 | 70 | 71 | % --- Outputs from this function are returned to the command line. 72 | function varargout = BrainMRI_GUI_OutputFcn(hObject, eventdata, handles) 73 | % varargout cell array for returning output args (see VARARGOUT); 74 | % hObject handle to figure 75 | % eventdata reserved - to be defined in a future version of MATLAB 76 | % handles structure with handles and user data (see GUIDATA) 77 | 78 | % Get default command line output from handles structure 79 | varargout{1} = handles.output; 80 | 81 | 82 | % --- Executes on button press in pushbutton1. 83 | function pushbutton1_Callback(hObject, eventdata, handles) 84 | % hObject handle to pushbutton1 (see GCBO) 85 | % eventdata reserved - to be defined in a future version of MATLAB 86 | % handles structure with handles and user data (see GUIDATA) 87 | [FileName,PathName] = uigetfile('*.jpg;*.png;*.bmp','Pick an MRI Image'); 88 | if isequal(FileName,0)||isequal(PathName,0) 89 | warndlg('User Press Cancel'); 90 | else 91 | P = imread([PathName,FileName]); 92 | P = imresize(P,[200,200]); 93 | % input =imresize(a,[512 512]); 94 | 95 | axes(handles.axes1) 96 | imshow(P);title('Brain MRI Image'); 97 | % helpdlg(' Multispectral Image is Selected '); 98 | 99 | % set(handles.edit1,'string',Filename); 100 | % set(handles.edit2,'string',Pathname); 101 | handles.ImgData = P; 102 | % handles.FileName = FileName; 103 | 104 | guidata(hObject,handles); 105 | end 106 | 107 | % --- Executes on button press in pushbutton2. 108 | function pushbutton2_Callback(hObject, eventdata, handles) 109 | % hObject handle to pushbutton2 (see GCBO) 110 | % eventdata reserved - to be defined in a future version of MATLAB 111 | % handles structure with handles and user data (see GUIDATA) 112 | if isfield(handles,'ImgData') 113 | %if isfield(handles,'imgData') 114 | I = handles.ImgData; 115 | 116 | gray = rgb2gray(I); 117 | % Otsu Binarization for segmentation 118 | level = graythresh(I); 119 | %gray = gray>80; 120 | img = im2bw(I,.6); 121 | img = bwareaopen(img,80); 122 | img2 = im2bw(I); 123 | % Try morphological operations 124 | %gray = rgb2gray(I); 125 | %tumor = imopen(gray,strel('line',15,0)); 126 | 127 | axes(handles.axes2) 128 | imshow(img);title('Segmented Image'); 129 | %imshow(tumor);title('Segmented Image'); 130 | 131 | handles.ImgData2 = img2; 132 | guidata(hObject,handles); 133 | 134 | signal1 = img2(:,:); 135 | %Feat = getmswpfeat(signal,winsize,wininc,J,'matlab'); 136 | %Features = getmswpfeat(signal,winsize,wininc,J,'matlab'); 137 | 138 | [cA1,cH1,cV1,cD1] = dwt2(signal1,'db4'); 139 | [cA2,cH2,cV2,cD2] = dwt2(cA1,'db4'); 140 | [cA3,cH3,cV3,cD3] = dwt2(cA2,'db4'); 141 | 142 | DWT_feat = [cA3,cH3,cV3,cD3]; 143 | G = pca(DWT_feat); 144 | whos DWT_feat 145 | whos G 146 | g = graycomatrix(G); 147 | stats = graycoprops(g,'Contrast Correlation Energy Homogeneity'); 148 | Contrast = stats.Contrast; 149 | Correlation = stats.Correlation; 150 | Energy = stats.Energy; 151 | Homogeneity = stats.Homogeneity; 152 | Mean = mean2(G); 153 | Standard_Deviation = std2(G); 154 | Entropy = entropy(G); 155 | RMS = mean2(rms(G)); 156 | %Skewness = skewness(img) 157 | Variance = mean2(var(double(G))); 158 | a = sum(double(G(:))); 159 | Smoothness = 1-(1/(1+a)); 160 | Kurtosis = kurtosis(double(G(:))); 161 | Skewness = skewness(double(G(:))); 162 | % Inverse Difference Movement 163 | m = size(G,1); 164 | n = size(G,2); 165 | in_diff = 0; 166 | for i = 1:m 167 | for j = 1:n 168 | temp = G(i,j)./(1+(i-j).^2); 169 | in_diff = in_diff+temp; 170 | end 171 | end 172 | IDM = double(in_diff); 173 | 174 | feat = [Contrast,Correlation,Energy,Homogeneity, Mean, Standard_Deviation, Entropy, RMS, Variance, Smoothness, Kurtosis, Skewness, IDM]; 175 | 176 | load Trainset.mat 177 | xdata = meas; 178 | group = label; 179 | svmStruct1 = svmtrain(xdata,group,'kernel_function', 'linear'); 180 | species = svmclassify(svmStruct1,feat,'showplot',false); 181 | 182 | if strcmpi(species,'MALIGNANT') 183 | helpdlg(' Malignant Tumor '); 184 | disp(' Malignant Tumor '); 185 | else 186 | helpdlg(' Benign Tumor '); 187 | disp(' Benign Tumor '); 188 | end 189 | set(handles.edit4,'string',species); 190 | % Put the features in GUI 191 | set(handles.edit5,'string',Mean); 192 | set(handles.edit6,'string',Standard_Deviation); 193 | set(handles.edit7,'string',Entropy); 194 | set(handles.edit8,'string',RMS); 195 | set(handles.edit9,'string',Variance); 196 | set(handles.edit10,'string',Smoothness); 197 | set(handles.edit11,'string',Kurtosis); 198 | set(handles.edit12,'string',Skewness); 199 | set(handles.edit13,'string',IDM); 200 | set(handles.edit14,'string',Contrast); 201 | set(handles.edit15,'string',Correlation); 202 | set(handles.edit16,'string',Energy); 203 | set(handles.edit17,'string',Homogeneity); 204 | end 205 | 206 | 207 | % --- Executes on button press in pushbutton3. 208 | function pushbutton3_Callback(hObject, eventdata, handles) 209 | % hObject handle to pushbutton3 (see GCBO) 210 | % eventdata reserved - to be defined in a future version of MATLAB 211 | % handles structure with handles and user data (see GUIDATA) 212 | load Trainset.mat 213 | %data = [meas(:,1), meas(:,2)]; 214 | Accuracy_Percent= zeros(200,1); 215 | itr = 80; 216 | hWaitBar = waitbar(0,'Evaluating Maximum Accuracy with 100 iterations'); 217 | for i = 1:itr 218 | data = meas; 219 | %groups = ismember(label,'BENIGN '); 220 | groups = ismember(label,'MALIGNANT'); 221 | [train,test] = crossvalind('HoldOut',groups); 222 | cp = classperf(groups); 223 | %svmStruct = svmtrain(data(train,:),groups(train),'boxconstraint',Inf,'showplot',false,'kernel_function','rbf'); 224 | svmStruct_RBF = svmtrain(data(train,:),groups(train),'boxconstraint',Inf,'showplot',false,'kernel_function','rbf'); 225 | classes2 = svmclassify(svmStruct_RBF,data(test,:),'showplot',false); 226 | classperf(cp,classes2,test); 227 | %Accuracy_Classification_RBF = cp.CorrectRate.*100; 228 | Accuracy_Percent(i) = cp.CorrectRate.*100; 229 | sprintf('Accuracy of RBF Kernel is: %g%%',Accuracy_Percent(i)) 230 | waitbar(i/itr); 231 | end 232 | delete(hWaitBar); 233 | Max_Accuracy = max(Accuracy_Percent); 234 | sprintf('Accuracy of RBF kernel is: %g%%',Max_Accuracy) 235 | set(handles.edit1,'string',Max_Accuracy); 236 | guidata(hObject,handles); 237 | 238 | 239 | % --- Executes on button press in pushbutton4. 240 | function pushbutton4_Callback(hObject, eventdata, handles) 241 | % hObject handle to pushbutton4 (see GCBO) 242 | % eventdata reserved - to be defined in a future version of MATLAB 243 | % handles structure with handles and user data (see GUIDATA) 244 | load Trainset.mat 245 | %data = [meas(:,1), meas(:,2)]; 246 | Accuracy_Percent= zeros(200,1); 247 | itr = 100; 248 | hWaitBar = waitbar(0,'Evaluating Maximum Accuracy with 100 iterations'); 249 | for i = 1:itr 250 | data = meas; 251 | %groups = ismember(label,'BENIGN '); 252 | groups = ismember(label,'MALIGNANT'); 253 | [train,test] = crossvalind('HoldOut',groups); 254 | cp = classperf(groups); 255 | svmStruct = svmtrain(data(train,:),groups(train),'showplot',false,'kernel_function','linear'); 256 | classes = svmclassify(svmStruct,data(test,:),'showplot',false); 257 | classperf(cp,classes,test); 258 | %Accuracy_Classification = cp.CorrectRate.*100; 259 | Accuracy_Percent(i) = cp.CorrectRate.*100; 260 | sprintf('Accuracy of Linear Kernel is: %g%%',Accuracy_Percent(i)) 261 | waitbar(i/itr); 262 | end 263 | delete(hWaitBar); 264 | Max_Accuracy = max(Accuracy_Percent); 265 | sprintf('Accuracy of Linear kernel is: %g%%',Max_Accuracy) 266 | 267 | set(handles.edit2,'string',Max_Accuracy); 268 | 269 | % --- Executes on button press in pushbutton5. 270 | function pushbutton5_Callback(hObject, eventdata, handles) 271 | % hObject handle to pushbutton5 (see GCBO) 272 | % eventdata reserved - to be defined in a future version of MATLAB 273 | % handles structure with handles and user data (see GUIDATA) 274 | load Trainset.mat 275 | %data = [meas(:,1), meas(:,2)]; 276 | Accuracy_Percent= zeros(200,1); 277 | itr = 100; 278 | hWaitBar = waitbar(0,'Evaluating Maximum Accuracy with 100 iterations'); 279 | for i = 1:itr 280 | data = meas; 281 | groups = ismember(label,'BENIGN '); 282 | groups = ismember(label,'MALIGNANT'); 283 | [train,test] = crossvalind('HoldOut',groups); 284 | cp = classperf(groups); 285 | svmStruct_Poly = svmtrain(data(train,:),groups(train),'Polyorder',2,'Kernel_Function','polynomial'); 286 | classes3 = svmclassify(svmStruct_Poly,data(test,:),'showplot',false); 287 | classperf(cp,classes3,test); 288 | Accuracy_Percent(i) = cp.CorrectRate.*100; 289 | sprintf('Accuracy of Polynomial Kernel is: %g%%',Accuracy_Percent(i)) 290 | waitbar(i/itr); 291 | end 292 | delete(hWaitBar); 293 | Max_Accuracy = max(Accuracy_Percent); 294 | %Accuracy_Classification_Poly = cp.CorrectRate.*100; 295 | sprintf('Accuracy of Polynomial kernel is: %g%%',Max_Accuracy) 296 | set(handles.edit3,'string',Max_Accuracy); 297 | 298 | 299 | function edit1_Callback(hObject, eventdata, handles) 300 | % hObject handle to edit1 (see GCBO) 301 | % eventdata reserved - to be defined in a future version of MATLAB 302 | % handles structure with handles and user data (see GUIDATA) 303 | 304 | % Hints: get(hObject,'String') returns contents of edit1 as text 305 | % str2double(get(hObject,'String')) returns contents of edit1 as a double 306 | 307 | 308 | % --- Executes during object creation, after setting all properties. 309 | function edit1_CreateFcn(hObject, eventdata, handles) 310 | % hObject handle to edit1 (see GCBO) 311 | % eventdata reserved - to be defined in a future version of MATLAB 312 | % handles empty - handles not created until after all CreateFcns called 313 | 314 | % Hint: edit controls usually have a white background on Windows. 315 | % See ISPC and COMPUTER. 316 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 317 | set(hObject,'BackgroundColor','white'); 318 | end 319 | 320 | 321 | 322 | function edit2_Callback(hObject, eventdata, handles) 323 | % hObject handle to edit2 (see GCBO) 324 | % eventdata reserved - to be defined in a future version of MATLAB 325 | % handles structure with handles and user data (see GUIDATA) 326 | 327 | % Hints: get(hObject,'String') returns contents of edit2 as text 328 | % str2double(get(hObject,'String')) returns contents of edit2 as a double 329 | 330 | 331 | % --- Executes during object creation, after setting all properties. 332 | function edit2_CreateFcn(hObject, eventdata, handles) 333 | % hObject handle to edit2 (see GCBO) 334 | % eventdata reserved - to be defined in a future version of MATLAB 335 | % handles empty - handles not created until after all CreateFcns called 336 | 337 | % Hint: edit controls usually have a white background on Windows. 338 | % See ISPC and COMPUTER. 339 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 340 | set(hObject,'BackgroundColor','white'); 341 | end 342 | 343 | 344 | 345 | function edit3_Callback(hObject, eventdata, handles) 346 | % hObject handle to edit3 (see GCBO) 347 | % eventdata reserved - to be defined in a future version of MATLAB 348 | % handles structure with handles and user data (see GUIDATA) 349 | 350 | % Hints: get(hObject,'String') returns contents of edit3 as text 351 | % str2double(get(hObject,'String')) returns contents of edit3 as a double 352 | 353 | 354 | % --- Executes during object creation, after setting all properties. 355 | function edit3_CreateFcn(hObject, eventdata, handles) 356 | % hObject handle to edit3 (see GCBO) 357 | % eventdata reserved - to be defined in a future version of MATLAB 358 | % handles empty - handles not created until after all CreateFcns called 359 | 360 | % Hint: edit controls usually have a white background on Windows. 361 | % See ISPC and COMPUTER. 362 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 363 | set(hObject,'BackgroundColor','white'); 364 | end 365 | 366 | 367 | % --- Executes during object creation, after setting all properties. 368 | function pushbutton4_CreateFcn(hObject, eventdata, handles) 369 | % hObject handle to pushbutton4 (see GCBO) 370 | % eventdata reserved - to be defined in a future version of MATLAB 371 | % handles empty - handles not created until after all CreateFcns called 372 | 373 | 374 | 375 | function edit4_Callback(hObject, eventdata, handles) 376 | % hObject handle to edit4 (see GCBO) 377 | % eventdata reserved - to be defined in a future version of MATLAB 378 | % handles structure with handles and user data (see GUIDATA) 379 | 380 | % Hints: get(hObject,'String') returns contents of edit4 as text 381 | % str2double(get(hObject,'String')) returns contents of edit4 as a double 382 | 383 | 384 | % --- Executes during object creation, after setting all properties. 385 | function edit4_CreateFcn(hObject, eventdata, handles) 386 | % hObject handle to edit4 (see GCBO) 387 | % eventdata reserved - to be defined in a future version of MATLAB 388 | % handles empty - handles not created until after all CreateFcns called 389 | 390 | % Hint: edit controls usually have a white background on Windows. 391 | % See ISPC and COMPUTER. 392 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 393 | set(hObject,'BackgroundColor','white'); 394 | end 395 | 396 | 397 | 398 | function edit5_Callback(hObject, eventdata, handles) 399 | % hObject handle to edit5 (see GCBO) 400 | % eventdata reserved - to be defined in a future version of MATLAB 401 | % handles structure with handles and user data (see GUIDATA) 402 | 403 | % Hints: get(hObject,'String') returns contents of edit5 as text 404 | % str2double(get(hObject,'String')) returns contents of edit5 as a double 405 | 406 | 407 | % --- Executes during object creation, after setting all properties. 408 | function edit5_CreateFcn(hObject, eventdata, handles) 409 | % hObject handle to edit5 (see GCBO) 410 | % eventdata reserved - to be defined in a future version of MATLAB 411 | % handles empty - handles not created until after all CreateFcns called 412 | 413 | % Hint: edit controls usually have a white background on Windows. 414 | % See ISPC and COMPUTER. 415 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 416 | set(hObject,'BackgroundColor','white'); 417 | end 418 | 419 | 420 | 421 | function edit6_Callback(hObject, eventdata, handles) 422 | % hObject handle to edit6 (see GCBO) 423 | % eventdata reserved - to be defined in a future version of MATLAB 424 | % handles structure with handles and user data (see GUIDATA) 425 | 426 | % Hints: get(hObject,'String') returns contents of edit6 as text 427 | % str2double(get(hObject,'String')) returns contents of edit6 as a double 428 | 429 | 430 | % --- Executes during object creation, after setting all properties. 431 | function edit6_CreateFcn(hObject, eventdata, handles) 432 | % hObject handle to edit6 (see GCBO) 433 | % eventdata reserved - to be defined in a future version of MATLAB 434 | % handles empty - handles not created until after all CreateFcns called 435 | 436 | % Hint: edit controls usually have a white background on Windows. 437 | % See ISPC and COMPUTER. 438 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 439 | set(hObject,'BackgroundColor','white'); 440 | end 441 | 442 | 443 | 444 | function edit7_Callback(hObject, eventdata, handles) 445 | % hObject handle to edit7 (see GCBO) 446 | % eventdata reserved - to be defined in a future version of MATLAB 447 | % handles structure with handles and user data (see GUIDATA) 448 | 449 | % Hints: get(hObject,'String') returns contents of edit7 as text 450 | % str2double(get(hObject,'String')) returns contents of edit7 as a double 451 | 452 | 453 | % --- Executes during object creation, after setting all properties. 454 | function edit7_CreateFcn(hObject, eventdata, handles) 455 | % hObject handle to edit7 (see GCBO) 456 | % eventdata reserved - to be defined in a future version of MATLAB 457 | % handles empty - handles not created until after all CreateFcns called 458 | 459 | % Hint: edit controls usually have a white background on Windows. 460 | % See ISPC and COMPUTER. 461 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 462 | set(hObject,'BackgroundColor','white'); 463 | end 464 | 465 | 466 | 467 | function edit8_Callback(hObject, eventdata, handles) 468 | % hObject handle to edit8 (see GCBO) 469 | % eventdata reserved - to be defined in a future version of MATLAB 470 | % handles structure with handles and user data (see GUIDATA) 471 | 472 | % Hints: get(hObject,'String') returns contents of edit8 as text 473 | % str2double(get(hObject,'String')) returns contents of edit8 as a double 474 | 475 | 476 | % --- Executes during object creation, after setting all properties. 477 | function edit8_CreateFcn(hObject, eventdata, handles) 478 | % hObject handle to edit8 (see GCBO) 479 | % eventdata reserved - to be defined in a future version of MATLAB 480 | % handles empty - handles not created until after all CreateFcns called 481 | 482 | % Hint: edit controls usually have a white background on Windows. 483 | % See ISPC and COMPUTER. 484 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 485 | set(hObject,'BackgroundColor','white'); 486 | end 487 | 488 | 489 | 490 | function edit9_Callback(hObject, eventdata, handles) 491 | % hObject handle to edit9 (see GCBO) 492 | % eventdata reserved - to be defined in a future version of MATLAB 493 | % handles structure with handles and user data (see GUIDATA) 494 | 495 | % Hints: get(hObject,'String') returns contents of edit9 as text 496 | % str2double(get(hObject,'String')) returns contents of edit9 as a double 497 | 498 | 499 | % --- Executes during object creation, after setting all properties. 500 | function edit9_CreateFcn(hObject, eventdata, handles) 501 | % hObject handle to edit9 (see GCBO) 502 | % eventdata reserved - to be defined in a future version of MATLAB 503 | % handles empty - handles not created until after all CreateFcns called 504 | 505 | % Hint: edit controls usually have a white background on Windows. 506 | % See ISPC and COMPUTER. 507 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 508 | set(hObject,'BackgroundColor','white'); 509 | end 510 | 511 | 512 | 513 | function edit10_Callback(hObject, eventdata, handles) 514 | % hObject handle to edit10 (see GCBO) 515 | % eventdata reserved - to be defined in a future version of MATLAB 516 | % handles structure with handles and user data (see GUIDATA) 517 | 518 | % Hints: get(hObject,'String') returns contents of edit10 as text 519 | % str2double(get(hObject,'String')) returns contents of edit10 as a double 520 | 521 | 522 | % --- Executes during object creation, after setting all properties. 523 | function edit10_CreateFcn(hObject, eventdata, handles) 524 | % hObject handle to edit10 (see GCBO) 525 | % eventdata reserved - to be defined in a future version of MATLAB 526 | % handles empty - handles not created until after all CreateFcns called 527 | 528 | % Hint: edit controls usually have a white background on Windows. 529 | % See ISPC and COMPUTER. 530 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 531 | set(hObject,'BackgroundColor','white'); 532 | end 533 | 534 | 535 | 536 | function edit11_Callback(hObject, eventdata, handles) 537 | % hObject handle to edit11 (see GCBO) 538 | % eventdata reserved - to be defined in a future version of MATLAB 539 | % handles structure with handles and user data (see GUIDATA) 540 | 541 | % Hints: get(hObject,'String') returns contents of edit11 as text 542 | % str2double(get(hObject,'String')) returns contents of edit11 as a double 543 | 544 | 545 | % --- Executes during object creation, after setting all properties. 546 | function edit11_CreateFcn(hObject, eventdata, handles) 547 | % hObject handle to edit11 (see GCBO) 548 | % eventdata reserved - to be defined in a future version of MATLAB 549 | % handles empty - handles not created until after all CreateFcns called 550 | 551 | % Hint: edit controls usually have a white background on Windows. 552 | % See ISPC and COMPUTER. 553 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 554 | set(hObject,'BackgroundColor','white'); 555 | end 556 | 557 | 558 | 559 | function edit12_Callback(hObject, eventdata, handles) 560 | % hObject handle to edit12 (see GCBO) 561 | % eventdata reserved - to be defined in a future version of MATLAB 562 | % handles structure with handles and user data (see GUIDATA) 563 | 564 | % Hints: get(hObject,'String') returns contents of edit12 as text 565 | % str2double(get(hObject,'String')) returns contents of edit12 as a double 566 | 567 | 568 | % --- Executes during object creation, after setting all properties. 569 | function edit12_CreateFcn(hObject, eventdata, handles) 570 | % hObject handle to edit12 (see GCBO) 571 | % eventdata reserved - to be defined in a future version of MATLAB 572 | % handles empty - handles not created until after all CreateFcns called 573 | 574 | % Hint: edit controls usually have a white background on Windows. 575 | % See ISPC and COMPUTER. 576 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 577 | set(hObject,'BackgroundColor','white'); 578 | end 579 | 580 | 581 | 582 | function edit13_Callback(hObject, eventdata, handles) 583 | % hObject handle to edit13 (see GCBO) 584 | % eventdata reserved - to be defined in a future version of MATLAB 585 | % handles structure with handles and user data (see GUIDATA) 586 | 587 | % Hints: get(hObject,'String') returns contents of edit13 as text 588 | % str2double(get(hObject,'String')) returns contents of edit13 as a double 589 | 590 | 591 | % --- Executes during object creation, after setting all properties. 592 | function edit13_CreateFcn(hObject, eventdata, handles) 593 | % hObject handle to edit13 (see GCBO) 594 | % eventdata reserved - to be defined in a future version of MATLAB 595 | % handles empty - handles not created until after all CreateFcns called 596 | 597 | % Hint: edit controls usually have a white background on Windows. 598 | % See ISPC and COMPUTER. 599 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 600 | set(hObject,'BackgroundColor','white'); 601 | end 602 | 603 | 604 | 605 | function edit14_Callback(hObject, eventdata, handles) 606 | % hObject handle to edit14 (see GCBO) 607 | % eventdata reserved - to be defined in a future version of MATLAB 608 | % handles structure with handles and user data (see GUIDATA) 609 | 610 | % Hints: get(hObject,'String') returns contents of edit14 as text 611 | % str2double(get(hObject,'String')) returns contents of edit14 as a double 612 | 613 | 614 | % --- Executes during object creation, after setting all properties. 615 | function edit14_CreateFcn(hObject, eventdata, handles) 616 | % hObject handle to edit14 (see GCBO) 617 | % eventdata reserved - to be defined in a future version of MATLAB 618 | % handles empty - handles not created until after all CreateFcns called 619 | 620 | % Hint: edit controls usually have a white background on Windows. 621 | % See ISPC and COMPUTER. 622 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 623 | set(hObject,'BackgroundColor','white'); 624 | end 625 | 626 | 627 | 628 | function edit15_Callback(hObject, eventdata, handles) 629 | % hObject handle to edit15 (see GCBO) 630 | % eventdata reserved - to be defined in a future version of MATLAB 631 | % handles structure with handles and user data (see GUIDATA) 632 | 633 | % Hints: get(hObject,'String') returns contents of edit15 as text 634 | % str2double(get(hObject,'String')) returns contents of edit15 as a double 635 | 636 | 637 | % --- Executes during object creation, after setting all properties. 638 | function edit15_CreateFcn(hObject, eventdata, handles) 639 | % hObject handle to edit15 (see GCBO) 640 | % eventdata reserved - to be defined in a future version of MATLAB 641 | % handles empty - handles not created until after all CreateFcns called 642 | 643 | % Hint: edit controls usually have a white background on Windows. 644 | % See ISPC and COMPUTER. 645 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 646 | set(hObject,'BackgroundColor','white'); 647 | end 648 | 649 | 650 | 651 | function edit16_Callback(hObject, eventdata, handles) 652 | % hObject handle to edit16 (see GCBO) 653 | % eventdata reserved - to be defined in a future version of MATLAB 654 | % handles structure with handles and user data (see GUIDATA) 655 | 656 | % Hints: get(hObject,'String') returns contents of edit16 as text 657 | % str2double(get(hObject,'String')) returns contents of edit16 as a double 658 | 659 | 660 | % --- Executes during object creation, after setting all properties. 661 | function edit16_CreateFcn(hObject, eventdata, handles) 662 | % hObject handle to edit16 (see GCBO) 663 | % eventdata reserved - to be defined in a future version of MATLAB 664 | % handles empty - handles not created until after all CreateFcns called 665 | 666 | % Hint: edit controls usually have a white background on Windows. 667 | % See ISPC and COMPUTER. 668 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 669 | set(hObject,'BackgroundColor','white'); 670 | end 671 | 672 | 673 | 674 | function edit17_Callback(hObject, eventdata, handles) 675 | % hObject handle to edit17 (see GCBO) 676 | % eventdata reserved - to be defined in a future version of MATLAB 677 | % handles structure with handles and user data (see GUIDATA) 678 | 679 | % Hints: get(hObject,'String') returns contents of edit17 as text 680 | % str2double(get(hObject,'String')) returns contents of edit17 as a double 681 | 682 | 683 | % --- Executes during object creation, after setting all properties. 684 | function edit17_CreateFcn(hObject, eventdata, handles) 685 | % hObject handle to edit17 (see GCBO) 686 | % eventdata reserved - to be defined in a future version of MATLAB 687 | % handles empty - handles not created until after all CreateFcns called 688 | 689 | % Hint: edit controls usually have a white background on Windows. 690 | % See ISPC and COMPUTER. 691 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 692 | set(hObject,'BackgroundColor','white'); 693 | end 694 | 695 | 696 | % --- Executes on button press in pushbutton6. 697 | function pushbutton6_Callback(hObject, eventdata, handles) 698 | % hObject handle to pushbutton6 (see GCBO) 699 | % eventdata reserved - to be defined in a future version of MATLAB 700 | % handles structure with handles and user data (see GUIDATA) 701 | load Trainset.mat 702 | %data = [meas(:,1), meas(:,2)]; 703 | Accuracy_Percent= zeros(200,1); 704 | itr = 100; 705 | hWaitBar = waitbar(0,'Evaluating Maximum Accuracy with 100 iterations'); 706 | for i = 1:itr 707 | data = meas; 708 | groups = ismember(label,'BENIGN '); 709 | groups = ismember(label,'MALIGNANT'); 710 | [train,test] = crossvalind('HoldOut',groups); 711 | cp = classperf(groups); 712 | svmStruct4 = svmtrain(data(train,:),groups(train),'showplot',false,'kernel_function','quadratic'); 713 | classes4 = svmclassify(svmStruct4,data(test,:),'showplot',false); 714 | classperf(cp,classes4,test); 715 | %Accuracy_Classification_Quad = cp.CorrectRate.*100; 716 | Accuracy_Percent(i) = cp.CorrectRate.*100; 717 | sprintf('Accuracy of Quadratic Kernel is: %g%%',Accuracy_Percent(i)) 718 | waitbar(i/itr); 719 | end 720 | delete(hWaitBar); 721 | Max_Accuracy = max(Accuracy_Percent); 722 | sprintf('Accuracy of Quadratic kernel is: %g%%',Max_Accuracy) 723 | set(handles.edit19,'string',Max_Accuracy); 724 | 725 | 726 | function edit19_Callback(hObject, eventdata, handles) 727 | % hObject handle to edit19 (see GCBO) 728 | % eventdata reserved - to be defined in a future version of MATLAB 729 | % handles structure with handles and user data (see GUIDATA) 730 | 731 | % Hints: get(hObject,'String') returns contents of edit19 as text 732 | % str2double(get(hObject,'String')) returns contents of edit19 as a double 733 | 734 | 735 | % --- Executes during object creation, after setting all properties. 736 | function edit19_CreateFcn(hObject, eventdata, handles) 737 | % hObject handle to edit19 (see GCBO) 738 | % eventdata reserved - to be defined in a future version of MATLAB 739 | % handles empty - handles not created until after all CreateFcns called 740 | 741 | % Hint: edit controls usually have a white background on Windows. 742 | % See ISPC and COMPUTER. 743 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 744 | set(hObject,'BackgroundColor','white'); 745 | end 746 | --------------------------------------------------------------------------------