This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/sudoku.png", 0); | |
img = cv2.blur(img, (3, 3)); | |
#############################FOCUS################################################ | |
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) | |
thresh2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY,11,2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/sudoku.png", 0); | |
img = cv2.blur(img, (3, 3)); | |
# threshold -> 127 | |
# maxval -> 255 | |
# Output: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/a.jpg", 0); | |
img = cv2.resize(img, (256, 256)); | |
ret,img = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) | |
kernel = np.ones((11,11),np.uint8) | |
eroded = cv2.erode(img,kernel,iterations = 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/sudoku.jpg", 0); | |
img = cv2.blur(img, (3, 3)); | |
# Otsu's thresholding | |
ret2,img = cv2.threshold(img,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/sudoku.jpg", 0); | |
img = cv2.blur(img, (3, 3)); | |
# Otsu's thresholding | |
ret2,img = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import scipy | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/rain.jpg", 0); | |
edges = cv2.Canny(img,150,200) | |
f = plt.figure(figsize=(15,15)) | |
f.add_subplot(1, 2, 1).set_title('Original Image'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/sudoku.png", 0); | |
dx = cv2.Scharr(img,cv2.CV_8UC1,1,0) # first order derivative around x | |
dy = cv2.Scharr(img,cv2.CV_8UC1,0,1) # first order derivative around y | |
f = plt.figure(figsize=(15,15)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/a.jpg", 0) | |
dx = cv2.Sobel(img,cv2.CV_8UC1,1,0,ksize=5) # first order derivative around x | |
dy = cv2.Sobel(img,cv2.CV_8UC1,0,1,ksize=5) # first order derivative around y | |
dx2 = cv2.Sobel(img,cv2.CV_8UC1,2,0,ksize=5) # second order derivative around x | |
dy2 = cv2.Sobel(img,cv2.CV_8UC1,0,2,ksize=5) # second order derivative around y | |
dxy = cv2.Sobel(img,cv2.CV_8UC1,1,1,ksize=5) # first order derivative around x then y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from PIL import Image, ImageFilter | |
from matplotlib import pyplot as plt | |
img = Image.open("imgs/chapter5/outdoor.jpg") | |
#######################FOCUS################## | |
sharpened = img.filter(ImageFilter.SHARPEN) | |
############################################## | |
f = plt.figure(figsize=(15,15)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/sudoku.png", 0) | |
img = cv2.blur(img, (3, 3)) | |
kernel = [ | |
[-1, -1, -1], | |
[-1, 9, -1], | |
[-1, -1, -1] |