Fuzzy Logic Image Processing


An edge is a boundary between two uniform regions. You can detect an edge by comparing the intensity of neighboring pixels. small intensity differences between two neighboring pixels do not always represent an edge. Instead, the intensity difference might represent a shading effect. The fuzzy logic approach for image processing allows you to use membership functions to define the degree to which a pixel belongs to an edge or a uniform region.

Import RGB Image and Convert to Grayscale

I = imread('peppers.png');
I' = 0.2989*I(:,:,1)+0.5870*I(:,:,2)+0.1140*I(:,:,3); figure; image(I','DataMapping','scaled'); colormap('gray'); title('Input Image in Grayscale'




Convert Image to Double-Precision Data

I = double(I');
Type = class(I'); scaling = double(intmax(Type)); I = I/scaling; 

Obtain Image Gradient

Gx = [-1 1]; Gy = Gx'; Ix = conv2(I,Gx,'same'); Iy = conv2(I,Gy,'same'); figure; image(Ix,'DataMapping','scaled'); colormap('gray'); title('Ix'); figure; image(Iy,'DataMapping','scaled'); colormap('gray'); title('Iy');
Define Fuzzy Inference System (FIS) for Edge Detection
edgeFIS = newfis('edgeDetection');
edgeFIS = addvar(edgeFIS,'input','Ix',[-1 1]); edgeFIS = addvar(edgeFIS,'input','Iy',[-1 1]);
sx = 0.1; sy = 0.1; edgeFIS = addmf(edgeFIS,'input',1,'zero','gaussmf',[sx 0]); edgeFIS = addmf(edgeFIS,'input',2,'zero','gaussmf',[sy 0]);
edgeFIS = addvar(edgeFIS,'output','Iout',[0 1]);
wa = 0.1; wb = 1; wc = 1; ba = 0; bb = 0; bc = .7; edgeFIS = addmf(edgeFIS,'output',1,'white','trimf',[wa wb wc]); edgeFIS = addmf(edgeFIS,'output',1,'black','trimf',[ba bb bc]);
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'; r = char(r1,r2); edgeFIS = parsrule(edgeFIS,r); showrule(edgeFIS)

Evaluate FIS

Ieval = zeros(size(I));% Preallocate the output matrix for ii = 1:size(I,1) Ieval(ii,:) = evalfis([(Ix(ii,:));(Iy(ii,:));]',edgeFIS); end


Plot Results

figure; image(I,'CDataMapping','scaled'); colormap('gray'); title('Original Grayscale Image') figure; image(Ieval,'CDataMapping','scaled'); colormap('gray'); title('Edge Detection Using Fuzzy Logic')

Popular posts from this blog

Image J