Segmentasi citra MRI dengan metode Active Contour


Berikut ini merupakan pemrograman GUI Matlab untuk mensegmentasi citra kepala hasil pemindaian Magnetic Resonance Imaging (MRI). Metode segmentasi citra yang digunakan adalah active contour. Pada contoh ini digunakan citra kepala MRI yang ada pada Matlab yang terdiri dari 27 slice tampang axial. Slice citra tersebut kemudian ditransformasi menjadi tampang sagittal dan coronal menggunakan transformasi Radon sehingga diperoleh 35 slice tampang sagittal, dan 45 slice tampang coronal. Hasil konturing dengan metode active contour kemudian direkonstruksi bersama slice citra pada masing-masing tampang dan divisualisasikan secara 3 dimensi.
Source code GUI Matlab untuk segmentasi citra MRI dengan metode active contour dapat diunduh melalui link berikut: link

Sedangkan tampilan kodingnya adalah:

function varargout = mri_image_processing(varargin)
% MRI_IMAGE_PROCESSING MATLAB code for mri_image_processing.fig
%      MRI_IMAGE_PROCESSING, by itself, creates a new MRI_IMAGE_PROCESSING or raises the existing
%      singleton*.
%
%      H = MRI_IMAGE_PROCESSING returns the handle to a new MRI_IMAGE_PROCESSING or the handle to
%      the existing singleton*.
%
%      MRI_IMAGE_PROCESSING('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MRI_IMAGE_PROCESSING.M with the given input arguments.
%
%      MRI_IMAGE_PROCESSING('Property','Value',...) creates a new MRI_IMAGE_PROCESSING or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before mri_image_processing_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to mri_image_processing_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 mri_image_processing

% Last Modified by GUIDE v2.5 03-Apr-2014 22:01:27

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @mri_image_processing_OpeningFcn, ...
                   'gui_OutputFcn',  @mri_image_processing_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 mri_image_processing is made visible.
function mri_image_processing_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 mri_image_processing (see VARARGIN)

% Choose default command line output for mri_image_processing
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
movegui(hObject, 'north');

% UIWAIT makes mri_image_processing wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = mri_image_processing_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)
image_num = str2double(get(handles.edit1,'string'));

if image_num > 1
    image_num = image_num-1;
else
    image_num = 1;
end

load mri
D = squeeze(D);

load horizontal
axes(handles.axes1);
image(D(:,:,image_num)+horizontal(:,:,image_num));
axis image;
colormap(map);
set(handles.edit1, 'string', image_num);

handles.D = D(:,:,image_num);
guidata(hObject, handles)


% --- 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)
image_num = str2double(get(handles.edit1,'string'));

if image_num < 27
    image_num = image_num+1;
else
    image_num = 27;
end

load mri
D = squeeze(D);

load horizontal
axes(handles.axes1);
image(D(:,:,image_num)+horizontal(:,:,image_num));
axis image;
colormap(map);
set(handles.edit1, 'string', image_num);

handles.D = D(:,:,image_num);
guidata(hObject, handles)


% --- 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)
image_num = str2double(get(handles.edit2,'string'));

if image_num > 1
    image_num = image_num-1;
else
    image_num = 1;
end

load mri
R3 = makeresampler({'cubic','nearest','nearest'},'fill');
T3 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 0.5; 68.5 0 -14]);
S = tformarray(D,T3,R3,[4 1 2],[1 2 4],[66 128 35],[],0);
S2 = padarray(S,[6 0 0 0],0,'both');
S2 = squeeze(S2);

axes(handles.axes4);
imagesc(S2(:,:,image_num));
axis image;
colormap(map);
set(handles.edit2, 'string', image_num);

handles.S2 = S2(:,:,image_num);
guidata(hObject, handles)


% --- 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)
image_num = str2double(get(handles.edit2,'string'));

if image_num < 35
    image_num = image_num+1;
else
    image_num = 35;
end

load mri
R3 = makeresampler({'cubic','nearest','nearest'},'fill');
T3 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 0.5; 68.5 0 -14]);
S = tformarray(D,T3,R3,[4 1 2],[1 2 4],[66 128 35],[],0);
S2 = padarray(S,[6 0 0 0],0,'both');
S2 = squeeze(S2);

axes(handles.axes4);
imagesc(S2(:,:,image_num));
axis image;
colormap(map);
set(handles.edit2, 'string', image_num);

handles.S2 = S2(:,:,image_num);
guidata(hObject, handles)


% --- 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)
image_num = str2double(get(handles.edit3,'string'));

if image_num > 1
    image_num = image_num-1;
else
    image_num = 1;
end

load mri
R3 = makeresampler({'cubic','nearest','nearest'},'fill');
T4 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 -0.5; 68.5 0 61]);
C = tformarray(D,T4,R3,[4 2 1],[1 2 4],[66 128 45],[],0);
C2 = padarray(C,[6 0 0 0],0,'both');
C2 = squeeze(C2);

