> For the complete documentation index, see [llms.txt](https://mmunar97.gitbook.io/colour-segmentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mmunar97.gitbook.io/colour-segmentation/examples/examples-of-fuzzy-logic-based-methods.md).

# Examples of Fuzzy Logic-based methods

## Example image

Let us consider the following image, which we want to segment.

![](/files/-Mitp5_Ai8hlyRUQzHdt)

We load the image, and initialise the `Segmentator` object to proceed with the segmentation.

```python
import cv2 
from colour_segmentation.base.segmentation_algorithm import SegmentationAlgorithm
from colour_segmentation.segmentator import Segmentator

segmentator = Segmentator(image=cv2.imread(r"assets/nectarine.jpg"))
```

## Results

For each of the above methods, we will apply the segmentation with and without the achromatic colours.

#### Amante-Fonseca

```python
result_amante_fonseca_achr = segmentator.segment(method=SegmentationAlgorithm.FUZZY_SET_AMANTE,
                                                 remove_achromatic_colours=False)
result_amante_fonseca_chr = segmentator.segment(method=SegmentationAlgorithm.FUZZY_SET_AMANTE,
                                                remove_achromatic_colours=True)
```

![Example of segmentation using Amante-Fonseca without removing achromatic colours (left) and removing achroomatic colours (right).](/files/-MitwrDFkMAyWr-N0tI5)

#### Chamorro-Martínez

```python
result_chamorro_achr = segmentator.segment(method=SegmentationAlgorithm.FUZZY_SET_CHAMORRO,
                                           remove_achromatic_colours=False)
result_chamorro_chr = segmentator.segment(method=SegmentationAlgorithm.FUZZY_SET_CHAMORRO,
                                              remove_achromatic_colours=True)
```

![Example of segmentation using Chamorro-Martínez without removing achromatic colours (left) and removing achroomatic colours (right).](/files/-MitwrDH_I1IvZ4zEXNb)

#### Liu-Wang

```python
result_liu = segmentator.segment(method=SegmentationAlgorithm.FUZZY_SET_LIU,
                                 apply_colour_correction=False,
                                 remove_achromatic_colours=True)
result_liu_corrected = segmentator.segment(method=SegmentationAlgorithm.FUZZY_SET_LIU,
                                           apply_colour_correction=True,
                                           remove_achromatic_colours=True)
```

![Example of segmentation using Liu-Wang applying without applying colour correction (left) and applying colour correction (right). In both images achromatic colours have been removed.](/files/-MitwrDGvHN2hg-iV_VR)

#### Shamir

```python
result_shamir_achr = segmentator.segment(method=SegmentationAlgorithm.FUZZY_SET_SHAMIR,
                                         remove_achromatic_colours=False)
result_shamir_chr = segmentator.segment(method=SegmentationAlgorithm.FUZZY_SET_SHAMIR,
                                        remove_achromatic_colours=True)
```

![Example of segmentation using hamir without removing achromatic colours (left) and removing achroomatic colours (right).](/files/-MitwrDIDwJ63bEALmwt)
