Anda di halaman 1dari 16

Pemrograman Matlab

Pengolahan Citra Digital, Pengolahan Video, Pengenalan


Pola, dan Data Mining

Pengolahan Citra CT Scan Paru-Paru


dengan Metode Segmentasi Active Contour

Pengolahan citra medis telah banyak dilakukan dengan mengembangkan berbagai macam
metode. Pengolahan yang dilakukan di antaranya bertujuan untuk meningkatkan kualitas citra
agar citra lebih mudah diinterpretasi dan untuk menganalisis citra secara objektif. Berikut ini
merupakan contoh pemrograman MATLAB untuk melakukan pengolahan citra CT Scan Paru-
Paru dengan metode segmentasi active contour. Citra diakuisisi dengan modalitas pesawat CT
Scan berformat DICOM (Digital Imaging and Communications in Medicine). Pengolahan citra
dilakukan untuk menghitung luas dan keliling daerah paru-paru.

Langkah-langkah pemrogramannya adalah sebagai berikut:


1. Membaca citra asli

1clc; clear; close all; warning off all;


2
3Img = dicomread('1');
4figure,imshow(Img,[])
5title('Citra Asli')
2. Inisialisasi masking untuk proses segmentasi

1h = imrect;
2setColor(h,'b')
3mask = createMask(h);
3. Segmentasi daerah paru dengan metode active contour

1bw = activecontour(Img,mask,1000);
2bw = imfill(bw,'holes');
3bw = bwareaopen(bw,500);
4bw = imclearborder(bw);
5
6figure, imshow(bw);
title('Citra Biner')
7
4. Menampilkan citra hasil segmentasi

1
2 figure, imshow(Img,[])
title('Hasil Segmentasi')
3 axis off
4 hold on
5 [c,~] = bwboundaries(bw,'noholes');
6 for k = 1:length(c)
7 boundary = c{k};
plot(boundary(:,2), boundary(:,1),'y','LineWidth',3)
8 end
9 hold off
10
5. Menghitung luas dan keliling daerah paru hasil segmentasi

1s = regionprops(bw, 'area','perimeter');
2area_bw = cat(1, s.Area);
3perim_bw = cat(1, s.Perimeter);
4
5res = 1.362; % resolusi spasial 1.362 pixel/mm
6area = area_bw/(res^2)/100
perimeter = perim_bw/res/10
7
6. Mengimplementasikan sistem pengolahan citra ke dalam GUI MATLAB
a. Tampilan awal GUI
b. Membuka citra asli

c. Inisialisasi masking untuk proses segmentasi


d. Proses segmentasi dengan metode active contour

e. Menghitung luas dan keliling daerah paru hasil segmentasi


f. Melakukan segmentasi pada daerah yang lain

g. Melakukan segmentasi pada daerah yang lain

Tampilan source code matlab untuk pengolahan citra CT Scan paru-paru adalah sebagai berikut:

1 function varargout = pengolahan_citra_paru(varargin)


