100% found this document useful (1 vote)
161 views23 pages

Brain Tumor Segmentation Using Convolutional Neural Network Source Code

Among brain tumors, gliomas are the most common and aggressive, leading to a very short life expectancy in their highest grade. Thus, treatment planning is a key stage to improve the quality of life of oncological patients. Magnetic Resonance Imaging (MRI) is a widely used imaging technique to assess these tumors, but the large amount of data produced by MRI prevents manual segmentation in a reasonable time, limiting the use of precise quantitative measurements in the clinical practice

Uploaded by

Ghana Kiran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
161 views23 pages

Brain Tumor Segmentation Using Convolutional Neural Network Source Code

Among brain tumors, gliomas are the most common and aggressive, leading to a very short life expectancy in their highest grade. Thus, treatment planning is a key stage to improve the quality of life of oncological patients. Magnetic Resonance Imaging (MRI) is a widely used imaging technique to assess these tumors, but the large amount of data produced by MRI prevents manual segmentation in a reasonable time, limiting the use of precise quantitative measurements in the clinical practice

Uploaded by

Ghana Kiran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Brain Tumor Segmentation using Convolutional Neural Network on

MRI Images

Source code:
function varargout = mainmenu(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mainmenu_OpeningFcn, ...
'gui_OutputFcn', @mainmenu_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before mainmenu is made visible.


function mainmenu_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to mainmenu (see VARARGIN)

% Choose default command line output for mainmenu


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes mainmenu wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = mainmenu_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Input_Image

global Input1

[filename pathname id] = uigetfile({'* .jpg'},'Select input image',[cd


'\images']);
if ~id,return,end
Input1 = double(imread([pathname filename]))/255;
Input_Image = double(imread([pathname filename]))/255;

fullpathname = strcat(pathname,filename);
text=fileread(fullfile(pathname, filename));
% disp(fullpathname);
axes(handles.axes1);
imshow(Input_Image)
handles.ImgData = Input_Image;
set(handles.edit1,'string',fullpathname);

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text


% str2double(get(hObject,'String')) returns contents of edit1 as a
double

% --- Executes during object creation, after setting all properties.


function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton10.


function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global ip_img;
global IMG
global Input_Image;

ip_img=Input_Image;

IMG=double(rgb2gray(ip_img));
CLM = 2;
[ IN, CEN, NOF ] = SUB_FUN8( IMG, CLM );
lb = zeros(2,1);

figure;
subplot(1,3,1);
imshow(IMG,[]);
for i=1:CLM

subplot(1,3,i+1);

imshow(IN(:,:,i),[]);
end

% --- Executes on button press in pushbutton11.


function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Input_Image1
global I
out2 = imadjust(Input_Image1,[.3; .9],[]);
axes(handles.axes2);
imshow(out2)
EN_IP=Input_Image1;
E = entropyfilt(EN_IP);

EN_INP = mat2gray(E);
axes(handles.axes2);
imshow(EN_INP);

BW1 = im2bw(EN_INP, .8);


axes(handles.axes2);

imshow(BW1);
axes(handles.axes2);
imshow(EN_IP);

BW_OP = bwareaopen(BW1,2000);
axes(handles.axes2);
imshow(BW_OP);

nhood = true(9);
C_BW = imclose(BW_OP,nhood);
imshow(C_BW)

R_M = imfill(C_BW,'holes');

imshow(R_M);
axes(handles.axes2);
imshow(EN_IP);

SRT = EN_IP;
SRT(R_M) = 0;
axes(handles.axes2);
imshow(SRT);

EN_INP2 = entropyfilt(SRT);
E_INP2 = mat2gray(EN_INP2);
axes(handles.axes2);
imshow(E_INP2);

BW_IN = im2bw(E_INP2,graythresh(E_INP2));

axes(handles.axes2);
imshow(BW_IN)
axes(handles.axes2);
imshow(EN_IP);
MSK = bwareaopen(BW_IN,1000);
axes(handles.axes2);
imshow(MSK);

TXT1 = EN_IP;
TXT1(~MSK) = 0;
TXT2 = EN_IP;
TXT2(MSK) = 0;

axes(handles.axes2);
imshow(TXT1);
axes(handles.axes2);
imshow(TXT2);
boundary = bwperim(MSK);
SMNT_RST = EN_IP;
SMNT_RST(boundary) = 255;
axes(handles.axes2);
imshow(SMNT_RST);

SM = stdfilt(EN_IP,nhood);
axes(handles.axes2);
imshow(mat2gray(SM));

RS = rangefilt(EN_IP,ones(5));
axes(handles.axes2);
imshow(RS);

% --- Executes on button press in pushbutton3.


function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Input_Image;
global level;
global bw;

global img2;

level=0.2;
I = Input_Image;

gray = rgb2gray(I);
% Otsu Binarization for segmentation
level = graythresh(I);
%gray = gray>80;
img = im2bw(I,.6);
img = bwareaopen(img,80);
img2 = im2bw(I);
% Try morphological operations
%gray = rgb2gray(I);
%tumor = imopen(gray,strel('line',15,0));

axes(handles.axes2)
imshow(img);

bw = im2bw(Input_Image, graythresh(Input_Image));

bw = bwareaopen(bw, 50);

L = bwlabel(bw);
s = regionprops(L,'PixelIdxList');

max_value = zeros(numel(s), 1);


for k = 1:numel(s)
max_value(k) = max(Input_Image(s(k).PixelIdxList));
end
bright_objects = find(max_value > 200)

s=bwarea(bright_objects)

level=0.2;
IMG_CONV = im2bw(Input_Image, graythresh(Input_Image));

IMG_CONV = bwareaopen(IMG_CONV, 100);

BW_DTC = bwlabel(IMG_CONV);
RGN_SEG = regionprops(BW_DTC,'PixelIdxList');

% Initialize vector containing max values.


max_value = zeros(numel(RGN_SEG), 1);
for INP = 1:numel(RGN_SEG)
max_value(INP) = max(Input_Image(RGN_SEG(INP).PixelIdxList));
end

BRT_OBJ = find(max_value < 200)

RGN_SEG=bwarea(BRT_OBJ)

guidata(hObject, handles);

if (bright_objects==1)
uiwait(msgbox('The segmented Image is Normal'));
else (bright_objects==2)

uiwait( msgbox('The segmented Image is Affected '));

end

% --- Executes on button press in pushbutton4.


function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Input_Image
global Input_Image1

Input_Image = Input_Image+0.01*randn(size(Input_Image));
Input_Image(Input_Image<0) = 0; Input_Image(Input_Image>1) = 1;
D = 2;
SIG = [7 0.4];

Input_Image1 = DATA(Input_Image,D,SIG);

scale = 1e10;
J = scale * imnoise(Input_Image1/scale, 'poisson');

axes(handles.axes2);
imshow(J);

% --- Executes on button press in pushbutton5.


function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Input_Image1
axes(handles.axes2);
imshow(Input_Image1);

% --- Executes on button press in pushbutton8.


function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Input_Image;

IMG=rgb2gray(Input_Image);

axes(handles.axes2);
imshow(IMG);

% --- Executes on button press in pushbutton9.


function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Input_Image1
Img_hist

IMG_RZ=imresize(Input_Image1,[500 500]);

IMG_RZ=im2double(IMG_RZ);
level=0.8;

INP = im2bw(IMG_RZ,(level+(.009)));
INP=~INP;
CN_EG=edge(INP,'prewitt');
TG_IMG=CN_EG&INP;

% --- Executes on button press in pushbutton12.


function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global img2
analysis

Data.m

function B = DATA(Input_Image,D,SIG)

if ~exist('Input_Image','var') || isempty(Input_Image)
error('Input image Input_Image is undefined or invalid');
end
if ~isfloat(Input_Image) || ~sum([1,3] == size(Input_Image,3)) || ...
min(Input_Image(:)) < 0 || max(Input_Image(:)) > 1
error(['Input image Input_Image must be a double precision ',...
'matrix of size NxMx1 or NxMx3 on the closed ',...
'interval [0,1].']);
end

if ~exist('w','var') || isempty(D) || ...


numel(D) ~= 1 || D < 1
D = 5;
end
D = ceil(D);

if ~exist('sigma','var') || isempty(SIG) || ...


numel(SIG) ~= 2 || SIG(1) <= 0 || SIG(2) <= 0
SIG = [3 0.1];
end

if size(Input_Image,3) == 1
B = BGRY(Input_Image,D,SIG(1),SIG(2));
else
B = BCLR(Input_Image,D,SIG(1),SIG(2));
end

function B = BGRY(Input_Image,D,SIGD,SIGR)
[X,Y] = meshgrid(-D:D,-D:D);
G = exp(-(X.^2+Y.^2)/(2*SIGD^2));

dim = size(Input_Image);
B = zeros(dim);
for i = 1:dim(1)
for j = 1:dim(2)

iMin = max(i-D,1);
iMax = min(i+D,dim(1));
jMin = max(j-D,1);
jMax = min(j+D,dim(2));
I = Input_Image(iMin:iMax,jMin:jMax);

H = exp(-(I-Input_Image(i,j)).^2/(2*SIGR^2));

F = H.*G((iMin:iMax)-i+D+1,(jMin:jMax)-j+D+1);
B(i,j) = sum(F(:).*I(:))/sum(F(:));

end
end

close(h);

function B = BCLR(Input_Image,D,SIGD,SIGR)

if exist('applycform','file')
Input_Image = applycform(Input_Image,makecform('srgb2lab'));
else
Input_Image = colorspace('Lab<-RGB',Input_Image);
end

[X,Y] = meshgrid(-D:D,-D:D);
G = exp(-(X.^2+Y.^2)/(2*SIGD^2));

SIGR = 100*SIGR;

dim = size(Input_Image);
B = zeros(dim);
for i = 1:dim(1)
for j = 1:dim(2)
iMin = max(i-D,1);
iMax = min(i+D,dim(1));
jMin = max(j-D,1);
jMax = min(j+D,dim(2));
I = Input_Image(iMin:iMax,jMin:jMax,:);

dL = I(:,:,1)-Input_Image(i,j,1);
da = I(:,:,2)-Input_Image(i,j,2);
db = I(:,:,3)-Input_Image(i,j,3);
H = exp(-(dL.^2+da.^2+db.^2)/(2*SIGR^2));

F = H.*G((iMin:iMax)-i+D+1,(jMin:jMax)-j+D+1);
norm_F = sum(F(:));
B(i,j,1) = sum(sum(F.*I(:,:,1)))/norm_F;
B(i,j,2) = sum(sum(F.*I(:,:,2)))/norm_F;
B(i,j,3) = sum(sum(F.*I(:,:,3)))/norm_F;

end
% waitbar(i/dim(1));
end

if exist('applycform','file')
B = applycform(B,makecform('lab2srgb'));
else
B = colorspace('RGB<-Lab',B);
end

ConvAnn.m

% Solve an Input-Output Fitting problem with a Neural Network


% Script generated by NFTOOL
% Created Mon Mar 06 03:56:41 PST 2017
%
% This script assumes these variables are defined:
%
% norm_feat - input data.
% meas - target data.

inputs = norm_feat;
targets = meas;

% Create a Fitting Network


hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};

