Pergunta

I'm working on a color image segmentation in HSV color space using Matlab fuzzy toolbox. the goal is to read an RGB image->convert to hsv->use H,S,V values as an input for fuzzy system and then find which class(here is our 16 constant output color) does this pixel belongs. here is the fuzzy system :

"The reasoning procedure is based on a zero-order Takagi-Sugeno model, so that the consequent part of each fuzzy rule is a crisp discrete value of the set{Black, White, Red, Orange,etc}. Since this model has 10 fuzzy sets for Hue, 5 for Saturation and 4 for Value, the total number of rules required for this model is 10*5*4=200".(1)

The problem is that when I use this line in my program to get output value

segimg=reshape(evalfis([h s v],hsvRuleSugeno),imgh,imgw);

the out put is not any of my constant classes, because it uses centroid for defuzzification and as you see below I can't rely on it, as an output !

I search many papers and websites but I think it's so simple that no one explained it! I'm missing something or probably i don't have enough knowledge would you please help me to understand this problem ?

reference: (1): Human Perception-based Color Segmentation Using Fuzzy Logic,Lior Shamir Department of Computer Science, Michigan Tech.

Foi útil?

Solução

The paper explains the computation process in section 2.3. You do not need non-discrete or centroid value as obtained from evalfis. I'm assuming you have made all the rules which must be giving one of the 16 classes as output. That means each each output class is associated with at least one rule. According to the paper, you need to:

  1. Make 16 groups containing rules associated to each output class. One group for yellow, one for white and one for black so on...
  2. Calculate the strength of each and every rule.
  3. For each group, find summation of strength value of all the rules contained in that group.
  4. Then find the group with maximum cumulative sum of strength of its contained rules.

To achieve this, we cannot rely on centroid based defuzzified value. I checked the documentation on evalfis and below is script that should be able to perform above algorithm. Idea is to collect strength of each rule, order the rules into groups based on rule's output class, then find summation of each group and find maximum.

[output, IRR, ORR, ARR] = evalfis(input, fismat)
m = cat(2, ORR, ARR);
m = sortrows(m, 1)

r = [];
for l = 2 : size(m, 1)
    if m(l, 1) ~= m(l - 1, 1)
        r = cat(1, r, m(l - 1, :));
    else
        m(l, 2) = m(l, 2) + m(l - 1, 2);
    end
end

if size(m, 1) >= 2
    r = cat(1, r, m(size(m, 1), :));
end

% r now contains the final class to be choosen
disp(r)

Outras dicas

Thanks a lot for your answer Shivam, Actually your code has an error but I got the idea and started working on it, and finally found what to do ! here is what I use and the result was OK ! now I have to work on adjusting rules to get better results

for i=1:imh
    for j=1:imw
        [output, IRR, ORR, ARR] = evalfis([h(i,j);s(i,j);v(i,j)], hsvRuleSugeno);
        m = cat(2,ARR,ORR);
        [trash,idx] = unique(m(:,1),'first');
        out = m(sort(idx),:);
        out(:,[1,2])=out(:,[2,1]);
        out = sortrows(out, 1);
         res=zeros(size(out));
           for l = 2 : size(out, 1)
                if out(l, 1) == out(l - 1, 1)
                res(l-1,1) = out(l-1,1);
                res(l-1,2) = out(l-1,2)+out(l,2);
                else
                res(l,1) = out(l,1);
                res(l,2) = out(l,2);  
                end
           end
           [num idx] = max(res(:,2));
           [x y] = ind2sub(size(res),idx);
          segimg(i,j)=res(x,y)/10;    
    end
end

the segment result :http://i45.tinypic.com/2aj9mg.jpg

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top