Images Processing Simulator [MATLAB GUI]

MORPHOLOGY OPERATION SIMULATOR



Gambar I-1. Images Processing Simulator

A. Morfologi Citra 

Operasi morfologi merupakan operasi yang umum dikenakan pada citra biner (hitam-putih) untuk mengubah struktur bentuk objek yang terkandung dalam citra.

Contoh lain aplikasi morfologi :

1. Membentuk filter spasial
2. Memperoleh skeleton (rangka) objek
3. Menentukan letak objek di dalam citra
4. Memperoleh bentuk struktur objek.

Gambar I-1. Hasil Morfologi Citra Biner

Untuk mempermudah melakukan operasi morfologi dan pemrosesan citra lainnya, gue sudah buatin sebuah simulator pemrosesan citra mulai dari basic processing sampai advanced processing of images processing. GUI ( graphical User Interface ) yang digunakan disini dibuat menggunakan MATLAB sehingga sobat semua lebih mudah memahaminya . Berikut tampilan dari simulator pemrosesan citra.
Terdiri dari :
1. Grayscale Image
2. Binary Image
3. Histogram Citra RGB
4. Histogram Citra Grayscale
5. Histogram Equalization
6. Convolution
7. Red SCale
8. Green Scale
9. Blue Scale
10. Shifting
11. Rotating
12. Complement / Negative Image
13. Morphology Operations : dilasi, erosi, open , close

B. Matlab Source Code

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

% Last Modified by GUIDE v2.5 14-Feb-2020 19:50:43

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = Tugas3Fix_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)
% Load Image
a=uigetfile() %A fileselector as uigetfile, with multiple selection which does not require Java
filename = a;
setappdata(0,'filename',filename); %store application-defined data
a = imread(a);
axes(handles.axes1);
imshow(a)
setappdata(0,'a',a)
setappdata(0,'filename',a);
%plot(handles.axes1,'a')


% --- 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)
% Reset
axes(handles.axes1)
cla('reset')% Clear axes
axes(handles.axes2)
cla('reset')



% --- 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)
%RGB to Grayscale
a=getappdata(0,'a');
a_gray=rgb2gray(a);
setappdata(0,'filename',a_gray); %store application-defined data
axes(handles.axes2);
imshow(a_gray)

% --- 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)
% BW Image
a=getappdata(0,'a');
g=rgb2gray(a)
a_bw=im2bw(g);
setappdata(0,'filename',a_bw); %store application-defined data
axes(handles.axes2);
imshow(a_bw)




% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
%Implement simple brightness
a=getappdata(0,'a');
val = 0.5*get(hObject,'Value')-0.5;
imbright=a+val;
axes(handles.axes2);
imshow(imbright);

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- 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)
% Complement
a = getappdata(0,'a');
im2=imcomplement(a);
axes(handles.axes2);
imshow(im2);

% --- 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)
%Histogram for RGB 
a = getappdata(0,'a');
input=a;
axes(handles.axes2)
imhist(input)


% --- 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)
%Histogram Gray
a = getappdata(0,'a');
input=a;
input = rgb2gray(input);
axes(handles.axes2)
imhist(input)

% --- 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)
msgbox("Don't leave me :')");
pause(1)
close();
close();


% --- 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)
% Green img
a =getappdata(0,'a');
green=a;
green(:,:,1)=0
green(:,:,3)=0%the average intensity of the green channel
setappdata(0,'filename',green);
setappdata(0,'imrotation',green);
axes(handles.axes2);
imshow(green)

% --- 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)
% BLUE
a =getappdata(0,'a');
blue=a;
blue(:,:,1)=0
blue(:,:,2)=0%the average intensity of the blue channel
setappdata(0,'filename',blue);
setappdata(0,'imrotation',blue);
axes(handles.axes2);
imshow(blue)

% --- 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)
% Rotate
a = getappdata(0,'a');
rotate=imrotate(a,45);
axes(handles.axes2);
imshow(rotate);

% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% equalization
a = getappdata(0,'a');
eq = histeq(a); %perataan histogram
axes(handles.axes2);
imshow(eq);

% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Resize
a= getappdata(0,'a');
rz=imresize(a,0.5);
axes(handles.axes2);
imshow(rz)

% --- 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)
% Salt&papper Noise
a=getappdata(0,'a');
noise=imnoise(a,'salt & pepper');
axes(handles.axes2);
imshow(noise)

