Hello, iam currently developing Fuzzy logic image processing system to detect edges in an image in matlab. so far, i only can change the value of sx and sy in command line to detect edges. (picture 1)
but i want apply it on this function (picture 2) and i dont know how to do it.
This is my code
classdef Sugoi < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Panel matlab.ui.container.Panel
UploadImageButton matlab.ui.control.Button
syEditField matlab.ui.control.NumericEditField
syEditFieldLabel matlab.ui.control.Label
sxEditField matlab.ui.control.NumericEditField
sxEditFieldLabel matlab.ui.control.Label
UIAxes2 matlab.ui.control.UIAxes
UIAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: UploadImageButton
function UploadImageButtonPushed(app, event)
[filename, pathname] = uigetfile('*.*', 'Pick an Image');
filename=strcat(pathname,filename);
a=imread(filename);
%import RGB image and convert to Grayscale
Igray = rgb2gray(a);
%figure
%image(Igray, 'CDataMapping','scaled')
%colormap('gray')
%title('Input Image in Grayscale')
%convert Image to Double-Precision Data
I = im2double(Igray);
%Obtain Image Gradient
Gx = [-1 1];
Gy = Gx';
Ix = conv2(I, Gx,'same');
Iy = conv2(I, Gy,'same');
%figure
%image(Ix, 'CDataMapping','scaled')
%colormap('gray')
%title('Ix')
%figure
%image(Iy,'CDataMapping','scaled')
%colormap('gray')
%title('Iy')
%Define Fuzzy Inference System (FIS) for Edge Detection
edgeFIS = mamfis('Name','edgeDetection');
edgeFIS = addInput(edgeFIS,[-1 1],'Name','Ix');
edgeFIS = addInput(edgeFIS,[-1 1],'Name','Iy');
%Change the value edgeFIS of image
sx = 0.01;
sy = 0.01;
edgeFIS = addMF(edgeFIS,'Ix','gaussmf',[sx 0],'Name','zero');
edgeFIS = addMF(edgeFIS,'Iy','gaussmf',[sy 0],'Name','zero');
edgeFIS = addOutput(edgeFIS,[0 1],'Name','Iout');
wa = 0.1;
wb = 1;
wc = 1;
ba = 0;
bb = 0;
bc = 0.7;
edgeFIS = addMF(edgeFIS,'Iout','trimf',[wa wb wc],'Name','white');
edgeFIS = addMF(edgeFIS,'Iout','trimf',[ba bb bc],'Name','black');
%figure
%subplot(2,2,1)
%plotmf(edgeFIS,'input',1)
%title('Ix')
%subplot(2,2,2)
%plotmf(edgeFIS,'input',2)
%title('Iy')
%subplot(2,2,[3 4])
%plotmf(edgeFIS,'output',1)
%title('Iout')
%Specify FIS Rules
r1 = "If Ix is zero and Iy is zero then Iout is white";
r2 = "If Ix is not zero or Iy is not zero then Iout is black";
edgeFIS = addRule(edgeFIS,[r1 r2]);
edgeFIS.Rules
%Evaluate FIS
Ieval = zeros(size(I));
for ii = 1:size(I,1)
Ieval(ii,:) = evalfis(edgeFIS,[(Ix(ii,:));(Iy(ii,:))]');
end
imshow(a, 'Parent',app.UIAxes);
imshow(Igray, 'Parent',app.UIAxes2)
%Plot Results(Final)
%figure
%image(I,'CDataMapping','scaled')
%colormap('gray')
%title('Original Grayscale Image')
figure
image(Ieval,'CDataMapping','scaled')
colormap('gray')
title('Edge Detection Using Fuzzy Logic')
end
% Value changed function: sxEditField
function sxEditFieldValueChanged(app, event)
value = app.sxEditField.Value;
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Original Image')
app.UIAxes.Position = [314 258 300 185];
% Create UIAxes2
app.UIAxes2 = uiaxes(app.UIFigure);
title(app.UIAxes2, 'Grayscale')
app.UIAxes2.Position = [315 46 300 185];
% Create Panel
app.Panel = uipanel(app.UIFigure);
app.Panel.Position = [47 149 260 221];
% Create sxEditFieldLabel
app.sxEditFieldLabel = uilabel(app.Panel);
app.sxEditFieldLabel.HorizontalAlignment = 'right';
app.sxEditFieldLabel.Position = [46 177 25 22];
app.sxEditFieldLabel.Text = 'sx';
% Create sxEditField
app.sxEditField = uieditfield(app.Panel, 'numeric');
app.sxEditField.ValueChangedFcn = createCallbackFcn(app, @sxEditFieldValueChanged, true);
app.sxEditField.Position = [86 177 100 22];
app.sxEditField.Value = 0.01;
% Create syEditFieldLabel
app.syEditFieldLabel = uilabel(app.Panel);
app.syEditFieldLabel.HorizontalAlignment = 'right';
app.syEditFieldLabel.Position = [47 138 25 22];
app.syEditFieldLabel.Text = 'sy';
% Create syEditField
app.syEditField = uieditfield(app.Panel, 'numeric');
app.syEditField.Position = [87 138 100 22];
app.syEditField.Value = 0.01;
% Create UploadImageButton
app.UploadImageButton = uibutton(app.Panel, 'push');
app.UploadImageButton.ButtonPushedFcn = createCallbackFcn(app, @UploadImageButtonPushed, true);
app.UploadImageButton.Position = [81 87 100 22];
app.UploadImageButton.Text = 'Upload Image';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = Sugoi
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end