# Liu-Wang

## Proposal of fuzzy sets <a href="#proposal-of-fuzzy-sets" id="proposal-of-fuzzy-sets"></a>

Seven categories are defined: red, orange, yellow, green, cyan, blue and purple. By default, each of the classes is represented by the following colour:

| Colour label | Index |     RGB value    | HEX value |
| ------------ | :---: | :--------------: | :-------: |
| Red          |   0   |  \[255, 33, 36]  |  #FF2124  |
| Orange       |   1   |  \[248, 149, 29] |  #F8951D  |
| Yellow       |   2   |  \[239, 233, 17] |  #EFE911  |
| Green        |   3   |  \[105, 189, 69] |  #69BD45  |
| Cyan         |   4   | \[111, 204, 221] |  #6FCCDD  |
| Blue         |   5   |  \[59, 83, 164]  |  #3B53A4  |
| Purple       |   6   |  \[158, 80, 159] |  #9E509F  |

{% hint style="info" %}
The colour associated with each label can be changed when calling the function that performs the segmentation. By default, they are the colours shown in the table above.
{% endhint %}

{% hint style="danger" %}
The indices of the colours must be positive integers. Negative integers are reserved for the internal calculation of the methods.
{% endhint %}

## Partition of the chromatic space

The H channel, whose values must be in range $$\[0, 360]$$, is partitioned using trapezoidal membership functions. For the sake of clarity, the parameters $$a$$, $$b$$, $$m$$, $$n$$ which uniquely determine the expression of the membership function are given. For more information, see section [Fuzzy Logic-based methods](https://mmunar97.gitbook.io/colour-segmentation/whats-behind/fuzzy-logic-based-methods/..#the-background-framework-fuzzy-logic-and-fuzzy-sets).

| Colour label | $$a$$ | $$b$$ | $$m$$ | $$n$$ |
| ------------ | :---: | :---: | :---: | :---: |
| Red          |  300  |   20  |  330  |   10  |
| Orange       |   10  |   55  |   20  |   40  |
| Yellow       |   40  |   80  |   55  |   65  |
| Green        |   65  |  170  |   80  |  140  |
| Cyan         |  140  |  210  |  170  |  200  |
| Blue         |  200  |  270  |  210  |  250  |
| Purple       |  250  |  330  |  270  |  300  |

{% hint style="warning" %}
In the definition of the red colour, it can be seen that it is not verified that $$a\<m\<n\<b$$. This is because the chromatic component H of the HSV colour space is circular, and the red colour is the one located on the boundary.
{% endhint %}

## Initial colour balance

Liu's method proposes an initial colour balance in order to correct excess lighting or contrast. The method they use is the Gray World method. The transformation carried out is as follows:

1. Convert the RGB image, where each R,G,B channel has discrete range $$\[0, 255]$$, to range $$\[0,1]$$.
2. Calculate the average of each channel, and calculate the average of the three previous averages. Say $$\lambda$$ to this value:

$$
\lambda = \dfrac{\overline{R}+\overline{G}+\overline{B}}{3}
$$

&#x20;  3\. Make a scale change to each channel. The scale in each case will be $$s\_i=\dfrac{\lambda}{\overline{C\_i}}$$.

$$
R' = \dfrac{\lambda}{\overline{R}}\cdot R, \qquad G' = \dfrac{\lambda}{\overline{G}}\cdot G, \qquad B' = \dfrac{\lambda}{\overline{B}}\cdot B
$$

&#x20;  4\. Correct possible out-of-range values. The scale factor $$s\_i$$ may be greater than 1 in some situations,   so it is necessary to set values greater than 1 to 1, and values less than 0 to 0.

## References

> **Liu, C.; Wang, L.**. (2016) *Fuzzy color recognition and segmentation of robot vision scene.* Proceedings: CISP 2015 - 8th International Congress of Image Signal.