axes(handles.axes7);
imagesc(C2(:,:,image_num));
axis image;
colormap(map);
set(handles.edit3, 'string', image_num);

handles.C2 = C2(:,:,image_num);
guidata(hObject, handles)


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
image_num = str2double(get(handles.edit3,'string'));

if image_num < 45
    image_num = image_num+1;
else
    image_num = 45;
end

load mri
R3 = makeresampler({'cubic','nearest','nearest'},'fill');
T4 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 -0.5; 68.5 0 61]);
C = tformarray(D,T4,R3,[4 2 1],[1 2 4],[66 128 45],[],0);
C2 = padarray(C,[6 0 0 0],0,'both');
C2 = squeeze(C2);

axes(handles.axes7);
imagesc(C2(:,:,image_num));
axis image;
colormap(map);
set(handles.edit3, 'string', image_num);

handles.C2 = C2(:,:,image_num);
guidata(hObject, handles)


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
load mri.mat
D = squeeze(D);
hold on
axes(handles.axes3);
vol3d('cdata',D,'texture','3D');
colormap(map);
view(3);  
axis off;  daspect([1 1 .4])
alphamap('rampup');
alphamap(.04 .* alphamap);
xlim([0 128])
ylim([0 128])
zlim([0 27])
hold on


% --- 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)


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 uipushtool1_ClickedCallback(hObject, eventdata, handles)
% hObject    handle to uipushtool1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

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

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

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

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

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

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

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

