Upload
idreesgis
View
222
Download
0
Embed Size (px)
Citation preview
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 1/62
Fuzzy techniques in image processing
Sami Hokuni
April 12, 2012
1/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 2/62
In a traditional set theory an element has only two options: iteither belongs totally to some set or it doesn’t belong there atall.
If we have set A such that [0, 1] ∈ A, then
− x = 1 belongs totally to the set A
− y = 2 doesn’t belong at all to the set A
This method is not very flexible if we have some imprecision
2/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 3/62
Let us assume that we have set Z of all people.From this set we would want to define a subset A called”young people”.
To define this subset we need to decide some threshold age,
for example 20 years.If you are exactly 20 years old, you belong to the subset”young people”.
However, if you are 20 years and one second old, you dontbelong to this subset at all.
3/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 4/62
In this case we would need more flexible system, which wouldhave some kind of gradual transition
Young → relatively young → somehow young → not so young
→ not at all young.Fuzzy logic offers us a way to do this kind of transitions.
4/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 5/62
Fuzzy set is characterized by its membership function µ.
Let us assume that we have fuzzy set A in set Z , and z issome element in Z .
Then value µA(z ) represents degree of membership of element
z in A.Degree of membership is some real number from range [0, 1].
Degree of membership tells us, how strongly an elementbelongs to the subset.
5/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 6/62
If µA(z )=1, then z belongs totally to the fuzzy set A.
If µA(z )=0, then z doesn’t belong at all to the fuzzy set A.
If µA(z ) ∈ (0, 1), then z belongs partially to the fuzzy set A.
6/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 7/62
Fuzzy set A is an ordered pair consisting of values z ∈ Z anda membership function that gives the degree of membershipto each z ∈ Z
A = {z , µA(z )|z ∈ Z }
Previous subset of ”young people” can then be expressed as
A = {(1, 1), · · · , (20, 1), (21, 0.9), · · · , (29, 0.1), (30, 0), · · · }
In this example people who are 30 or older do not belong tothe subset ”young people” at all.
7/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 8/628/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 9/62
Membership value is not the same as probability.
For example, in the figure on the last slide we saw that themembership value for z = 25 was 0.5.
Probablilistic statement: There is 50% chance that thisperson is young.
Here person is considered to either be in the set of youngpeople or not in that set.
Fuzzy statement: Person is young to some degree, and herethis degree is 0.5.
Fuzzy logic is characterized by imprecision, not byrandomness.
9/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 10/62
Fuzzy set A ∈ Z is empty if and only if µA(z ) = 0 for all
z ∈ Z .Two fuzzy sets A ∈ Z and B ∈ Z are equal (A = B ) if andonly if µA(z ) = µB (z ) for all z ∈ Z .
Fuzzy set A is a subset of fuzzy set B if and only if µA(
z ) ≤
µB (
z ) for all
z ∈
Z .
Complement of a fuzzy set(NOT) A, denoted by A, is the setwhose membership function is
µA(z ) = 1 − µA(z )
for all z ∈ Z .
10/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 11/62
The union(OR) of two fuzzy sets A and B , denoted A ∪ B , is
a fuzzy set U with the membership function
µU (z ) = max {µA(z ), µB (z )}
for all z ∈ Z .
The intersection(AND) of two fuzzy sets A and B , denotedA ∩ B , is a fuzzy set I with the membership function
µI (z ) = min {µA(z ), µB (z )}
for all z ∈ Z .
11/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 12/62
Membership function can be defined in many different ways
A few next slides will present some of the most common types
of membership functions
12/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 13/62
Triangular
13/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 14/62
Trapezoidal
14/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 15/62
Sigmoidal
15/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 16/62
Let us suppose that we have an electric motor, whose health
we would like to measure.To simplify the case we can assume that it is enough tomeasure average vibration frequency.
Three are three ranges of average frequency:
− In low range motor is performing normally
− In mid range motor is performing marginally
− In high range motor is in the near-failure mode
Because these ranges sound imprecise, using fuzzy logic onthem might be a good idea.
16/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 17/62
0 10 20 30 40 50 60 70 80
0
0.2
0.4
0.6
0.8
1
Average vibration frequency : z
D e g r e e o f m
e m b e r s h i p : µ ( z )
µ low
(z)
µ mid
(z)
µ high
(z)
17/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 18/62
Based on previous definitions we can come up with followingfuzzy IF-THEN rules:
IF the frequency is low , THEN motor operation is normal (R 1)
OR
IF the frequency is mid , THEN motor operation is marginal (R 2)
OR
IF the frequency is high, THEN motor operation is near failure (R 3)
18/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 19/62
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 20/62
0 10 20 30 40 50 60 70 80 90 100
0
0.2
0.4
0.6
0.8
1
Abnormality in percents : v
D e g r e e o f m e m b e r s h i p
µ norm
(v) µ marg
(v) µ fail
(v)
20/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 21/62
IF the frequency is low , THEN motor operation is normal
(R 1).
This rule relates low AND normal .
There is nothing more than intersection operation AND,which we defined earlier.
As a result we get following membership function
µ1(z , v ) = µlow (z ) AND µnorm(v ) = min {µlow (z ), µnorm(v )}
This function is a general result.
21/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 22/62
However, we are interested in outputs due to some specificinput z 0.
The degree of membership of z 0 in terms of the lowmembership function is µlow (z 0).
To obtain the output corresponding to the rule R 1 and inputz 0, we use AND operator to the specific value µlow (z 0) andµ1(z 0, v ) (general solution evaluated at z 0).
22/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 23/62
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 24/62
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 25/62
Now we need to obtain the overall response in this fuzzysystem.
In other words we need to combine Q 1, Q 2 and Q 3 into one Q .
Originally: R 1 OR R 2 OR R 3.
Therefore complete fuzzy output is given by
Q (v ) = Q 1(v ) OR Q 2(v ) OR Q 3(v )
25/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 26/62
OR was previously defines as a max operation
Therefore
Q (v ) = max {Q 1(v ), Q 2(v ), Q 3(v )}
= maxr
mins ,t
{µs (z 0), µt (v )}
where r = {1, 2, 3},s = {low , mid , high} andt = {norm, marg , fail }. Here s and t are paired combinations.
Although Q (v ) was developed specifically for this example, itwould be generalized to n rules.
Then r = {1, 2, · · · , n}.
26/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 27/62
0 10 20 30 40 50 60 70 80 90 100
0
0.2
0.4
0.6
0.8
1
Abnormality in percents : v
D e g r e e o f
m e m b e r s h i p
z0 is some specific input value
µ norm
(v) µ marg
(v) µ fail
(v)
µlow
(z0)
µmid
(z0)
µhigh
(z0)
27/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 28/62
0 10 20 30 40 50 60 70 80 90 100
0
0.2
0.4
0.6
0.8
1
Abnormality in percents : v
D e g r e e
o f m e m b e r s h i p
Q1(v)
Q2(v)
Q3(v)
28/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 29/62
0 10 20 30 40 50 60 70 80 90 100
0
0.2
0.4
0.6
0.8
1
Abnormality in percents : v
D e g r e e
o f m e m b e r s h i p
Q(v)
29/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 30/62
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 31/62
For example, let us assume that z 0 = 0.7.
By counting center of gravity for this z 0 we obtain v 0 = 0.76.
If an engine has frequency value of 0.7 it is operating with a76% degree of abnormality.
31/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 32/62
In this example rules were rather simple and had only onepart(IF...THEN)
If rules have more than one part, all parts have to be taken
into account in fuzzification.
32/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 33/62
For example, let us assume that we have another variablecalled temperature .
Now we would have to define a membership function also fortemperature.
First rule could then go in a following way
IF frequency is low AND temperature is moderate
THEN motor is normal
33/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 34/62
Membership function for the first rule would then be
µ1(z , t , v ) = µlow (z ) AND µmod (t ) AND µnorm(v )
= min {µlow (z ), µmod (t ), µnorm(v )}
Next we would select some specific frequency z 0 andtemperature t 0.
34/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 35/62
What phases we just did?1. Fuzzify the inputs (µlow , µmid , µhigh)
2. Perform all required fuzzy logical operations (µ1, µ2, µ3).
3. Apply an implication method (Q 1, Q 2, Q 3).
4. Apply an aggregation method for fuzzy sets acquired inphase 3 (Q ).
5. Defuzzify the final output set (center of gravity).
35/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 36/62
Nested functions are defined inside another function.
Nested functions are a relatively new feature and therefore
older versions of MATLAB dont support this.
36/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 37/62
function y = tax(income)
adjusted income = income - 6000;
y = compute tax
function y = compute taxy = 0.28*adjusted income;
end
end
37/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 38/62
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 39/62
ulow=@(z)1-sigmamf(z,0.27,0.47);umid=@(z)triangmf(z,0.24,0.50,0.74);
uhigh=@(z)sigmamf(z,0.53,0.73);
unorm=@(z)1-sigmamf(z,0.18,0.33);
umarg=@(z)trapezmf(z,0.23,0.35,0.53,0.69);ufail=@(z)sigmamf(z,0.59,0.78);
rules = {ulow; umid; uhigh; }
L=lambdafcns(rules);
39/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 40/62
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 41/62
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 42/62
udark=@(z)1-sigmamf(z,0.35,0.5);
ugray=@(z)triangmf(z,0.35,0.5,0.65);
ubright=@(z)sigmamf(z,0.5,0.65);
udarker=@(z)bellmf(z,0.0,0.1);
umidgray=@(z)bellmf(z,0.4,0.5);
ubrighter=@(z)bellmf(z,0.8,0.9);
42/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 43/62
Output membership functions(darker, midgray, brighter)
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 44/62
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.5
1
1.5
Intensity of output figure(v)
D e g r e e o f m
e m b e r s h i p
µdarker
(v)
µgrayer(v)µ
brighter(v)
44/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 45/62
% System response functions
rules={udark;ugray;ubright};
outmf={udarker,umidgray,ubrighter};
F=fuzzysysfcn(rules,outmf,[0 1]);
% Read image(will be of class uint8)
f image=imread(’saturnus.JPG’);
z=linspace(0,1,256);
% Construct the intensity transformation function
T=F(z);
% Transform the intensities of f image by using T
g image=intrans(f image,’specified’,T);
figure;
imshow(g image);
45/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 46/62
46/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 47/62
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 48/62
In the following tables z i are marked as intensity values of a
pixel and d i = z i − z 5 are marked as the intensity differencebetween center pixel z 5.
z 1 z 2 z 3z 4 z 5 z 6z
7 z
8 z
9
d 1 d 2 d 3d 4 0 d 6d 7 d 8 d 9
48/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 49/62
From the previous tables we can form following rules forboundary recognition
IF d 2 is zero AND d 6 is zero THEN make z 5 white
IF d 6 is zero AND d 8 is zero THEN make z 5 white
IF d 8 is zero AND d 4 is zero THEN make z 5 white
IF d 4 is zero AND d 2 is zero THEN make z 5 white
ELSE make z 5 black
To simplify the case only four of the neighbor pixels are used.
49/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 50/62
We have four rules(+else) and four inputs.
Each row in the following matrix corresponds to one rule.
Next we need to define the membership functions for
zero(input), white(output) and black(output).
50/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 51/62
Let us assume that our image has L different intensity levels.Then the intensity differences can range between −(L − 1)and L − 1.
It is clear that our output picture also has L different intensity
levels.In this example we fix L = 256
In other words we are using an image of class uint8
51/ 62 Sami Hokuni Fuzzy techniques in image processing
Input membership function(zero)
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 52/62
−255 0 255
0
0.2
0.4
0.6
0.8
1
Intensity differences(z)
D e g r e e o f m
e m b e r s h i p
µzero
(z)
52/ 62 Sami Hokuni Fuzzy techniques in image processing
Output membership functions(black and white)
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 53/62
0 50 100 150 200 250
0
0.2
0.4
0.6
0.8
1
Intensity of the output image(v)
D e g r e e o f m
e m b e r s h i p
µblack
(v)
µwhite(v)
53/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 54/62
% MAKEFUZZYEDGES Script
% Input membership functions
zero=@(z)bellmf(z,-0.3,0);
not used=@(z)onemf(z);
% Output membership functions
black=@(z)triangmf(z,0,0,0.75);
white=@(z)triangmf(z,0.25,1,1);
% There are four rules and four inputs
inmf={zero, not used, zero, not used
not used, not used, zero, zeronot used, zero, not used, zero
zero, zero, not used, not used}
54/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 55/62
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 56/62
function g=fuzzyfilt(f)
% Cast f onto floating point
[f,revertclass]=tofloat(f)
% Count the intensity differences
z1=imfilter(f,[0 -1 1],’conv’,’replicate’);
z2=imfilter(f,[0; -1; 1],’conv’,’replicate’);
z3=imfilter(f,[1;-1;0],’conv’,’replicate’);
z4=imfilter(f,[1 -1 0], ’conv’,’replicate’);
% Load the previously made script and use it
s=load(’fuzzyedgesys’);
g=s.G(z1,z2,z3,z4);
g=revertclass(g);
56/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 57/62
57/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 58/62
58/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 59/62
59/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 60/62
In the previous pictures we saw that constant regions of theimage appeared gray.
When intensity differences are close to zero we apply theTHEN rules.
Output is then some constant between L−1
2 and L − 1, whatproduces the grayish tone to the image
This can be ”fixed” by using function mat2gray.
60/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 61/62
61/ 62 Sami Hokuni Fuzzy techniques in image processing
8/13/2019 Ho Kuni 120412
http://slidepdf.com/reader/full/ho-kuni-120412 62/62