% --- 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)
% Average filter
a = getappdata(0,'a');
noise = imnoise(a,'salt & pepper');
a3 = fspecial('average',[7 7]);
t_sp_a3 = filter2(a3,noise);
axes(handles.axes2);
imshow(t_sp_a3/255)

% --- 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)
% Gaussian
a = getappdata(0,'a');
noise=imnoise(a,'gaussian');
axes(handles.axes2);
imshow(noise)

% --- 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)
% Periodic Noise
a = getappdata(0,'a');
s = size(a);
[x,y]=meshgrid(1:s(1),1:s(2));
p = sin(x/3+y/5)+1;
noise=imnoise(im2double(a)+p/2)/2;
axes(handles.axes2);
imshow(noise)

% --- 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)
% FLIP
i = getappdata(0,'a');
i2= flipdim(i,2);
axes(handles.axes2);
imshow(i2)


% --- 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)
% RED Image
a =getappdata(0,'a');
red=a;
red(:,:,2:3)=0 %the average intensity of the red channel
setappdata(0,'filename',red);
setappdata(0,'imrotation',red);
axes(handles.axes2);
imshow(red)

% --- 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)
% Convolution
a =getappdata(0,'a');
g = rgb2gray(a);
H = [-1 0 -1; 0 4 0; -1 0 -1];
self_convolutions =conv2(g,H);
axes(handles.axes2);
imshow(self_convolutions)


% --- 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)
% FILTER MEDIAN
a =getappdata(0,'a');
F = rgb2gray(a);
[tinggi, lebar] = size(F);
for baris=2 : tinggi-1
    for kolom=2 : lebar-1
        data = [F(baris-1, kolom-1) ...
            F(baris-1, kolom) ...
            F(baris-1, kolom+1) ...
            F(baris, kolom-1) ...
            F(baris, kolom) ...
            F(baris, kolom+1) ...
            F(baris+1, kolom-1) ...
            F(baris+1, kolom) ...
            F(baris+1, kolom+1)];
% Urutkan
        for i=1 : 8
            for j=i+1 : 9
                if data(i) > data(j)
                    tmp = data(i);
                    data(i) = data(j);
                    data(j) = tmp;
                end
            end
        end
% Ambil nilai median
        G(baris, kolom) = data(5);
    end
end
axes(handles.axes2);
imshow(G);



% --- 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)
% Filter Batas
a =getappdata(0,'a');
F = rgb2gray(a);
Ukuran = size(F);
tinggi = Ukuran(1);
lebar = Ukuran(2);
G = F;
for baris=2 : tinggi-1
    for kolom=2 : lebar-1
        minPiksel = min([F(baris-1, kolom-1) ...
           F(baris-1, kolom) F(baris, kolom+1) ...
           F(baris, kolom-1) ...
           F(baris, kolom+1) F(baris+1, kolom-1) ...
           F(baris+1, kolom) F(baris+1, kolom+1)]);
        maksPiksel = min([F(baris-1, kolom-1) ...
           F(baris-1, kolom) F(baris, kolom+1) ...
           F(baris, kolom-1) ...
           F(baris, kolom+1) F(baris+1, kolom-1) ...
           F(baris+1, kolom) F(baris+1, kolom+1)]);
        if F(baris, kolom) < minPiksel
            G(baris, kolom) = minPiksel;
        else
            if F(baris, kolom) > maksPiksel
                G(baris, kolom) = maksPiksel;
            else
                G(baris, kolom) = F(baris, kolom);
            end
        end
    end
end
axes(handles.axes2);
imshow(G);
clear;


% --- 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)
% ZOOM 
sy = 0.5;
sx = 0.5;
a =getappdata(0,'a');
F = a;
[tinggi, lebar] = size(F);
tinggi_baru = tinggi * sy;
lebar_baru = lebar * sx;
F2 = double(F);
for y=1 : tinggi_baru
    y2 = ((y-1) / sy) + 1;
    for x=1 : lebar_baru
        x2 = ((x-1) / sx) + 1;
        G(y, x) = F(floor(y2), floor(x2));
    end
end
axes(handles.axes2);
G = uint8(G);
imshow(G)

% --- Executes on button press in pushbutton33.
function pushbutton33_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton33 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% SHifting 
a =getappdata(0,'a');
F = rgb2gray(a);
[tinggi, lebar] = size(F);
sx = -70; % Penggesaran arah horisontal
sy = -35; % Penggesaran arah vertikal
F2 = double(F);
G = zeros(size(F2));
for y=1 : tinggi
    for x=1 : lebar
        xlama = x - sx;
        ylama = y - sy;
        if (xlama>=1) && (xlama<=lebar) && (ylama>=1) && (ylama<=tinggi)
            G(y, x) = F2(ylama, xlama);
        else
            G(y, x) = 0;
        end
    end
end
axes(handles.axes2);
G = uint8(G);
imshow(G);
clear all;


% --- 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(handles.radiobutton1,'Value',1)
set(handles.radiobutton2,'Value',0)
set(handles.radiobutton3,'Value',0)
set(handles.radiobutton4,'Value',0)


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on button press in pushbutton34.
function pushbutton34_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton34 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Img_Gray = handles.Img_Gray;
% Img_bw = handles.Img_bw;
a=getappdata(0,'a');
Img_Gray =rgb2gray(a);
Img_bw = im2bw(Img_Gray);
% Operations
val1 = get(handles.radiobutton1,'Value');
val2 = get(handles.radiobutton2,'Value');
val3 = get(handles.radiobutton3,'Value');
val4 = get(handles.radiobutton4,'Value');

% Structure Element
val5 = get(handles.radiobutton5,'Value');
val6 = get(handles.radiobutton6,'Value');
val7 = get(handles.radiobutton7,'Value');
val8 = get(handles.radiobutton8,'Value');

% R
R = str2double(get(handles.edit1,'String'));

%
if val5 == 1
    se = strel('disk',R);
elseif val6 == 1
    se = strel('diamond',R);
elseif val7 == 1
    se = strel('square',R);
elseif val8 == 1
    se = strel('line',R,45);
end


if val1 == 1
    Morph_Gray = imerode(Img_Gray,se);
    %Morph_bw = imerode(Img_bw,se);
elseif val2 == 1
    Morph_Gray = imdilate(Img_Gray,se);
    %Morph_bw = imdilate(Img_bw,se);
elseif val3 == 1
    Morph_Gray = imopen(Img_Gray,se);
    %Morph_bw = imopen(Img_bw,se);
elseif val4 == 1
    Morph_Gray = imclose(Img_Gray,se);
    %Morph_bw = imclose(Img_bw,se);
end

axes(handles.axes1)
cla('reset')% Clear axes
imshow(Img_Gray)
title('Grayscale Image')
%axes(handles.axes3)
%cla('reset')
%imshow(Img_bw)
%title('Binary Image')
axes(handles.axes2)
cla('reset')
imshow(Morph_Gray)
title('Morphological Operation')
%axes(handles.axes4)
%cla('reset')
%imshow(Morph_bw)
%title('Morphological Operation')

% --- 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(handles.radiobutton1,'Value',0)
set(handles.radiobutton2,'Value',1)
set(handles.radiobutton3,'Value',0)
set(handles.radiobutton4,'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(handles.radiobutton1,'Value',0)
set(handles.radiobutton2,'Value',0)
set(handles.radiobutton3,'Value',1)
set(handles.radiobutton4,'Value',0)


% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton4 (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 radiobutton4
set(handles.radiobutton1,'Value',0)
set(handles.radiobutton2,'Value',0)
set(handles.radiobutton3,'Value',0)
set(handles.radiobutton4,'Value',1)


% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton5 (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 radiobutton5
set(handles.radiobutton5,'Value',1)
set(handles.radiobutton6,'Value',0)
set(handles.radiobutton7,'Value',0)
set(handles.radiobutton8,'Value',0)


% --- Executes on button press in radiobutton6.
function radiobutton6_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton6 (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 radiobutton6
set(handles.radiobutton5,'Value',0)
set(handles.radiobutton6,'Value',1)
set(handles.radiobutton7,'Value',0)
set(handles.radiobutton8,'Value',0)


% --- Executes on button press in radiobutton7.
function radiobutton7_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton7 (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 radiobutton7
set(handles.radiobutton5,'Value',0)
set(handles.radiobutton6,'Value',0)
set(handles.radiobutton7,'Value',1)
set(handles.radiobutton8,'Value',0)


% --- Executes on button press in radiobutton8.
function radiobutton8_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton8 (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 radiobutton8
set(handles.radiobutton5,'Value',0)
set(handles.radiobutton6,'Value',0)
set(handles.radiobutton7,'Value',0)
set(handles.radiobutton8,'Value',1)


% --- Executes on button press in pushbutton35.
function pushbutton35_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton35 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
val = str2double(get(handles.edit1,'String'))-1;
if val < 1
    val = 1;
end
set(handles.edit1,'String',val)


% --- Executes on button press in pushbutton36.
function pushbutton36_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton36 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
val = str2double(get(handles.edit1,'String'))+1;
if val > 10
    val = 10;
end
set(handles.edit1,'String',val)


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 pushbutton37.
% function pushbutton37_Callback(hObject, eventdata, handles)
% % hObject    handle to pushbutton37 (see GCBO)
% % eventdata  reserved - to be defined in a future version of MATLAB
% % handles    structure with handles and user data (see GUIDATA)
% [filename,pathname] = uigetfile({'*.*'});
% if ~isequal(filename,0)
%     Info = imfinfo(fullfile(pathname,filename));
%     if Info.BitDepth == 1
%         msgbox('Citra masukan harus citra RGB atau Grayscale');
%         return
%     elseif Info.BitDepth == 8
%         Img_Gray = imread(fullfile(pathname,filename));
%         axes(handles.axes1)
%         cla('reset')
%         imshow(Img_Gray)
%         title('Grayscale Image')
%         Img_bw = im2bw(Img_Gray,graythresh(Img_Gray));
%         axes(handles.axes3)
%         cla('reset')
%         imshow(Img_bw)
%         title('Binary Image')
%     else
%         Img_Gray = rgb2gray(imread(fullfile(pathname,filename)));
%         axes(handles.axes1)
%         cla('reset')
%         imshow(Img_Gray)
%         title('Grayscale Image')
%         Img_bw = im2bw(Img_Gray,graythresh(Img_Gray));
%         axes(handles.axes3)
%         cla('reset')
%         imshow(Img_bw)
%         title('Binary Image')
%     end
% else
%     return
% end
% handles.Img_Gray = Img_Gray;
% handles.Img_Gray2 = Img_Gray;
% handles.Img_bw = Img_bw;
% handles.Img_bw2 = Img_bw;
% guidata(hObject,handles);
% set(handles.pushbutton34,'Enable','on')

% --- Executes on button press in pushbutton39.
function pushbutton39_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton39 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
a=getappdata(0,'a');
Img_Gray =rgb2gray(a);
Img_bw = im2bw(Img_Gray);

% Operations
val1 = get(handles.radiobutton1,'Value');
val2 = get(handles.radiobutton2,'Value');
val3 = get(handles.radiobutton3,'Value');
val4 = get(handles.radiobutton4,'Value');

% Structure Element
val5 = get(handles.radiobutton5,'Value');
val6 = get(handles.radiobutton6,'Value');
val7 = get(handles.radiobutton7,'Value');
val8 = get(handles.radiobutton8,'Value');

% R
R = str2double(get(handles.edit1,'String'));

%
if val5 == 1
    se = strel('disk',R);
elseif val6 == 1
    se = strel('diamond',R);
elseif val7 == 1
    se = strel('square',R);
elseif val8 == 1
    se = strel('line',R,45);
end
if val1 == 1
 %   Morph_Gray = imerode(Img_Gray,se);
    Morph_bw = imerode(Img_bw,se);
elseif val2 == 1
  %  Morph_Gray = imdilate(Img_Gray,se);
    Morph_bw = imdilate(Img_bw,se);
elseif val3 == 1
  %  Morph_Gray = imopen(Img_Gray,se);
    Morph_bw = imopen(Img_bw,se);
elseif val4 == 1
  %  Morph_Gray = imclose(Img_Gray,se);
    Morph_bw = imclose(Img_bw,se);
end

%axes(handles.axes1)
%cla('reset')% Clear axes
%imshow(Img_Gray)
%title('Grayscale Image')
axes(handles.axes1)
cla('reset')
imshow(Img_bw)
title('Binary Image')
%axes(handles.axes2)
%cla('reset')
%imshow(Morph_Gray)
%title('Morphological Operation')
axes(handles.axes2)
cla('reset')
imshow(Morph_bw)
title('Morphological Operation')

File.fig | | Download








0 Response to "Images Processing Simulator [MATLAB GUI]"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel