Tutorial membuat thresholding
(program matlab)
Thresholding merupakan salah satu metode segmentasi citra di
mana prosesnya didasarkan pada perbedaan derajat keabuan citra.
Marilah kita simak penjelasan tentang cara pembuatan
thresholding di bawah ini :
1. Langkah pertama kita membuat
disegn thresholding
2. Lalu kita mengisi skrip yang pertama open image
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
[name_file1,name_path1] = uigetfile(...
{'*.bmp;*.jpg;*.tif','files
of type (*.bmp,*.jpg,*.tif)';
'*.bmp','file
Bitmap (*.Bmp)';...
'*.jpg','file
jpeg (*.jpg)';
'*.tif','file
Tif (*.tif)';
'*.*','All
Files (*.*)'},...
'Open image');
if
~isequal(name_file1,0)
handles.data1 =
imread(fullfile(name_path1,name_file1));
guidata(hObject,handles);
axes(handles.axes1);
imshow(handles.data1);
else
return;
end
3. Lalu kita mengisi skrip yang ke dua grayscale
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject,
eventdata, handles)
image1 = handles.data1;
gray = rgb2gray(image1);
axes(handles.axes2);
imshow(gray);
handles.data2 = gray;
guidata(hObject,handles);
4.
Lalu kita mengisi skrip yang ke tiga slider1_Callback
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
gray = handles.data2;
value = get(handles.slider1,'value');
thresh = imcomplement(im2bw(gray,value/255));
axes(handles.axes2);
imshow(thresh);
handles.data3 = thresh;
guidata(hObject,handles);
set(handles.edit1,'string',value)
5. Lalu kita mengisi skrip yang ke empat
save
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
thresh = handles.data3;
[name_file_save,path_save] = uiputfile( ...
{'*.bmp','file
Bitmap (*.bmp)';...
'*.jpg','file
jpeg (*.jpg)';
'*.tif','file
Tif (*.tif)';
'*.*','All
Files (*.*)'},...
'save image');
if~isequal(name_file_save,O)
imwrite(thresh,fullfile(path_save,name_file_save));
else
return
end