% Setup Division of Data for Training, Validation, Testing


% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;

% For help on training function 'trainlm' type: help trainlm


% For a list of all training functions type: help nntrain
net.trainFcn = 'trainlm'; % Levenberg-Marquardt

% Choose a Performance Function


% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean squared error

% Choose Plot Functions


% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};

% Train the Network


[net,tr] = train(net,inputs,targets);

% Test the Network


outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)

% Recalculate Training, Validation and Test Performance


trainTargets = targets .* tr.trainMask{1};
valTargets = targets .* tr.valMask{1};
testTargets = targets .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)

% View the Network


%view(net)

% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, plotfit(net,inputs,targets)
%figure, plotregression(targets,outputs)
%figure, ploterrhist(errors)
CNN.m

% Solve an Input-Output Fitting problem with a Neural Network


% Script generated by NFTOOL
% Created Mon Mar 06 03:53:29 PST 2017
%
% This script assumes these variables are defined:
%
% meas - input data.
% norm_feat - target data.

inputs = meas;
targets = norm_feat;

% Create a Fitting Network


hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);

% Choose Input and Output Pre/Post-Processing Functions


% For a list of all processing functions type: help nnprocess
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};

% Setup Division of Data for Training, Validation, Testing


% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;

% For help on training function 'trainlm' type: help trainlm


