# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mmunar97.gitbook.io/colour-segmentation/examples/examples-of-fuzzy-logic-based-methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
