Anda di halaman 1dari 62

Fuzzy techniques in image processing

Sami Hokuni

April 12, 2012

1/ 62

Sami Hokuni

Fuzzy techniques in image processing

In a traditional set theory an element has only two options: it either belongs totally to some set or it doesnt belong there at all. If we have set A such that [0, 1] A, then x = 1 belongs totally to the set A y = 2 doesnt belong at all to the set A This method is not very exible if we have some imprecision

2/ 62

Sami Hokuni

Fuzzy techniques in image processing

Let us assume that we have set Z of all people. From this set we would want to dene a subset A called young people. To dene 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 dont belong to this subset at all.

3/ 62

Sami Hokuni

Fuzzy techniques in image processing

In this case we would need more exible system, which would have some kind of gradual transition Young relatively young somehow young not so young not at all young. Fuzzy logic oers us a way to do this kind of transitions.

4/ 62

Sami Hokuni

Fuzzy techniques in image processing

Fuzzy set is characterized by its membership function . Let us assume that we have fuzzy set A in set Z , and z is some 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 element belongs to the subset.

5/ 62

Sami Hokuni

Fuzzy techniques in image processing

If A (z )=1, then z belongs totally to the fuzzy set A. If A (z )=0, then z doesnt 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

Fuzzy set A is an ordered pair consisting of values z Z and a membership function that gives the degree of membership to 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 to the subset young people at all.

7/ 62

Sami Hokuni

Fuzzy techniques in image processing

8/ 62

Sami Hokuni

Fuzzy techniques in image processing

Membership value is not the same as probability. For example, in the gure on the last slide we saw that the membership value for z = 25 was 0.5. Probablilistic statement: There is 50% chance that this person is young. Here person is considered to either be in the set of young people or not in that set. Fuzzy statement: Person is young to some degree, and here this degree is 0.5. Fuzzy logic is characterized by imprecision, not by randomness.

9/ 62

Sami Hokuni

Fuzzy techniques in image processing

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 and only 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 . , is the set Complement of a fuzzy set(NOT) A, denoted by A whose membership function is A (z ) = 1 A (z ) for all z Z .

10/ 62

Sami Hokuni

Fuzzy techniques in image processing

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 , denoted A 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

Membership function can be dened in many dierent 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

Triangular

13/ 62

Sami Hokuni

Fuzzy techniques in image processing

Trapezoidal

14/ 62

Sami Hokuni

Fuzzy techniques in image processing

Sigmoidal

15/ 62

Sami Hokuni

Fuzzy techniques in image processing

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 to measure 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 on them might be a good idea.

16/ 62

Sami Hokuni

Fuzzy techniques in image processing

1
low

(z)
mid

(z)

high

(z)

0.8 Degree of membership : (z)

0.6

0.4

0.2

10

20

30 40 50 Average vibration frequency : z

60

70

80

17/ 62

Sami Hokuni

Fuzzy techniques in image processing

Based on previous denitions we can come up with following fuzzy IF-THEN rules: IF the frequency is low, THEN motor operation is normal (R1 ) OR IF the frequency is mid, THEN motor operation is marginal (R2 ) OR IF the frequency is high, THEN motor operation is near failure (R3 )

18/ 62

Sami Hokuni

Fuzzy techniques in image processing

Next we need to decide what kind of output we want to create from these rules In this case we select percent of operational abnormality. Inputs were characterized into three fuzzy classes: low, mid and high. Now outputs will also be characterized into three fuzzy classes: normal, marginal and near failure.

19/ 62

Sami Hokuni

Fuzzy techniques in image processing

1
norm

(v)

marg

(v)

fail

(v)

0.8

Degree of membership

0.6

0.4

0.2

10

20

30

40 50 60 Abnormality in percents : v

70

80

90

100

20/ 62

Sami Hokuni

Fuzzy techniques in image processing

IF the frequency is low, THEN motor operation is normal (R1 ). This rule relates low AND normal. There is nothing more than intersection operation AND, which we dened 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

However, we are interested in outputs due to some specic input z0 . The degree of membership of z0 in terms of the low membership function is low (z0 ). To obtain the output corresponding to the rule R1 and input z0 , we use AND operator to the specic value low (z0 ) and 1 (z0 , v ) (general solution evaluated at z0 ).

22/ 62

Sami Hokuni

Fuzzy techniques in image processing

