text_plain_output_5.png text_plain_output_4.png image_output_5.png text_plain_output_6.png text_plain_output_3.png image_output_4.png text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png image_output_3.png image_output_2.png image_output_1.png
import matplotlib.pyplot as plt

import tensorflow as tf

def show_image_with_filter(image, kernel):
    image = tf.image.convert_image_dtype(image, dtype=tf.float32)
    image = tf.expand_dims(image, axis=0)
    kernel = tf.reshape(kernel, [*kernel.shape, 1, 1])
    kernel = tf.cast(kernel, dtype=tf.float32)
    image_filter = tf.nn.conv2d(input=image, filters=kernel, strides=1, padding='SAME')
    image_detect = tf.nn.relu(image_filter)
    image_condense = tf.nn.pool(input=image_detect, window_shape=(2, 2), pooling_type='MAX', strides=(2, 2), padding='SAME')
    plt.axis('off')
    plt.axis('off')
    plt.axis('off')
    plt.axis('off')

import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
plt.rc('figure', autolayout=True)
plt.rc('axes', labelweight='bold', labelsize='large', titleweight='bold', titlesize=18, titlepad=10)
plt.rc('image', cmap='magma')
tf.config.run_functions_eagerly(True)
image_path = '../input/computer-vision-resources/car_illus.jpg'
image = tf.io.read_file(image_path)
image = tf.io.decode_jpeg(image, channels=1)
image = tf.image.resize(image, size=[400, 400])
random_kernel = tf.constant([[1, 2, 3], [-1, -2, -3], [0, 0, 0]])
edge_detect_kernel = tf.constant([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])
bottom_sobel_kernel = tf.constant([[-1, -2, -1], [0, 0, 0], [1, 2, 1]])
emboss_kernel = tf.constant([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]])
sharpen_kernel = tf.constant([[0, -1, 0], [-1, 5, -1], [0, -1, 0]])
print('\nRANDOM KERNEL:\n')
show_image_with_filter(image, random_kernel)
print('\nEDGE DETECT KERNEL:\n')
show_image_with_filter(image, edge_detect_kernel)
print('\nBOTTOM SOBEL KERNEL:\n')
show_image_with_filter(image, bottom_sobel_kernel)
print('\nEMBOSS KERNEL:\n')
show_image_with_filter(image, emboss_kernel)
print('\nSHARPEN KERNEL:\n')
show_image_with_filter(image, sharpen_kernel)