Image Classification Using Edge Detection Withe Fuzzy Logic: Par: Chettouh Safieddine Sohbi Salem Hammoudi Mabrouk
Image Classification Using Edge Detection Withe Fuzzy Logic: Par: Chettouh Safieddine Sohbi Salem Hammoudi Mabrouk
Image Classification Using Edge Detection Withe Fuzzy Logic: Par: Chettouh Safieddine Sohbi Salem Hammoudi Mabrouk
par:
Chettouh safieddine
Sohbi salem
Hammoudi mabrouk
In most of these methods, adjacent points of pixels are assumed in some classes and
then fuzzy
system inference are implemented using appropriate membership function, defined for
each
class [Mahani, et al. 2008]. In Liang, et al. [Liang, et al. 2003], adjacent points are as-
sumed
as 3×3 sets around the concerned point. By predefining membership function to de-
tect edges.
In these rules discontinuity in the color of different 3×3 sets, edges are extracted. It
uses 5 fuzzy
rules and predefined membership function to detect edges. In these rules discontinu-
ity of adjacent point around the concerned point are investigated. If this difference is
similar to one of predefined sets, the pixel is
assumed as edge.A similar work is proposed by Mansoori, et al. [Mansoori, et al.
2006], wherein
adjacent points of each pixel are grouped in six different set. Then by using of appro-
priate bell shape membership function, the value from zero to one is determined for
each group. Based on
the membership.
stages of work :
Images are categorized by entering the image into the algorithm, then it
tells you to which category it belongs
For image classification there are two algorithms, one for training and one
for testing
Training algorithme :
You enter an RGB image and detect the edges to produce a black and white
image, then save the image values in the db matrix.
progremme
clc;
clear all;
close all;
%% Taking an Image
[fname, path]=uigetfile('.png','Open an Image as input for training');
fname=strcat(path, fname);
im=imread(fname);
%%%%%%%%%%%%
Irgb = im;
Igray = rgb2gray(Irgb);
figure
image(Igray,'CDataMapping','scaled')
colormap('gray')
title('Input Image in Grayscale')
I = im2double(Igray);
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')
% edgeFIS=mamfis;
edgeFIS = mamfis('Name','edgeDetection');
edgeFIS = addInput(edgeFIS,[-1 1],'Name','Ix');
edgeFIS = addInput(edgeFIS,[-1 1],'Name','Iy');
sx = 0.1;
sy = 0.1;
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')
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
Ieval = zeros(size(I));
for ii = 1:size(I,1)
Ieval(ii,:) = evalfis(edgeFIS,[(Ix(ii,:));(Iy(ii,:))]');
end
figure
image(I,'CDataMapping','scaled')
colormap('gray')
title('Original Grayscale Image')
figure
image(Ieval,'CDataMapping','scaled')
colormap('gray')
title('Edge Detection Using Fuzzy Logic')
%%%%%%%%%%%%%%
%%im=im2bw(im);
imshow(Ieval);
title('Input Image');
c=input('Enter the Class(Number from 1-12)');
%% Feature Extraction
F=FeatureStatistical(Ieval);
try
load db;
F=[F c];
db=[db; F];
save db.mat db
catch
db=[F c]; % 10 12 1
save db.mat db
end
testing algorithme :
You enter an RGB image and then the algorithm transforms
the image using boundary detection (fuzzy logic)
Then it compares its values to the values in the db array and
tells you to which class it belongs.
%% Test Image
clc;
clear all;
close all;
[fname, path]=uigetfile('.png','provide an Image for testing');
fname=strcat(path, fname);
im=imread(fname);
%edge detection using fuzzy logic
Irgb = im;
Igray = rgb2gray(Irgb);
figure
image(Igray,'CDataMapping','scaled')
colormap('gray')
title('Input Image in Grayscale')
I = im2double(Igray);
Gx = [-1 1];
Gy = Gx';
Ix = conv2(I,Gx,'same');
Iy = conv2(I,Gy,'same');
figure
figure
image(Ix,'CDataMapping','scaled')
colormap('gray')
title('Ix')
figure
image(Iy,'CDataMapping','scaled')
colormap('gray')
title('Iy')
% edgeFIS=mamfis;
edgeFIS = mamfis('Name','edgeDetection');
edgeFIS = addInput(edgeFIS,[-1 1],'Name','Ix');
edgeFIS = addInput(edgeFIS,[-1 1],'Name','Iy');
sx = 0.1;
sy = 0.1;
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')
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
Ieval = zeros(size(I));
for ii = 1:size(I,1)
Ieval(ii,:) = evalfis(edgeFIS,[(Ix(ii,:));(Iy(ii,:))]');
end
figure
image(I,'CDataMapping','scaled')
colormap('gray')
title('Original Grayscale Image')
figure
image(Ieval,'CDataMapping','scaled')
colormap('gray')
title('Edge Detection Using Fuzzy Logic')
%%%%%%%%%
%%im=im2bw(im);
imshow(Ieval);
title('Test Image');
%% Find the class the test image belongs
Ftest=FeatureStatistical(Ieval);
%% Compare with the feature of training image in the database
load db.mat
Ftrain=db(:,1:2);
Ctrain=db(:,3);
for (i=1:size(Ftrain,1));
dist(i,:)=sum(abs(Ftrain(i,:)-Ftest));
end
m=find(dist==min(dist),1);
det_class=Ctrain(m);
msgbox(strcat('Detected Class=',num2str(det_class)));