% For a list of all training functions type: help nntrain
net.trainFcn = 'trainlm'; % Levenberg-Marquardt

% Choose a Performance Function


% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean squared error

% Choose Plot Functions


% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};

% Train the Network


[net,tr] = train(net,inputs,targets);

% Test the Network


outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)

% Recalculate Training, Validation and Test Performance


trainTargets = targets .* tr.trainMask{1};
valTargets = targets .* tr.valMask{1};
testTargets = targets .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)

if(performance<0.4)
msgbox('Stage 1: The Classification Image is Affected')
disp('Stage 1: The Classification Image is Affected')
elseif(performance<0.6)
msgbox('Stage 2: The Classification Image is Affected')
disp('Stage 2: The Classification Image is Affected')
else
msgbox('Stage 3: The Classification Image is Affected')
disp('Stage 3: The Classification Image is Affected')
end

function varargout = analysis(varargin)


% ANALYSIS MATLAB code for analysis.fig
% ANALYSIS, by itself, creates a new ANALYSIS or raises the existing
% singleton*.
%
% H = ANALYSIS returns the handle to a new ANALYSIS or the handle to
% the existing singleton*.
%
% ANALYSIS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ANALYSIS.M with the given input arguments.
%
% ANALYSIS('Property','Value',...) creates a new ANALYSIS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before analysis_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to analysis_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help analysis

% Last Modified by GUIDE v2.5 06-Mar-2017 04:02:04

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @analysis_OpeningFcn, ...
'gui_OutputFcn', @analysis_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before analysis is made visible.


function analysis_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to analysis (see VARARGIN)
global img2
handles.ImgData2 = img2;
guidata(hObject,handles);

signal1 = img2(:,:);
%Feat = getmswpfeat(signal,winsize,wininc,J,'matlab');
%Features = getmswpfeat(signal,winsize,wininc,J,'matlab');

[cA1,cH1,cV1,cD1] = dwt2(signal1,'db4');
[cA2,cH2,cV2,cD2] = dwt2(cA1,'db4');
[cA3,cH3,cV3,cD3] = dwt2(cA2,'db4');

DWT_feat = [cA3,cH3,cV3,cD3];
G = princomp(DWT_feat);
whos DWT_feat
whos G
g = graycomatrix(G);
stats = graycoprops(g,'Contrast Correlation Energy Homogeneity');
Contrast = stats.Contrast;
Correlation = stats.Correlation;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
Mean = mean2(G);
Standard_Deviation = std2(G);
Entropy = entropy(G);
RMS = mean2(rms(G));
%Skewness = skewness(img)
Variance = mean2(var(double(G)));
a = sum(double(G(:)));
Smoothness = 1-(1/(1+a));
Kurtosis = kurtosis(double(G(:)));
Skewness = skewness(double(G(:)));
% Inverse Difference Movement
m = size(G,1);
n = size(G,2);
in_diff = 0;
for i = 1:m
for j = 1:n
temp = G(i,j)./(1+(i-j).^2);
in_diff = in_diff+temp;
end
end
IDM = double(in_diff);

feat = [Contrast,Correlation,Energy,Homogeneity, Mean, Standard_Deviation,


Entropy, RMS, Variance, Smoothness, Kurtosis, Skewness, IDM];

load Trainset.mat
load Normalized_Features.mat
xdata = meas;
group = label;
svmStruct1 = svmtrain(xdata,group,'kernel_function', 'linear');
species = svmclassify(svmStruct1,feat,'showplot',false);

% Put the features in GUI


set(handles.edit1,'string',Mean);
set(handles.edit2,'string',Standard_Deviation);
set(handles.edit3,'string',Entropy);
set(handles.edit4,'string',RMS);
set(handles.edit5,'string',Variance);
set(handles.edit6,'string',Smoothness);
set(handles.edit7,'string',Kurtosis);
set(handles.edit8,'string',Skewness);
set(handles.edit9,'string',IDM);
set(handles.edit10,'string',Contrast);
set(handles.edit11,'string',Correlation);
set(handles.edit12,'string',Energy);
set(handles.edit13,'string',Homogeneity);

% Choose default command line output for analysis


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);
% UIWAIT makes analysis wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = analysis_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text


% str2double(get(hObject,'String')) returns contents of edit1 as a
double

% --- Executes during object creation, after setting all properties.