% --------------------------------------------------------------------
function uipushtool9_ClickedCallback(hObject, eventdata, handles)
% hObject    handle to uipushtool9 (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 pushbutton15.

function pushbutton15_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
D = handles.D;
axes(handles.axes1)
h = imrect;
mask = createMask(h);
bw = activecontour(D,mask,300);

axes(handles.axes2)
imagesc(D);
axis image
hold on
[c,~] = bwboundaries(bw,'noholes');
for k = 1:length(c)
    boundary = c{k};
    plot(boundary(:,2), boundary(:,1),'LineWidth',3)
end
hold off

hold on
axes(handles.axes3)
x1 = boundary(:,2)';
y1 = boundary(:,1)';
image_num = str2double(get(handles.edit1,'String'));
z1 = ones(length(x1)+1,1);
x = cat(1,x1',x1(1,1));
y = cat(1,y1',y1(1,1));
z1(:) = image_num;
z = z1;
plot3(x,y,z,'LineWidth',3)
axis off;  daspect([1 1 .4])
xlim([0 128])
ylim([0 128])
zlim([0 27])
hold on


% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton16 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
D = handles.D;
axes(handles.axes1)
h = imellipse;
mask = createMask(h);
bw = activecontour(D,mask,300);

axes(handles.axes2)
imagesc(D);
axis image
hold on
[c,~] = bwboundaries(bw,'noholes');

for k = 1:length(c)
    boundary = c{k};
    plot(boundary(:,2), boundary(:,1),'LineWidth',3)
end
hold off

hold on
axes(handles.axes3)
x1 = boundary(:,2)';
y1 = boundary(:,1)';
image_num = str2double(get(handles.edit1,'String'));
z1 = ones(length(x1)+1,1);
x = cat(1,x1',x1(1,1));
y = cat(1,y1',y1(1,1));
z1(:) = image_num;
z = z1;
plot3(x,y,z,'LineWidth',3)
axis off;  daspect([1 1 .4])
xlim([0 128])
ylim([0 128])
zlim([0 27])
hold on


% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton17 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
D = handles.D;
axes(handles.axes1)
h = impoly;
mask = createMask(h);
bw = activecontour(D,mask,300);
  
axes(handles.axes2)
imagesc(D);
axis image
hold on
[c,~] = bwboundaries(bw,'noholes');
for k = 1:length(c)
    boundary = c{k};
    plot(boundary(:,2), boundary(:,1),'LineWidth',3)
end
hold off

hold on
axes(handles.axes3)
x1 = boundary(:,2)';
y1 = boundary(:,1)';
image_num = str2double(get(handles.edit1,'String'));
z1 = ones(length(x1)+1,1);
x = cat(1,x1',x1(1,1));
y = cat(1,y1',y1(1,1));
z1(:) = image_num;
z = z1;
plot3(x,y,z,'LineWidth',3)
axis off;  daspect([1 1 .4])
xlim([0 128])
ylim([0 128])
zlim([0 27])
hold on


% --- Executes on button press in pushbutton18.
function pushbutton18_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton18 (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 pushbutton19.
function pushbutton19_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton19 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
S2 = handles.S2;
axes(handles.axes4)
h = imrect;
setColor(h,'g')
mask = createMask(h);
bw = activecontour(S2,mask,300);

axes(handles.axes5)
imagesc(S2);
axis image
hold on
[c,~] = bwboundaries(bw,'noholes');
for k = 1:length(c)
    boundary = c{k};
    plot(boundary(:,2), boundary(:,1),'g','LineWidth',3)
end
hold off

hold on
axes(handles.axes6)
x1 = boundary(:,2)';
y1 = boundary(:,1)';
image_num = str2double(get(handles.edit2,'String'));
z1 = ones(length(x1)+1,1);
x = cat(1,x1',x1(1,1));
y = cat(1,y1',y1(1,1));
z1(:) = image_num;
z = z1;
plot3(x,y,z,'g','LineWidth',3)
axis off;  daspect([1 1 .4])
xlim([0 128])
ylim([0 128])
zlim([0 35])
hold on


% --- Executes on button press in pushbutton20.
function pushbutton20_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton20 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
S2 = handles.S2;
axes(handles.axes4)
h = imellipse;
setColor(h,'g')
mask = createMask(h);
bw = activecontour(S2,mask,300);

axes(handles.axes5)
imagesc(S2);
axis image
hold on
[c,~] = bwboundaries(bw,'noholes');
for k = 1:length(c)
    boundary = c{k};
    plot(boundary(:,2), boundary(:,1),'g','LineWidth',3)
end
hold off

hold on
axes(handles.axes6)
x1 = boundary(:,2)';
y1 = boundary(:,1)';
image_num = str2double(get(handles.edit2,'String'));
z1 = ones(length(x1)+1,1);
x = cat(1,x1',x1(1,1));
y = cat(1,y1',y1(1,1));
z1(:) = image_num;
z = z1;
plot3(x,y,z,'g','LineWidth',3)
axis off;  daspect([1 1 .4])
xlim([0 128])
ylim([0 128])
zlim([0 35])
hold on

% --- Executes on button press in pushbutton21.
function pushbutton21_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton21 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
S2 = handles.S2;
axes(handles.axes4)
h = impoly;
setColor(h,'g')
mask = createMask(h);
bw = activecontour(S2,mask,300);
  
axes(handles.axes5)
imagesc(S2);
axis image
hold on
[c,~] = bwboundaries(bw,'noholes');
for k = 1:length(c)
    boundary = c{k};
    plot(boundary(:,2), boundary(:,1),'g','LineWidth',3)
end
hold off

hold on
axes(handles.axes6)
x1 = boundary(:,2)';
y1 = boundary(:,1)';
image_num = str2double(get(handles.edit2,'String'));
z1 = ones(length(x1)+1,1);
x = cat(1,x1',x1(1,1));
y = cat(1,y1',y1(1,1));
z1(:) = image_num;
z = z1;
plot3(x,y,z,'g','LineWidth',3)
axis off;  daspect([1 1 .4])
xlim([0 128])
ylim([0 128])
zlim([0 35])
hold on


% --- Executes on button press in pushbutton22.
function pushbutton22_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton22 (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 pushbutton23.
function pushbutton23_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton23 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
C2 = handles.C2;
axes(handles.axes7)
h = imrect;
setColor(h,'r')
mask = createMask(h);
bw = activecontour(C2,mask,300);

axes(handles.axes8)
imagesc(C2);
axis image
hold on
[c,~] = bwboundaries(bw,'noholes');
for k = 1:length(c)
    boundary = c{k};
    plot(boundary(:,2), boundary(:,1),'r','LineWidth',3)
end
hold off

hold on
axes(handles.axes9)
x1 = boundary(:,2)';
y1 = boundary(:,1)';
image_num = str2double(get(handles.edit3,'String'));
z1 = ones(length(x1)+1,1);
x = cat(1,x1',x1(1,1));
y = cat(1,y1',y1(1,1));
z1(:) = image_num;
z = z1;
plot3(x,y,z,'r','LineWidth',3)
axis off;  daspect([1 1 .4])
xlim([0 128])
ylim([0 128])
zlim([0 45])
hold on


% --- Executes on button press in pushbutton24.
function pushbutton24_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton24 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
C2 = handles.C2;
axes(handles.axes7)
h = imellipse;
setColor(h,'r')
mask = createMask(h);
bw = activecontour(C2,mask,300);

axes(handles.axes8)
imagesc(C2);
axis image
hold on
[c,~] = bwboundaries(bw,'noholes');
for k = 1:length(c)
    boundary = c{k};
    plot(boundary(:,2), boundary(:,1),'r','LineWidth',3)
end
hold off

hold on
axes(handles.axes9)
x1 = boundary(:,2)';
y1 = boundary(:,1)';
image_num = str2double(get(handles.edit3,'String'));
z1 = ones(length(x1)+1,1);
x = cat(1,x1',x1(1,1));
y = cat(1,y1',y1(1,1));
z1(:) = image_num;
z = z1;
plot3(x,y,z,'r','LineWidth',3)
axis off;  daspect([1 1 .4])
xlim([0 128])
ylim([0 128])
zlim([0 45])
hold on


% --- Executes on button press in pushbutton25.
function pushbutton25_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton25 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
C2 = handles.C2;
axes(handles.axes7)
h = impoly;
setColor(h,'r')
mask = createMask(h);
bw = activecontour(C2,mask,300);
  
axes(handles.axes8)
imagesc(C2);
axis image
hold on
[c,~] = bwboundaries(bw,'noholes');
for k = 1:length(c)
    boundary = c{k};
    plot(boundary(:,2), boundary(:,1),'r','LineWidth',3)
end
hold off

hold on
axes(handles.axes9)
x1 = boundary(:,2)';
y1 = boundary(:,1)';
image_num = str2double(get(handles.edit3,'String'));
z1 = ones(length(x1)+1,1);
x = cat(1,x1',x1(1,1));
y = cat(1,y1',y1(1,1));
z1(:) = image_num;
z = z1;
plot3(x,y,z,'r','LineWidth',3)
axis off;  daspect([1 1 .4])
xlim([0 128])
ylim([0 128])
zlim([0 45])
hold on

% --- Executes on button press in pushbutton26.
function pushbutton26_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton26 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes during object creation, after setting all properties.
function pushbutton2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
buttonIm = imread('up.png');
set(hObject,'cdata',buttonIm,'string', '');


% --- Executes during object creation, after setting all properties.
function pushbutton1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
buttonIm = imread('down.png');
set(hObject,'cdata',buttonIm,'string', '');


% --- Executes during object creation, after setting all properties.
function pushbutton4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
buttonIm = imread('up.png');
set(hObject,'cdata',buttonIm,'string', '');


% --- Executes during object creation, after setting all properties.
function pushbutton3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
buttonIm = imread('down.png');
set(hObject,'cdata',buttonIm,'string', '');


% --- Executes during object creation, after setting all properties.
function pushbutton6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
buttonIm = imread('up.png');
set(hObject,'cdata',buttonIm,'string', '');


% --- Executes during object creation, after setting all properties.
function pushbutton5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
buttonIm = imread('down.png');
set(hObject,'cdata',buttonIm,'string', '');


% --- Executes during object creation, after setting all properties.
function pushbutton15_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes on button press in pushbutton27.
function pushbutton27_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton27 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
load mri
R3 = makeresampler({'cubic','nearest','nearest'},'fill');
T3 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 0.5; 68.5 0 -14]);
S = tformarray(D,T3,R3,[4 1 2],[1 2 4],[66 128 35],[],0);
S2 = padarray(S,[6 0 0 0],0,'both');
S2 = squeeze(S2);
hold on
axes(handles.axes6);
vol3d('cdata',S2,'texture','3D');
colormap(map);
view(3);  
axis off;  daspect([1 1 .4])
alphamap('rampup');
alphamap(.04 .* alphamap);
xlim([0 128])
ylim([0 128])
zlim([0 35])
hold on

% --- Executes on button press in pushbutton28.
function pushbutton28_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton28 (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 pushbutton29.
function pushbutton29_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton29 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
load mri
R3 = makeresampler({'cubic','nearest','nearest'},'fill');
T4 = maketform('affine',[-2.5 0 0; 0 1 0; 0 0 -0.5; 68.5 0 61]);
C = tformarray(D,T4,R3,[4 2 1],[1 2 4],[66 128 45],[],0);
C2 = padarray(C,[6 0 0 0],0,'both');
C2 = squeeze(C2);
hold on
axes(handles.axes9);
vol3d('cdata',C2,'texture','3D');
colormap(map);
view(3);  
axis off;  daspect([1 1 .4])
alphamap('rampup');
alphamap(.04 .* alphamap);
xlim([0 128])
ylim([0 128])
zlim([0 45])
hold on

% --- Executes on button press in pushbutton30.
function pushbutton30_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton30 (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 togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton1
if isequal(get(hObject,'Value'),1)
    rotate3d(handles.axes3,'on');
else
    rotate3d(handles.axes3,'off');
end


% --- Executes on button press in togglebutton2.
function togglebutton2_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton2
if isequal(get(hObject,'Value'),1)
    rotate3d(handles.axes6,'on');
else
    rotate3d(handles.axes6,'off');
end


% --- Executes on button press in togglebutton3.
function togglebutton3_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton3
if isequal(get(hObject,'Value'),1)
    rotate3d(handles.axes9,'on');
else
    rotate3d(handles.axes9,'off');
end

Save

Save

Save

Posted on October 29, 2013, in Pengenalan Matlab, Pengolahan Citra and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: