<jupyter_start><jupyter_text>Extracting Features from Images Obtaining pixel intensities for image and transforming those into usable features  Installation of opencv may be requiredOpenCV == Open Source Computer Vision Library<jupyter_code>!pip install opencv-python
import cv2<jupyter_output><empty_output><jupyter_text>Load an image from which to extract RGB pixel intensities<jupyter_code># Image with dimensions 173x130
imagePath = '../data/dog.jpg'

image = cv2.imread(imagePath)<jupyter_output><empty_output><jupyter_text>View image using matplotlib<jupyter_code>%matplotlib inline

import matplotlib
import matplotlib.pyplot as plt

plt.imshow(image)<jupyter_output><empty_output><jupyter_text>Image array contains RGB values for each pixel in the image<jupyter_code>image.shape
image<jupyter_output><empty_output><jupyter_text>Each pixel has RGB intensities<jupyter_code>image[0][0]<jupyter_output><empty_output><jupyter_text>Scale this image to a smaller size<jupyter_code>size=(32, 32)
resized_image_feature_vector = cv2.resize(image, size)
plt.imshow(resized_image_feature_vector)
resized_image_feature_vector.shape
resized_image_feature_vector<jupyter_output><empty_output><jupyter_text>Image array can be flattened into a one-dimensional array<jupyter_code>resized_flattened_image_feature_vector = resized_image_feature_vector.flatten()
len(resized_flattened_image_feature_vector)
image_grayscale = cv2.imread(imagePath, cv2.IMREAD_GRAYSCALE )
plt.imshow(image_grayscale)
image_grayscale.shape
image_grayscale
import numpy as np

expanded_image_grayscale = np.expand_dims(image_grayscale, axis=2)
expanded_image_grayscale.shape
expanded_image_grayscale<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07193396226415094, 'fraction_numerical': 0.01061320754716981, 'mean_word_length': 10.703448275862069, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '21711', 'license': 'MIT', 'n_tokens_mistral': 602, 'n_tokens_neox': 570, 'n_words': 111, 'path': '07 Prepare Your Data For Machine Learning/0.3 Image Feature Processing.ipynb', 'repo_name': 'IshmaelAsabere/Machine_Learning-Various-Topics', 'size': '1696'}