function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text


% str2double(get(hObject,'String')) returns contents of edit2 as a
double

% --- Executes during object creation, after setting all properties.


function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text


% str2double(get(hObject,'String')) returns contents of edit3 as a
double

% --- Executes during object creation, after setting all properties.


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text


% str2double(get(hObject,'String')) returns contents of edit4 as a
double

% --- Executes during object creation, after setting all properties.


function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a
double

% --- Executes during object creation, after setting all properties.


function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a
double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a
double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit8_Callback(hObject, eventdata, handles)


% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text


% str2double(get(hObject,'String')) returns contents of edit8 as a
double

% --- Executes during object creation, after setting all properties.


function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit9_Callback(hObject, eventdata, handles)
% hObject handle to edit9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text


% str2double(get(hObject,'String')) returns contents of edit9 as a
double

% --- Executes during object creation, after setting all properties.


function edit9_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit10_Callback(hObject, eventdata, handles)


% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit10 as text


% str2double(get(hObject,'String')) returns contents of edit10 as a
double

% --- Executes during object creation, after setting all properties.


function edit10_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit11_Callback(hObject, eventdata, handles)


% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit11 as text


% str2double(get(hObject,'String')) returns contents of edit11 as a
double

% --- Executes during object creation, after setting all properties.


function edit11_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

Analysis.m

function edit12_Callback(hObject, eventdata, handles)


% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit12 as text


% str2double(get(hObject,'String')) returns contents of edit12 as a
double

% --- Executes during object creation, after setting all properties.


function edit12_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit13_Callback(hObject, eventdata, handles)


% hObject handle to edit13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit13 as text
% str2double(get(hObject,'String')) returns contents of edit13 as a
double

% --- Executes during object creation, after setting all properties.


function edit13_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load Trainset.mat
load Normalized_Features.mat
ConvAnn
CNN

Data.m

function [ Unow, CNTR, now_obj_fcn ] = SUB_FUN8( INP_IMG, N_CLTR )

if nargin < 2
N_CLTR = 2;
end

[row, col] = size(INP_IMG);


E_N = 2;
EPLN_VL = 0.001;
MX_ITR = 100;

UP_VAL = rand(row, col, N_CLTR);


DEP_SUM = sum(UP_VAL, 3);
DEP_SUM = repmat(DEP_SUM, [1,1, N_CLTR]);
UP_VAL = UP_VAL./DEP_SUM;
CNTR = zeros(N_CLTR,1);

for i=1:N_CLTR
CNTR(i,1) = sum(sum(UP_VAL(:,:,i).*INP_IMG))/sum(sum(UP_VAL(:,:,i)));
end

pre_obj_fcn = 0;
for i=1:N_CLTR
pre_obj_fcn = pre_obj_fcn + sum(sum((UP_VAL(:,:,i) .*INP_IMG -
CNTR(i)).^2));
end
fprintf('Initial objective fcn = %f\n', pre_obj_fcn);

for ITR = 1:MX_ITR

Unow = zeros(size(UP_VAL));
for i=1:row
for j=1:col
for uII = 1:N_CLTR
tmp = 0;
for uJJ = 1:N_CLTR
disUp = abs(INP_IMG(i,j) - CNTR(uII));
disDn = abs(INP_IMG(i,j) - CNTR(uJJ));
tmp = tmp + (disUp/disDn).^(2/(E_N-1));
end
Unow(i,j, uII) = 1/(tmp);
end
end
end

now_obj_fcn = 0;
for i=1:N_CLTR
now_obj_fcn = now_obj_fcn + sum(sum((Unow(:,:,i) .*INP_IMG -
CNTR(i)).^2));
end
fprintf('Iter = %d, Objective = %f\n', ITR, now_obj_fcn);

if max(max(max(abs(Unow-UP_VAL))))<EPLN_VL || abs(now_obj_fcn -
pre_obj_fcn)<EPLN_VL %ÒýÈë2¸öÅж¨
break;
else
UP_VAL = Unow.^E_N;
for i=1:N_CLTR
CNTR(i,1) =
sum(sum(UP_VAL(:,:,i).*INP_IMG))/sum(sum(UP_VAL(:,:,i)));
end
pre_obj_fcn = now_obj_fcn;
end
end

You might also like