<jupyter_start><jupyter_text>Feature extraction- Fourier transform- Wavelet transform- Histogram of Oriented Gradients(HOG)- Speeded Up Robust Features (SURF)- Local Binary Patterns (LBP)- Color histograms        => Feature extraction require domain knowledge        => Convolution = detect local pattern  Data types| Types       | Example                   | shape      || ------------|:-------------------------:| ----------:||  Scalar     | 354556                    | no shape   ||   2D vector     |[5, 9]:          | (2,)       ||   3D vector          |[1, 2, 3]:        | (3,)       ||   5D vector          |[4, 9, 10, 22, 6]:| (5,)       ||  matrix     | [[0, 1, 0],               | (2,3)      ||             |  [8, 5, 9]]               |            || tensor (order = 3) | [[[0, 1, 0],       | (2,2,3)  ||                    | [8, 5, 9]],        ||                    | [[5, 4, 3],        | ||                    | [2, 3, 7]]]   | |  Example 4x4 color image = tensor (4, 4, 3)<jupyter_code>img = np.random.randint(255, size=(4, 4, 3), dtype='uint8')
plt.imshow(img);
plt.figure(figsize=(5, 5))
plt.subplot(221)
plt.imshow(img)
plt.title("All Channels combined")

plt.subplot(222)
plt.imshow(img[:, : , 0], cmap='Reds')
plt.title("Red channel")

plt.subplot(223)
plt.imshow(img[:, : , 1], cmap='Greens')
plt.title("Green channel")

plt.subplot(224)
plt.imshow(img[:, : , 2], cmap='Blues')
plt.title("Blue channel")<jupyter_output><empty_output><jupyter_text>Convolution- convolution = to detect a pattern- If a pattern match = high value in convolution result<jupyter_code>a = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], dtype='float32')
b = np.array([-1, 1], dtype='float32') # edge detection

c = np.convolve(a, b)
plt.subplot(211)
plt.plot(a, 'o-')
plt.plot(b, 'o-')

plt.subplot(212)
plt.plot(c, 'o-')<jupyter_output><empty_output><jupyter_text>Image filters with convolutions<jupyter_code>from scipy.ndimage.filters import convolve
from scipy.signal import convolve2d
from scipy import misc
# Image
img = misc.ascent()

# Kernel - Highlight horizontal line
h_kernel = np.array([[ 1,  2,  1],
                     [ 0,  0,  0],
                     [-1, -2, -1]])

# Convolution
res = convolve2d(img, h_kernel)
plt.subplot(131)
plt.imshow(img, cmap='gray');
plt.title("Image");

plt.subplot(132)
plt.imshow(h_kernel, cmap='gray');
plt.title("Kernel - filter");

plt.subplot(133)
plt.imshow(res, cmap='gray');
plt.title("Result");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19298952457695406, 'fraction_numerical': 0.0499597099113618, 'mean_word_length': 2.5169971671388103, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '453058', 'license': 'Unlicense', 'n_tokens_mistral': 1007, 'n_tokens_neox': 881, 'n_words': 217, 'path': 'CourseUdemy_Keras/4_CNN/2_Features_Tensor.ipynb', 'repo_name': 'dangkhoa1992/Advanced-Machine-Learning-Specialization', 'size': '2482'}