<jupyter_start><jupyter_text>Morphological Transformation  Import Libraries<jupyter_code>import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('D:\Computer-Vision-Bootcamp\images\expert.png',0)

#Erosion---
#it erodes away the boundaries of foreground object
#kernal slides through all the image and all the pixel
#from the original image conside 1 only if kernal's pixel is 1

_,mask= cv2.threshold(img,230,255,cv2.THRESH_BINARY_INV)
kernel = np.ones((5,5),np.uint8)# 5x5 kernel with full of ones.
erosion = cv2.erode(mask,kernel) #optional parameters   iterations = 2


#Dilation --
#It is just opposite of erosion.
#Here, a pixel element is ‘1’ if atleast one pixel under the kernel is ‘1’
#So it inc. the white region in the image or size of foreground object in.
#Normally, in cases like noise removal, erosion is followed by dilation.
#Because, erosion removes white noises, but it also shrinks our object.

kernel = np.ones((1,1),np.uint8)# 5x5 kernel with full of ones.
dilation  = cv2.dilate(mask,kernel) #iterations = 2 (optional parameters) iterations = 2




cv2.imshow("mask==",mask)
cv2.imshow("img",img)
# cv2.imshow("ker=",kernel)
cv2.imshow("erosion==",erosion)
cv2.imshow("dilate==",dilation)



cv2.waitKey(0)
cv2.destroyAllWindows()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11247130833970925, 'fraction_numerical': 0.029074215761285386, 'mean_word_length': 5.380487804878049, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '151594', 'license': 'MIT', 'n_tokens_mistral': 479, 'n_tokens_neox': 444, 'n_words': 144, 'path': 'Ex-20-Morphological Transformation.ipynb', 'repo_name': 'imsanjoykb/Computer-Vision-Bootcamp', 'size': '1307'}