Therefore we get Q1 (v ) = min {low (z0 ), 1 (z0 , v )} = min low (z0 ), min low (z0 ), norm (v )
constant

= min {low (z0 ), norm (v )}

Now Q1 (v ) denotes the fuzzy output due to rule R1 and specic input z0 .

23/ 62

Sami Hokuni

Fuzzy techniques in image processing

In a similar way we can write for rules R2 and R3 and specic input z0 Q2 (v ) = min {mid (z0 ), marg (v )} Q3 (v ) = min {high (z0 ), fail (v )} Each of Q1 , Q2 and Q3 are now outputs associated with a particular rule and a specic input.

24/ 62

Sami Hokuni

Fuzzy techniques in image processing

Now we need to obtain the overall response in this fuzzy system. In other words we need to combine Q1 , Q2 and Q3 into one Q . Originally: R1 OR R2 OR R3 . Therefore complete fuzzy output is given by Q (v ) = Q1 (v ) OR Q2 (v ) OR Q3 (v )

25/ 62

Sami Hokuni

Fuzzy techniques in image processing

OR was previously denes as a max operation Therefore Q (v ) = max {Q1 (v ), Q2 (v ), Q3 (v )} = max min {s (z0 ), t (v )}
r s ,t

where r = {1, 2, 3},s = {low , mid , high} and t = {norm, marg , fail }. Here s and t are paired combinations. Although Q (v ) was developed specically for this example, it would be generalized to n rules. Then r = {1, 2, , n}.

26/ 62

Sami Hokuni

Fuzzy techniques in image processing

z0 is some specific input value

1 norm(v) marg(v) fail(v)

0.8 high(z0) 0.6

Degree of membership

0.4 mid(z0)

0.2

low(z0) 0

10

20

30

40 50 60 Abnormality in percents : v

70

80

90

100

27/ 62

Sami Hokuni

Fuzzy techniques in image processing

Q (v) 1 Q (v) 2 Q (v)


3

0.8

Degree of membership

0.6

0.4

0.2

10

20

30

40 50 60 Abnormality in percents : v

70

80

90

100

28/ 62

Sami Hokuni

Fuzzy techniques in image processing

0.8

Degree of membership

0.6

0.4

Q(v)
0.2

10

20

30

40 50 60 Abnormality in percents : v

70

80

90

100

29/ 62

Sami Hokuni

Fuzzy techniques in image processing

Now we have acquired a complete output corresponding to a specic input. However, we are still dealing with a fuzzy step. Finally we have to obtain a crisp output v0 from a fuzzy set Q (defuzzication). One common approach to this is to count the center of gravity of Q (v ) vQ (v )dv v0 = . Q (v )dv where both integrals are taken over the range of values of v .

30/ 62

Sami Hokuni

Fuzzy techniques in image processing

For example, let us assume that z0 = 0.7. By counting center of gravity for this z 0 we obtain v0 = 0.76. If an engine has frequency value of 0.7 it is operating with a 76% degree of abnormality.

31/ 62

Sami Hokuni

Fuzzy techniques in image processing

In this example rules were rather simple and had only one part(IF...THEN) If rules have more than one part, all parts have to be taken into account in fuzzication.

32/ 62

Sami Hokuni

Fuzzy techniques in image processing

For example, let us assume that we have another variable called temperature. Now we would have to dene a membership function also for temperature. 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

Membership function for the rst 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 specic frequency z0 and temperature t0 .

34/ 62

Sami Hokuni

Fuzzy techniques in image processing

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 (Q1 , Q2 , Q3 ). 4. Apply an aggregation method for fuzzy sets acquired in phase 3 (Q ). 5. Defuzzify the nal output set (center of gravity).

35/ 62

Sami Hokuni

Fuzzy techniques in image processing

Nested functions are dened 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

function y = tax(income) adjusted income = income - 6000; y = compute tax function y = compute tax y = 0.28*adjusted income; end end

37/ 62

Sami Hokuni

Fuzzy techniques in image processing

Implementations for membership functions mentioned in the book triangmf(z,a,b,c), (Triangular) trapezmf(z,a,b,c,d), (Trapezoidal) sigmamf(z,a,b), (Sigmoidal) smf(z,a,b) bellmf(z,a,b) truncgaussmf(z,a,b,s) zeromf(z), (All membership values are zeros) onemf(z), (All membership values are ones)

38/ 62

Sami Hokuni

Fuzzy techniques in image processing

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