% PENGOLAHAN_CITRA_PARU MATLAB code for pengolahan_citra_paru.fig
2 % PENGOLAHAN_CITRA_PARU, by itself, creates a new
3 PENGOLAHAN_CITRA_PARU or raises the existing
4 % singleton*.
5 %
6 % H = PENGOLAHAN_CITRA_PARU returns the handle to a new
PENGOLAHAN_CITRA_PARU or the handle to
7 % the existing singleton*.
8 %
9 % PENGOLAHAN_CITRA_PARU('CALLBACK',hObject,eventData,handles,...)
10 calls the local
% function named CALLBACK in PENGOLAHAN_CITRA_PARU.M with the given
11 input arguments.
12 %
13 % PENGOLAHAN_CITRA_PARU('Property','Value',...) creates a new
14 PENGOLAHAN_CITRA_PARU or raises the
15 % existing singleton*. Starting from the left, property value pairs
are
16 % applied to the GUI before pengolahan_citra_paru_OpeningFcn gets
17 called. An
18 % unrecognized property name or invalid value makes property
19 application
% stop. All inputs are passed to pengolahan_citra_paru_OpeningFcn
20 via varargin.
21 %
22 % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only
23 one
24 % instance to run (singleton)".
%
25 % See also: GUIDE, GUIDATA, GUIHANDLES
26
27 % Edit the above text to modify the response to help pengolahan_citra_paru
28
29 % Last Modified by GUIDE v2.5 23-Feb-2018 18:41:08
30
31 % Begin initialization code - DO NOT EDIT
32 gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
33 'gui_Singleton', gui_Singleton, ...
34 'gui_OpeningFcn', @pengolahan_citra_paru_OpeningFcn, ...
35 'gui_OutputFcn', @pengolahan_citra_paru_OutputFcn, ...
36 'gui_LayoutFcn', [] , ...
'gui_Callback', []);
37 if nargin && ischar(varargin{1})
38 gui_State.gui_Callback = str2func(varargin{1});
39 end
40
41 if nargout
42 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
43 gui_mainfcn(gui_State, varargin{:});
44 end
45 % End initialization code - DO NOT EDIT
46
47
48 % --- Executes just before pengolahan_citra_paru is made visible.
function pengolahan_citra_paru_OpeningFcn(hObject, eventdata, handles,
49 varargin)
50 % This function has no output args, see OutputFcn.
51 % hObject handle to figure
52 % eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
53 % varargin command line arguments to pengolahan_citra_paru (see
54 VARARGIN)
55
56 % Choose default command line output for pengolahan_citra_paru
57 handles.output = hObject;
58
% Update handles structure
59 guidata(hObject, handles);
60 movegui(hObject,'center');
61
62 % UIWAIT makes pengolahan_citra_paru wait for user response (see UIRESUME)
63 % uiwait(handles.figure1);
64
65
66 % --- Outputs from this function are returned to the command line.
function varargout = pengolahan_citra_paru_OutputFcn(hObject, eventdata,
67 handles)
68 % varargout cell array for returning output args (see VARARGOUT);
69 % hObject handle to figure
70 % eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
71
72 % Get default command line output from handles structure
73 varargout{1} = handles.output;
74
75
76 % --- Executes on button press in pushbutton1.
77 function pushbutton1_Callback(hObject, eventdata, handles)
78 % hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
79 % handles structure with handles and user data (see GUIDATA)
80 [filename, pathname] = uigetfile('*.*');
81
82 if ~isequal(filename,0)
83 set(handles.pushbutton2,'Enable','on')
84
85 axes(handles.axes1)
cla reset
86 set(gca,'XTick',[])
87 set(gca,'YTick',[])
88
89 axes(handles.axes2)
90 cla reset
set(gca,'XTick',[])
91
set(gca,'YTick',[])
92
93 axes(handles.axes3)
94 cla reset
95 set(gca,'XTick',[])
96 set(gca,'YTick',[])
97 Img = dicomread(fullfile(pathname, filename));
98 axes(handles.axes1)
imshow(Img,[])
99 title('Citra Asli')
100 set(handles.pushbutton2,'Enable','on')
101 set(handles.pushbutton3,'Enable','off')
102else
103end return
104
105handles.Img = Img;
106guidata(hObject, handles)
107
108% --- Executes on button press in pushbutton2.
109function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
110% eventdata reserved - to be defined in a future version of MATLAB
111% handles structure with handles and user data (see GUIDATA)
112Img = handles.Img;
113
114axes(handles.axes2)
115cla reset
set(gca,'XTick',[])
116set(gca,'YTick',[])
117
118axes(handles.axes3)
119cla reset
120set(gca,'XTick',[])
set(gca,'YTick',[])
121
122set(handles.pushbutton3,'Enable','off')
123set(handles.edit1,'String',[])
124set(handles.edit2,'String',[])
125
126axes(handles.axes1)
127cla reset
imshow(Img,[])
128title('Citra Asli')
129h = imrect;
130setColor(h,'b')
131mask = createMask(h);
132%bwdelete(h);
= activecontour(Img,mask,1000);
133bw = imfill(bw,'holes');
134bw = bwareaopen(bw,500);
135bw = imclearborder(bw);
136
137axes(handles.axes2)
cla reset
138imshow(Img,[])
139title('Hasil Segmentasi')
140axis off
141hold on
142[c,~] = bwboundaries(bw,'noholes');
for k = 1:length(c)
143 boundary = c{k};
144 plot(boundary(:,2), boundary(:,1),'y','LineWidth',3)
end
145hold off
146
147axes(handles.axes3)
148cla reset
149imshow(bw)
150title('Citra Biner')
151set(handles.pushbutton3,'Enable','on')
152
153handles.bw = bw;
154guidata(hObject, handles)
155
156% --- Executes on button press in pushbutton3.
157function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
158% eventdata reserved - to be defined in a future version of MATLAB
159% handles structure with handles and user data (see GUIDATA)
160bw = handles.bw;
161
162s = regionprops(bw, 'area','perimeter');
163area_bw = cat(1, s.Area);
perim_bw = cat(1, s.Perimeter);
164
165res = 1.362; % resolusi spasial 1.362 pixel/mm
166area = area_bw/(res^2)/100;
167perimeter = perim_bw/res/10;
168
169set(handles.edit1,'String',[num2str(area),' cm2'])
set(handles.edit2,'String',[num2str(perimeter),' cm'])
170
171% --- Executes on button press in pushbutton4.
172function pushbutton4_Callback(hObject, eventdata, handles)
173% hObject handle to pushbutton4 (see GCBO)
174% eventdata reserved - to be defined in a future version of MATLAB
175% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1)
176cla reset
177set(gca,'XTick',[])
178set(gca,'YTick',[])
179
180axes(handles.axes2)
181cla reset
set(gca,'XTick',[])
182set(gca,'YTick',[])
183
184axes(handles.axes3)
185cla reset
186set(gca,'XTick',[])
set(gca,'YTick',[])
187
188set(handles.edit1,'String',[])
189set(handles.edit2,'String',[])
190
191set(handles.pushbutton2,'Enable','off')
set(handles.pushbutton3,'Enable','off')
192
193function edit1_Callback(hObject, eventdata, handles)
194% hObject handle to edit1 (see GCBO)
195% eventdata reserved - to be defined in a future version of MATLAB
196% handles structure with handles and user data (see GUIDATA)
197
198%% Hints: str2double(get(hObject,'String'))
get(hObject,'String') returns contents of edit1 as text
returns contents of edit1 as a
199double
200
201
202% --- Executes during object creation, after setting all properties.
203function edit1_CreateFcn(hObject, eventdata, handles)
204% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
205% handles empty - handles not created until after all CreateFcns called
206
207% Hint: edit controls usually have a white background on Windows.
208% See ISPC and COMPUTER.
209if ispc && isequal(get(hObject,'BackgroundColor'),
210get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
211end
212
213
214
215function edit2_Callback(hObject, eventdata, handles)
216% hObject handle to edit2 (see GCBO)
217 % eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
218
219% Hints: get(hObject,'String') returns contents of edit2 as text
220% str2double(get(hObject,'String')) returns contents of edit2 as a
221double
222
223
224% --- Executes during object creation, after setting all properties.
225function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
226% eventdata reserved - to be defined in a future version of MATLAB
227% handles empty - handles not created until after all CreateFcns called
228
229% Hint: edit controls usually have a white background on Windows.
230% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
231get(0,'defaultUicontrolBackgroundColor'))
232 set(hObject,'BackgroundColor','white');
233end
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

Source code dan citra pada pemrograman di atas dapat diunduh pada halaman berikut ini: Source
Code

Segmentasi Citra dengan Metode Thresholding

In "Pengolahan Citra"

Pengolahan Citra Digital


In "Pengolahan Citra"

Pengolahan Citra Biner

Anda mungkin juga menyukai