Posts

Image
  Computer vision: Morphological Transformations in openCV Arabic import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread('smarties.png', cv2.IMREAD_GRAYSCALE) _, mask = cv2.threshold(img, 220, 255, cv2.THRESH_BINARY_INV) kernal = np.ones((5,5), np.uint8) dilation = cv2.dilate(mask, kernal, iterations=2) erosion = cv2.erode(mask, kernal, iterations=1) opening = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernal) closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernal) mg = cv2.morphologyEx(mask, cv2.MORPH_GRADIENT, kernal) th = cv2.morphologyEx(mask, cv2.MORPH_TOPHAT, kernal) titles = ['image', 'mask', 'dilation', 'erosion', 'opening', 'closing', 'mg', 'th'] images = [img, mask, dilation, erosion, opening, closing, mg, th] for i in range(8):     plt.subplot(2, 4, i+1), plt.imshow(images[i], 'gray')           plt.title(titles[i])           plt.xticks([]),plt.yticks([])#ticks    ...
Image
  Computer vision: matplotlib with open CV  from matplotlib import pyplot as plt import cv2 img = cv2 . imread ( 'lena.jpg' , - 1 ) cv2 . imshow ( 'image' , img ) img = cv2 . cvtColor ( img , cv2 . COLOR_BGR2RGB ) plt . imshow ( img ) plt . xticks ([]), plt . yticks ([])#ticks plt . show ()#show cv2 . waitKey ( 0 ) cv2 . destroyAllWindows ()#close window ========================================== secod code import numpy as np from matplotlib import pyplot as plt import cv2 as cv img = cv . imread ( 'gradient.png' , 0 ) _ , th1 = cv . threshold ( img , 50 , 255 , cv . THRESH_BINARY ) _ , th2 = cv . threshold ( img , 200 , 255 , cv . THRESH_BINARY_INV ) _ , th3 = cv . threshold ( img , 127 , 255 , cv . THRESH_TRUNC ) _ , th4 = cv . threshold ( img , 127 , 255 , cv . THRESH_TOZERO ) _ , th5 = cv . threshold ( img , 127 , 255 , cv . THRESH_TOZERO_INV ) titles = [ 'Original Image' , 'BINARY' , 'BINARY_INV...