<reponame>Balaji-Ganesh/Furnishing-OpenCV-Basics
"""
Gradient: An Image gradient is the directional change in the intensity, color of an image.
"""

import cv2
import numpy as np
from matplotlib import pyplot as plt


img = cv2.imread('sudoku.png', cv2.IMREAD_GRAYSCALE)  # pass sudoku.png for better understanding

# Applying the gradient types on the image that read
# Laplacian Gradient
# lplcianGrdnt = cv2.Laplacian(img, cv2.CV_64F)  # passed CV_64 so, it can also accept the -ve float values. Why -ve values? :: while applying the laplacian transformation we may get -ve values, so to accept and store we are passing the datatype which can also take -values along with the +values.
# As we may have -values in our image array, we can't display it, so we need to convert to normal array(array with +values)
# We do this in pgmmatically through absolute function, which makes a -values into +values

lplcianGrdnt = cv2.Laplacian(img, cv2.CV_64F)
lplcianGrdnt = np.uint8(np.absolute(lplcianGrdnt))

# Sobel-X and Sobel-Y are the derivatives of the value w.r.t. X and Y axes respectively
# Here for both the sobel-X and sobel-Y, We use the same method named cv2.Sobel() method, The difference b/w sobel-X and sobel-Y is the 3rd parameter(dx) and 4th parameter(dy),  if '1' and '0' --it is Sobel-X else it is(i.e., '0' and '1') is for sobel-Y
# *** Even this method results the array as outofbounds(-ve value), we need to make it +ve by absolute func
sobelX = cv2.Sobel(img, cv2.CV_64F, 1, 0)
sobelY = cv2.Sobel(img, cv2.CV_64F, 0, 1)
# Making the numpy images +ve
sobelX = np.uint8(np.absolute(sobelX))
sobelY = np.uint8(np.absolute(sobelY))

"""
Working: for the Sobel-X the direction of intensity will be in vertical direction and for the sobel-Y the intensity will be in Horizontal direction
"""

# combining the result sobel-X and sobel-Y to get a clear image of sudoku.png to solve efficiently
cmbndsblXsblY = cv2.bitwise_or(sobelX, sobelY)
cannyEdgImg = cv2.Canny(img, 100, 200)




# Displaying FacesImages
titles = ['Original Image', 'Laplacian Gradient', 'SobelX', 'SobelY', 'Combined image of sobel-X and sobel-Y', 'canny ']
images = [img, lplcianGrdnt, sobelX, sobelY, cmbndsblXsblY, cannyEdgImg]


for i in range(len(images)):
    plt.subplot(2, 3,  i+1)
    plt.title(titles[i]), plt.imshow(images[i], 'gray')
    plt.xticks([]), plt.yticks([])

plt.show()

"""
Gradient: An Image gradient is the directional change in the intensity, color of an image.
"""

import cv2
import numpy as np
from matplotlib import pyplot as plt


img = cv2.imread('sudoku.png', cv2.IMREAD_GRAYSCALE)  # pass sudoku.png for better understanding

# Applying the gradient types on the image that read
# Laplacian Gradient
# lplcianGrdnt = cv2.Laplacian(img, cv2.CV_64F)  # passed CV_64 so, it can also accept the -ve float values. Why -ve values? :: while applying the laplacian transformation we may get -ve values, so to accept and store we are passing the datatype which can also take -values along with the +values.
# As we may have -values in our image array, we can't display it, so we need to convert to normal array(array with +values)
# We do this in pgmmatically through absolute function, which makes a -values into +values

lplcianGrdnt = cv2.Laplacian(img, cv2.CV_64F)
lplcianGrdnt = np.uint8(np.absolute(lplcianGrdnt))

# Sobel-X and Sobel-Y are the derivatives of the value w.r.t. X and Y axes respectively
# Here for both the sobel-X and sobel-Y, We use the same method named cv2.Sobel() method, The difference b/w sobel-X and sobel-Y is the 3rd parameter(dx) and 4th parameter(dy),  if '1' and '0' --it is Sobel-X else it is(i.e., '0' and '1') is for sobel-Y
# *** Even this method results the array as outofbounds(-ve value), we need to make it +ve by absolute func
sobelX = cv2.Sobel(img, cv2.CV_64F, 1, 0)
sobelY = cv2.Sobel(img, cv2.CV_64F, 0, 1)
# Making the numpy images +ve
sobelX = np.uint8(np.absolute(sobelX))
sobelY = np.uint8(np.absolute(sobelY))

"""
Working: for the Sobel-X the direction of intensity will be in vertical direction and for the sobel-Y the intensity will be in Horizontal direction
"""

# combining the result sobel-X and sobel-Y to get a clear image of sudoku.png to solve efficiently
cmbndsblXsblY = cv2.bitwise_or(sobelX, sobelY)
cannyEdgImg = cv2.Canny(img, 100, 200)




# Displaying FacesImages
titles = ['Original Image', 'Laplacian Gradient', 'SobelX', 'SobelY', 'Combined image of sobel-X and sobel-Y', 'canny ']
images = [img, lplcianGrdnt, sobelX, sobelY, cmbndsblXsblY, cannyEdgImg]


for i in range(len(images)):
    plt.subplot(2, 3,  i+1)
    plt.title(titles[i]), plt.imshow(images[i], 'gray')
    plt.xticks([]), plt.yticks([])

plt.show()
Gradient: An Image gradient is the directional change in the intensity, color of an image. # pass sudoku.png for better understanding # Applying the gradient types on the image that read # Laplacian Gradient # lplcianGrdnt = cv2.Laplacian(img, cv2.CV_64F)  # passed CV_64 so, it can also accept the -ve float values. Why -ve values? :: while applying the laplacian transformation we may get -ve values, so to accept and store we are passing the datatype which can also take -values along with the +values. # As we may have -values in our image array, we can't display it, so we need to convert to normal array(array with +values) # We do this in pgmmatically through absolute function, which makes a -values into +values # Sobel-X and Sobel-Y are the derivatives of the value w.r.t. X and Y axes respectively # Here for both the sobel-X and sobel-Y, We use the same method named cv2.Sobel() method, The difference b/w sobel-X and sobel-Y is the 3rd parameter(dx) and 4th parameter(dy),  if '1' and '0' --it is Sobel-X else it is(i.e., '0' and '1') is for sobel-Y # *** Even this method results the array as outofbounds(-ve value), we need to make it +ve by absolute func # Making the numpy images +ve Working: for the Sobel-X the direction of intensity will be in vertical direction and for the sobel-Y the intensity will be in Horizontal direction # combining the result sobel-X and sobel-Y to get a clear image of sudoku.png to solve efficiently # Displaying FacesImages