<jupyter_start><jupyter_text>Image to featuresRead an image with opencv.<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('ggplot')
from jyquickhelper import add_notebook_menu
add_notebook_menu()<jupyter_output><empty_output><jupyter_text>OpenCV<jupyter_code>import numpy as np
import argparse
import cv2
from numpy import matrix
import os
from functools import reduce

# create NumPy arrays from the boundaries
lower = np.array([0, 0, 0], dtype = "uint8")
upper = np.array([100, 115, 240], dtype = "uint8")

i=0
List= []
folder = "tomates"

if not os.path.exists(folder):
    raise FileNotFoundError(os.path.abspath(folder))

for element in os.listdir(folder):
    i+=1
    # load the image
    image = cv2.imread(os.path.join(folder, element))
    res = cv2.resize(image,(100, 100), interpolation = cv2.INTER_CUBIC)

    # find the colors within the specified boundaries and apply the mask
    mask = cv2.inRange(res, lower, upper)
    output = cv2.bitwise_and(res, res, mask = mask)
    shape = output.shape
    nb = reduce(lambda a,b: a*b, shape)
    mat = output.reshape((1, nb))
    List.append(mat)
    print(element, mat.shape)

bigmat = np.vstack(List)
bigmat.shape
from pyquickhelper.helpgen import NbImage
NbImage("tomates/imgt_61.jpg")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11332312404287902, 'fraction_numerical': 0.023736600306278714, 'mean_word_length': 4.860986547085202, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '491180', 'license': 'MIT', 'n_tokens_mistral': 479, 'n_tokens_neox': 459, 'n_words': 119, 'path': '_doc/notebooks/cheat_sheets/image_features.ipynb', 'repo_name': 'sdpython/ensae_projects', 'size': '1306'}