<reponame>linksdl/futuretec-project-self_driving_cars_projects<filename>udacity-program_self_driving_car_engineer_v1.0/part01-computer vision and deep learning/module04-computer vision/lesson02-gradients and color spaces/magnitude_of_gradient/mag_dir.py
"""
# !/usr/bin/env python
# -*- coding: utf-8 -*-
@Time        : 2022/2/28 20:51
@Author      : <EMAIL>
@ProjectName : udacity-program_self_driving_car_engineer_v1.0_source.0
@File        : mag_dir.py
"""


import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import pickle


# Read in an image
image = mpimg.imread('signs_vehicles_xygrad.png')

# Define a function that applies Sobel x and y,
# then computes the magnitude of the gradient
# and applies a threshold

def mag_thresh(img, sobel_kernel=3, mag_thresh=(0, 255)):
    # Apply the following steps to img
    # 1) Convert to grayscale
    # 2) Take the gradient in x and y separately
    # 3) Calculate the magnitude
    # 4) Scale to 8-bit (0 - 255) and convert to type = np.uint8
    # 5) Create a binary mask where mag thresholds are met
    # 6) Return this mask as your binary_output image
    binary_output = np.copy(img)  # Remove this line
    return binary_output


# Run the function
mag_binary = mag_thresh(image, sobel_kernel=3, mag_thresh=(30, 100))
# Plot the result
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(24, 9))
f.tight_layout()
ax1.imshow(image)
ax1.set_title('Original Image', fontsize=50)
ax2.imshow(mag_binary, cmap='gray')
ax2.set_title('Thresholded Magnitude', fontsize=50)
plt.subplots_adjust(left=0., right=1, top=0.9, bottom=0.)

vision and deep learning/module04-computer vision/lesson02-gradients and color spaces/magnitude_of_gradient/mag_dir.py
"""
# !/usr/bin/env python
# -*- coding: utf-8 -*-
@Time        : 2022/2/28 20:51
@Author      : <EMAIL>
@ProjectName : udacity-program_self_driving_car_engineer_v1.0_source.0
@File        : mag_dir.py
"""


import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import pickle


# Read in an image
image = mpimg.imread('signs_vehicles_xygrad.png')

# Define a function that applies Sobel x and y,
# then computes the magnitude of the gradient
# and applies a threshold

def mag_thresh(img, sobel_kernel=3, mag_thresh=(0, 255)):
    # Apply the following steps to img
    # 1) Convert to grayscale
    # 2) Take the gradient in x and y separately
    # 3) Calculate the magnitude
    # 4) Scale to 8-bit (0 - 255) and convert to type = np.uint8
    # 5) Create a binary mask where mag thresholds are met
    # 6) Return this mask as your binary_output image
    binary_output = np.copy(img)  # Remove this line
    return binary_output


# Run the function
mag_binary = mag_thresh(image, sobel_kernel=3, mag_thresh=(30, 100))
# Plot the result
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(24, 9))
f.tight_layout()
ax1.imshow(image)
ax1.set_title('Original Image', fontsize=50)
ax2.imshow(mag_binary, cmap='gray')
ax2.set_title('Thresholded Magnitude', fontsize=50)
plt.subplots_adjust(left=0., right=1, top=0.9, bottom=0.)
# !/usr/bin/env python # -*- coding: utf-8 -*- @Time        : 2022/2/28 20:51 @Author      : <EMAIL> @ProjectName : udacity-program_self_driving_car_engineer_v1.0_source.0 @File        : mag_dir.py # Read in an image # Define a function that applies Sobel x and y, # then computes the magnitude of the gradient # and applies a threshold # Apply the following steps to img # 1) Convert to grayscale # 2) Take the gradient in x and y separately # 3) Calculate the magnitude # 4) Scale to 8-bit (0 - 255) and convert to type = np.uint8 # 5) Create a binary mask where mag thresholds are met # 6) Return this mask as your binary_output image # Remove this line # Run the function # Plot the result