z=0.7; outputmfs={unorm,umarg,ufail}; Q=implfcns(L,outputmfs,z); Qagg=aggfcn(Q); result=defuzzify(Qagg,[0 1]) result = 0.7619

40/ 62

Sami Hokuni

Fuzzy techniques in image processing

How to use fuzzy sets on intensity transformations? Contrast enhancement can be expressed in terms of following rules IF a pixel is dark THEN make it darker IF a pixel is gray THEN make it gray IF a pixel is bright THEN make it brighter

41/ 62

Sami Hokuni

Fuzzy techniques in image processing

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

Input membership functions(dark, gray, bright)

0.8 Degree of membership

0.6

dark gray

(z)

(z) (z)

0.4

bright

0.2

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Intensity of original figure(z) 0.8 0.9 1

43/ 62

Sami Hokuni

Fuzzy techniques in image processing

Output membership functions(darker, midgray, brighter)


1.5

darker grayer

(v)

(v) (v)

brighter

Degree of membership

0.5

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Intensity of output figure(v) 0.8 0.9 1

44/ 62

Sami Hokuni

Fuzzy techniques in image processing

% 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

46/ 62

Sami Hokuni

Fuzzy techniques in image processing

How to use fuzzy sets on spatial ltering? The basic approach is to focus on neighbors of some certain pixel. For example, we could make a fuzzy boundary detection algorithm by using the following rule IF a pixel belongs to a uniform region THEN make it white ELSE make it black

47/ 62

Sami Hokuni

Fuzzy techniques in image processing

In the following tables zi are marked as intensity values of a pixel and di = zi z5 are marked as the intensity dierence between center pixel z5 . z1 z4 z7 d1 d4 d7 z2 z5 z8 d2 0 d8 z3 z6 z9 d3 d6 d9

48/ 62

Sami Hokuni

Fuzzy techniques in image processing

From the previous tables we can form following rules for boundary recognition IF d2 is zero AND d6 is zero THEN make z5 white IF d6 is zero AND d8 is zero THEN make z5 white IF d8 is zero AND d4 is zero THEN make z5 white IF d4 is zero AND d2 is zero THEN make z5 white ELSE make z5 black

To simplify the case only four of the neighbor pixels are used.

49/ 62

Sami Hokuni

Fuzzy techniques in image processing

We have four rules(+else) and four inputs. Each row in the following matrix corresponds to one rule. Next we need to dene the membership functions for zero(input), white(output) and black(output).

50/ 62

Sami Hokuni

Fuzzy techniques in image processing

Let us assume that our image has L dierent intensity levels. Then the intensity dierences can range between (L 1) and L 1. It is clear that our output picture also has L dierent intensity levels. In this example we x 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)


zero(z)

0.8 Degree of membership

0.6

0.4

0.2

0 255 0 Intensity differences(z) 255

52/ 62

Sami Hokuni

Fuzzy techniques in image processing

Output membership functions(black and white)


(v) (v)

black white

0.8 Degree of membership

0.6

0.4

0.2

0 0 50 100 150 Intensity of the output image(v) 200 250

53/ 62

Sami Hokuni

Fuzzy techniques in image processing

% 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, zero not used, zero, not used, zero zero, zero, not used, not used}

54/ 62

Sami Hokuni

Fuzzy techniques in image processing

outmf={white, white, white, white, black} vrange=[0,1] F=fuzzysysfcn(inmf,outmf,vrange); % Approximation method to reduce calculation times G=approxfcn(F,[-1 1; -1 1; -1 1; -1 1]); % Save all this to a mat file called fuzzyedgesys.mat save fuzzyedgesys G

% Inputs to the output membership functions are in the rang

55/ 62

Sami Hokuni

Fuzzy techniques in image processing

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

57/ 62

Sami Hokuni

Fuzzy techniques in image processing

58/ 62

Sami Hokuni

Fuzzy techniques in image processing

59/ 62

Sami Hokuni

Fuzzy techniques in image processing

In the previous pictures we saw that constant regions of the image appeared gray. When intensity dierences are close to zero we apply the THEN rules. Output is then some constant between produces the grayish tone to the image
L 1 2

and L 1, what

This can be xed by using function mat2gray.

60/ 62

Sami Hokuni

Fuzzy techniques in image processing

61/ 62

Sami Hokuni

Fuzzy techniques in image processing

62/ 62

Sami Hokuni

Fuzzy techniques in image processing