Skip to content
Snippets Groups Projects
Commit 17d31eed authored by igraf's avatar igraf
Browse files

Add feature representation part

parent 1f7c71b1
No related branches found
No related tags found
No related merge requests found
......@@ -105,6 +105,66 @@ To visually represent the **class-wise distribution**, we plotted a histogram:
*Balance of Dataset*: The histogram provides visual and easy to see insights into whether the dataset is balanced or unbalanced. In our case, the dataset is mostly balanced. The apple class is slightly overrepresented and the nectarine, orange and jostaberry classes may have insufficient datapoints. We will keep an eye on the performance of our models on these classes to see if the imbalance has an impact on the model's ability to learn and predict these classes 🔍.
### Feature Representation
The features we can use for training our models are always based on the **pixel values** of the images.
In the dummy example below, there is a 3x3 pixel image. Each pixel has three values: intensity of red, green and blue (**RGB**).
<img align="center" width="100%" height="auto" src="figures/image_features.png" title="test">
By concatenating the color values of one pixel and then concatenating the pixels, we can represent the image as a 1D vector. The length of the vector is then equal to the number of pixels in the image multiplied by 3 (RGB).
**Example from the dataset**:
- 260 x 380 pixels in the example image
- => 1D vector with length 260 x 380 x 3 = 296,400
![Example image](figures/examples_from_dataset/banana.jpg)
| | Pixel 1 | Pixel 2 | Pixel 3 | ... | Pixel 381 (=second row) | ... | Pixel height x width = 98,800 |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Red | 245 | 245 | 245 | ... | 245 | ... | 50 |
| Green | 204 | 204 | 204 | ... | 204 | ... | 41 |
| Blue | 99 | 99 | 101 | ... | 99 | ... | 32 |
↪️ See how the pixel data is extracted from the sample image in [`extract_features.py`](minimal_examples/extract_features.py)
*What does the pixel data tell us about the image?*
- the pixel in the top left corner has the RGB values (245, 204, 99) (:yellow_circle:)
- the pixel in the bottom right corner has the RGB values (50, 41, 32) (= brown/black :brown_circle:)
### Resizing Images
Because we need the same number of features for each image, we have to **resize** all images to the same size. Doing this also reduces the amount of data to be processed and speeds up the training process. However, resizing images can also lead to a loss of information, especially if the images are resized to a very small size.
### Feature Engineering With Filters
As already mentioned in the [Related Work](#related-work) section, applying different filters to the images can improve the model's performance. We are experimenting with the following filters:
- **Grayscaling**:
- reduces the image to a single channel, which can be beneficial for reducing computational complexity
- in general, more useful for tasks where color is not important
- **Canny** edge detection:
- detects edges in the images
- threshold can be adjusted to detect more or less edges
- only black and white information
- **HSV** (Hue, Saturation, Value) color space:
- separately represents the intensity of the color (Hue), the saturation (how pure the color is) and the value (brightness).
- is said to be more robust to changes in lighting conditions and can improve the model's performance
- **Sobel** edge detection:
- detects edges in the images
- keeps some color information
Gray | Canny | HSV | Sobel |
:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:
![Gray](figures/examples_from_dataset/banana-gray.jpg) | ![Canny](figures/examples_from_dataset/banana-edges.jpg) | ![HSV](figures/examples_from_dataset/banana-hsv.jpg) | ![Sobel](figures/examples_from_dataset/banana-sobel.jpg) |
## Metrics
To evaluate classification models, the following metrics are commonly used:
......@@ -244,6 +304,7 @@ We have conducted a series of experiments to evaluate the performance of differe
To reproduce the results, please refer to the [README](src/README.md) in the src folder for instructions on how to run the experiments.
### Feature Engineering
- we are experimenting with different feature combinations, which can be used as an input parameter for our `classify_images.py` script
| Feature / Filter | Length | Description |
......@@ -252,6 +313,8 @@ To reproduce the results, please refer to the [README](src/README.md) in the src
| `hsv` | the images are converted to HSV color space and the HSV values are used as features |
| `sobel` | 7500 | the images are
We have experimented with different sizes and found that 50x50 pixels is a good compromise between the amount of data to be processed and the quality of the images.
### Naive Bayes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment