Segmentasi citra MRI dengan metode Active Contour
Berikut ini merupakan contoh aplikasi 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.
File source code GUI Matlab lengkap beserta citra untuk segmentasi citra MRI dengan metode active contour dapat diperoleh melalui halaman berikut ini: Source Code
Sedangkan tampilan kodingnya adalah:
1. Tampang aksial:
function varargout = axial_mri_image_processing(varargin) % AXIAL_MRI_IMAGE_PROCESSING MATLAB code for axial_mri_image_processing.fig % AXIAL_MRI_IMAGE_PROCESSING, by itself, creates a new AXIAL_MRI_IMAGE_PROCESSING or raises the existing % singleton*. % % H = AXIAL_MRI_IMAGE_PROCESSING returns the handle to a new AXIAL_MRI_IMAGE_PROCESSING or the handle to % the existing singleton*. % % AXIAL_MRI_IMAGE_PROCESSING('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in AXIAL_MRI_IMAGE_PROCESSING.M with the given input arguments. % % AXIAL_MRI_IMAGE_PROCESSING('Property','Value',...) creates a new AXIAL_MRI_IMAGE_PROCESSING or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before axial_mri_image_processing_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to axial_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 axial_mri_image_processing % Last Modified by GUIDE v2.5 01-Jun-2017 19:10:07 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @axial_mri_image_processing_OpeningFcn, ... 'gui_OutputFcn', @axial_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 axial_mri_image_processing is made visible. function axial_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 axial_mri_image_processing (see VARARGIN) % Choose default command line output for axial_mri_image_processing handles.output = hObject; movegui(hObject,'center'); load mri D = squeeze(D); axes(handles.axes1); image(D(:,:,1)); axis off; colormap(map); handles.D = D(:,:,1); % Update handles structure guidata(hObject, handles); % UIWAIT makes axial_mri_image_processing wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = axial_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); axes(handles.axes1); image(D(:,:,image_num)); axis off; 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); axes(handles.axes1); image(D(:,:,image_num)); axis off; colormap(map); set(handles.edit1, 'string', image_num); handles.D = D(:,:,image_num); guidata(hObject, handles) 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 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) radio1 = get(handles.radiobutton1,'Value'); radio2 = get(handles.radiobutton2,'Value'); radio3 = get(handles.radiobutton3,'Value'); load mri try if radio1 == 1 D = handles.D; axes(handles.axes1) cla reset image(D); axis off colormap(map) h = imrect; setColor(h,'b') mask = createMask(h); delete(h); bw = activecontour(D,mask,300); axes(handles.axes1) cla reset image(D); axis off hold on [c,~] = bwboundaries(bw,'noholes'); for k = 1:length(c) boundary = c{k}; plot(boundary(:,2), boundary(:,1),'b','LineWidth',3) end hold off load mri D = squeeze(D); hold on axes(handles.axes2); vol3d('cdata',D,'texture','3D'); colormap(map); view(3); axis off; daspect([1 1 .4]) alphamap('rampup'); alphamap(.2 .* alphamap); xlim([0 128]) ylim([0 128]) zlim([0 27]) hold on axes(handles.axes2) 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,'b','LineWidth',3) axis off; daspect([1 1 .4]) xlim([0 128]) ylim([0 128]) zlim([0 27]) hold on elseif radio2 == 1 D = handles.D; axes(handles.axes1) cla reset image(D); axis off colormap(map) h = imellipse; setColor(h,'b') mask = createMask(h); delete(h); bw = activecontour(D,mask,300); axes(handles.axes1) cla reset image(D); axis off hold on [c,~] = bwboundaries(bw,'noholes'); for k = 1:length(c) boundary = c{k}; plot(boundary(:,2), boundary(:,1),'b','LineWidth',3) end hold off load mri D = squeeze(D); hold on axes(handles.axes2); vol3d('cdata',D,'texture','3D'); colormap(map); view(3); axis off; daspect([1 1 .4]) alphamap('rampup'); alphamap(.2 .* alphamap); xlim([0 128]) ylim([0 128]) zlim([0 27]) hold on axes(handles.axes2) 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,'b','LineWidth',3) axis off; daspect([1 1 .4]) xlim([0 128]) ylim([0 128]) zlim([0 27]) hold on elseif radio3 == 1 D = handles.D; axes(handles.axes1) cla reset image(D); axis off colormap(map) h = impoly; setColor(h,'b') mask = createMask(h); delete(h); bw = activecontour(D,mask,300); axes(handles.axes1) cla reset image(D); axis off hold on [c,~] = bwboundaries(bw,'noholes'); for k = 1:length(c) boundary = c{k}; plot(boundary(:,2), boundary(:,1),'b','LineWidth',3) end hold off load mri D = squeeze(D); hold on axes(handles.axes2); vol3d('cdata',D,'texture','3D'); colormap(map); view(3); axis off; daspect([1 1 .4]) alphamap('rampup'); alphamap(.2 .* alphamap); xlim([0 128]) ylim([0 128]) zlim([0 27]) hold on axes(handles.axes2) 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,'b','LineWidth',3) axis off; daspect([1 1 .4]) xlim([0 128]) ylim([0 128]) zlim([0 27]) hold on end catch return 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) set(handles.edit1,'String',1) set(handles.radiobutton1,'Value',1) set(handles.radiobutton2,'Value',0) set(handles.radiobutton3,'Value',0) axes(handles.axes1) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) axes(handles.axes2) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) load mri D = squeeze(D); axes(handles.axes1); image(D(:,:,1)); axis off; colormap(map); % --- Executes on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (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 radiobutton1 set(hObject,'Value',1) set(handles.radiobutton2,'Value',0) set(handles.radiobutton3,'Value',0) % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (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 radiobutton2 set(hObject,'Value',1) set(handles.radiobutton1,'Value',0) set(handles.radiobutton3,'Value',0) % --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (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 radiobutton3 set(hObject,'Value',1) set(handles.radiobutton1,'Value',0) set(handles.radiobutton2,'Value',0) % --- 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.axes2,'on'); set(hObject,'String','Rotate off') else rotate3d(handles.axes2,'off'); set(hObject,'String','Rotate on') end % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all; guidata(sagittal_mri_image_processing); % -------------------------------------------------------------------- function Untitled_2_Callback(hObject, eventdata, handles) % hObject handle to Untitled_2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all; guidata(coronal_mri_image_processing);
2. Tampang Sagittal
function varargout = sagittal_mri_image_processing(varargin) % SAGITTAL_MRI_IMAGE_PROCESSING MATLAB code for sagittal_mri_image_processing.fig % SAGITTAL_MRI_IMAGE_PROCESSING, by itself, creates a new SAGITTAL_MRI_IMAGE_PROCESSING or raises the existing % singleton*. % % H = SAGITTAL_MRI_IMAGE_PROCESSING returns the handle to a new SAGITTAL_MRI_IMAGE_PROCESSING or the handle to % the existing singleton*. % % SAGITTAL_MRI_IMAGE_PROCESSING('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SAGITTAL_MRI_IMAGE_PROCESSING.M with the given input arguments. % % SAGITTAL_MRI_IMAGE_PROCESSING('Property','Value',...) creates a new SAGITTAL_MRI_IMAGE_PROCESSING or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before sagittal_mri_image_processing_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to sagittal_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 sagittal_mri_image_processing % Last Modified by GUIDE v2.5 01-Jun-2017 19:09:07 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @sagittal_mri_image_processing_OpeningFcn, ... 'gui_OutputFcn', @sagittal_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 sagittal_mri_image_processing is made visible. function sagittal_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 sagittal_mri_image_processing (see VARARGIN) % Choose default command line output for sagittal_mri_image_processing handles.output = hObject; movegui(hObject,'center'); 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'); axes(handles.axes1); image(S2(:,:,1)); axis off; colormap(map); handles.S2 = S2(:,:,1); guidata(hObject, handles) % Update handles structure guidata(hObject, handles); % UIWAIT makes sagittal_mri_image_processing wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = sagittal_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 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'); axes(handles.axes1); image(S2(:,:,image_num)); axis off; colormap(map); set(handles.edit1, 'string', image_num); handles.S2 = S2(:,:,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 < 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'); axes(handles.axes1); image(S2(:,:,image_num)); axis off; colormap(map); set(handles.edit1, 'string', image_num); handles.S2 = S2(:,:,image_num); guidata(hObject, handles) 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 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) radio1 = get(handles.radiobutton1,'Value'); radio2 = get(handles.radiobutton2,'Value'); radio3 = get(handles.radiobutton3,'Value'); load mri try if radio1 == 1 S2 = handles.S2; axes(handles.axes1) cla reset image(S2); axis off colormap(map) h = imrect; setColor(h,'g') mask = createMask(h); delete(h); bw = activecontour(S2,mask,300); axes(handles.axes1) cla reset image(S2); axis off 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 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.axes2); vol3d('cdata',S2,'texture','3D'); colormap(map); view(3); axis off; daspect([1 1 .4]) alphamap('rampup'); alphamap(.2 .* alphamap); xlim([0 128]) ylim([0 128]) zlim([0 35]) hold on axes(handles.axes2) 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,'g','LineWidth',3) axis off; daspect([1 1 .4]) xlim([0 128]) ylim([0 128]) zlim([0 35]) hold on elseif radio2 == 1 S2 = handles.S2; axes(handles.axes1) cla reset image(S2); axis off colormap(map) h = imellipse; setColor(h,'g') mask = createMask(h); delete(h); bw = activecontour(S2,mask,300); axes(handles.axes1) cla reset image(S2); axis off 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 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.axes2); vol3d('cdata',S2,'texture','3D'); colormap(map); view(3); axis off; daspect([1 1 .4]) alphamap('rampup'); alphamap(.2 .* alphamap); xlim([0 128]) ylim([0 128]) zlim([0 35]) hold on axes(handles.axes2) 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,'g','LineWidth',3) axis off; daspect([1 1 .4]) xlim([0 128]) ylim([0 128]) zlim([0 35]) hold on elseif radio3 == 1 S2 = handles.S2; axes(handles.axes1) cla reset image(S2); axis off colormap(map) h = impoly; setColor(h,'g') mask = createMask(h); delete(h); bw = activecontour(S2,mask,300); axes(handles.axes1) cla reset image(S2); axis off 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 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.axes2); vol3d('cdata',S2,'texture','3D'); colormap(map); view(3); axis off; daspect([1 1 .4]) alphamap('rampup'); alphamap(.2 .* alphamap); xlim([0 128]) ylim([0 128]) zlim([0 35]) hold on axes(handles.axes2) 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,'g','LineWidth',3) axis off; daspect([1 1 .4]) xlim([0 128]) ylim([0 128]) zlim([0 35]) hold on end catch return 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) set(handles.edit1,'String',1) set(handles.radiobutton1,'Value',1) set(handles.radiobutton2,'Value',0) set(handles.radiobutton3,'Value',0) axes(handles.axes1) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) axes(handles.axes2) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) load mri axes(handles.axes1); 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'); image(S2(:,:,1)); axis off; colormap(map); % --- Executes on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (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 radiobutton1 set(hObject,'Value',1) set(handles.radiobutton2,'Value',0) set(handles.radiobutton3,'Value',0) % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (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 radiobutton2 set(hObject,'Value',1) set(handles.radiobutton1,'Value',0) set(handles.radiobutton3,'Value',0) % --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (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 radiobutton3 set(hObject,'Value',1) set(handles.radiobutton1,'Value',0) set(handles.radiobutton2,'Value',0) % --- 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.axes2,'on'); set(hObject,'String','Rotate off') else rotate3d(handles.axes2,'off'); set(hObject,'String','Rotate on') end % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all; guidata(axial_mri_image_processing); % -------------------------------------------------------------------- function Untitled_2_Callback(hObject, eventdata, handles) % hObject handle to Untitled_2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all; guidata(coronal_mri_image_processing);
3. Tampang Coronal
function varargout = coronal_mri_image_processing(varargin) % CORONAL_MRI_IMAGE_PROCESSING MATLAB code for coronal_mri_image_processing.fig % CORONAL_MRI_IMAGE_PROCESSING, by itself, creates a new CORONAL_MRI_IMAGE_PROCESSING or raises the existing % singleton*. % % H = CORONAL_MRI_IMAGE_PROCESSING returns the handle to a new CORONAL_MRI_IMAGE_PROCESSING or the handle to % the existing singleton*. % % CORONAL_MRI_IMAGE_PROCESSING('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in CORONAL_MRI_IMAGE_PROCESSING.M with the given input arguments. % % CORONAL_MRI_IMAGE_PROCESSING('Property','Value',...) creates a new CORONAL_MRI_IMAGE_PROCESSING or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before coronal_mri_image_processing_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to coronal_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 coronal_mri_image_processing % Last Modified by GUIDE v2.5 01-Jun-2017 19:07:47 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @coronal_mri_image_processing_OpeningFcn, ... 'gui_OutputFcn', @coronal_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 coronal_mri_image_processing is made visible. function coronal_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 coronal_mri_image_processing (see VARARGIN) % Choose default command line output for coronal_mri_image_processing handles.output = hObject; movegui(hObject,'center'); 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.axes1); image(C2(:,:,1)); axis off; colormap(map); handles.C2 = C2(:,:,1); guidata(hObject, handles) % Update handles structure guidata(hObject, handles); % UIWAIT makes coronal_mri_image_processing wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = coronal_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 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.axes1); image(C2(:,:,image_num)); axis off; colormap(map); set(handles.edit1, 'string', image_num); handles.C2 = C2(:,:,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 < 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.axes1); image(C2(:,:,image_num)); axis off; colormap(map); set(handles.edit1, 'string', image_num); handles.C2 = C2(:,:,image_num); guidata(hObject, handles) 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 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) radio1 = get(handles.radiobutton1,'Value'); radio2 = get(handles.radiobutton2,'Value'); radio3 = get(handles.radiobutton3,'Value'); load mri try if radio1 == 1 C2 = handles.C2; axes(handles.axes1) cla reset image(C2); axis off colormap(map) h = imrect; setColor(h,'r') mask = createMask(h); delete(h); bw = activecontour(C2,mask,300); axes(handles.axes1) cla reset image(C2); axis off 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 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.axes2); vol3d('cdata',C2,'texture','3D'); colormap(map); view(3); axis off; daspect([1 1 .5]) alphamap('rampup'); alphamap(.2 .* alphamap); xlim([0 128]) ylim([0 128]) zlim([0 45]) hold on axes(handles.axes2) 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,'r','LineWidth',3) axis off; daspect([1 1 .5]) xlim([0 128]) ylim([0 128]) zlim([0 45]) hold on elseif radio2 == 1 C2 = handles.C2; axes(handles.axes1) cla reset image(C2); axis off colormap(map) h = imellipse; setColor(h,'r') mask = createMask(h); delete(h); bw = activecontour(C2,mask,300); axes(handles.axes1) cla reset image(C2); axis off 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 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.axes2); vol3d('cdata',C2,'texture','3D'); colormap(map); view(3); axis off; daspect([1 1 .5]) alphamap('rampup'); alphamap(.2 .* alphamap); xlim([0 128]) ylim([0 128]) zlim([0 45]) hold on axes(handles.axes2) 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,'r','LineWidth',3) axis off; daspect([1 1 .5]) xlim([0 128]) ylim([0 128]) zlim([0 45]) hold on elseif radio3 == 1 C2 = handles.C2; axes(handles.axes1) cla reset image(C2); axis off colormap(map) h = impoly; setColor(h,'r') mask = createMask(h); delete(h); bw = activecontour(C2,mask,300); axes(handles.axes1) cla reset image(C2); axis off 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 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.axes2); vol3d('cdata',C2,'texture','3D'); colormap(map); view(3); axis off; daspect([1 1 .5]) alphamap('rampup'); alphamap(.2 .* alphamap); xlim([0 128]) ylim([0 128]) zlim([0 45]) hold on axes(handles.axes2) 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,'r','LineWidth',3) axis off; daspect([1 1 .5]) xlim([0 128]) ylim([0 128]) zlim([0 45]) hold on end catch return 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) set(handles.edit1,'String',1) set(handles.radiobutton1,'Value',1) set(handles.radiobutton2,'Value',0) set(handles.radiobutton3,'Value',0) axes(handles.axes1) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) axes(handles.axes2) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) load mri axes(handles.axes1); 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); image(C2(:,:,1)); axis off; colormap(map); % --- Executes on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (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 radiobutton1 set(hObject,'Value',1) set(handles.radiobutton2,'Value',0) set(handles.radiobutton3,'Value',0) % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (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 radiobutton2 set(hObject,'Value',1) set(handles.radiobutton1,'Value',0) set(handles.radiobutton3,'Value',0) % --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (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 radiobutton3 set(hObject,'Value',1) set(handles.radiobutton1,'Value',0) set(handles.radiobutton2,'Value',0) % --- 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.axes2,'on'); set(hObject,'String','Rotate off') else rotate3d(handles.axes2,'off'); set(hObject,'String','Rotate on') end % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all; guidata(axial_mri_image_processing); % -------------------------------------------------------------------- function Untitled_2_Callback(hObject, eventdata, handles) % hObject handle to Untitled_2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all; guidata(sagittal_mri_image_processing);
Penerapan metode active contour untuk segmentasi citra thorax dapat dilihat pada video berikut ini:

Posted on October 29, 2013, in Pengenalan Matlab, Pengolahan Citra and tagged active contour menggunakan matlab, cara segmentasi citra matlab, citra aksial matlab, citra axial sagittal coronal matlab, citra coronal matlab, citra medis 3D matlab, citra MRI Matlab, citra sagittal matlab, contoh segmentasi citra matlab, gui matlab segmentasi citra, MRI image processing matlab, pengolahan citra medis menggunakan matlab, pengolahan citra MRI matlab, segmentasi active contour matlab, segmentasi citra dengan matlab, segmentasi citra menggunakan matlab, slice citra matlab, slice thickness matlab, visualisasi citra 3 dimensi matlab. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0