<jupyter_start><jupyter_text>- Morphological operators are sets of kernals that can be achieve a variety of effects, such as reducing noise.- Certain operaters are good at reducing black point on the white backgroung and vice-versa.- Certain operators can also achieve an erosion and dilation effect that can add or erode from an existing image.The basic morphological operations are: - Erosion - DilationErosion:- Erosion shrink-ens the image pixels i.e. it is used for shrinking of element A by using element B.- Erosion removes pixels on object boundaries.:- The value of the output pixel is the minimum value of all the pixels in the neighborhood. A pixel is set to 0 if any of     the neighboring pixels have the value 0.     Dilation:- Dilation expands the image pixels i.e. it is used for expanding an element A by using structuring element B.- Dilation adds pixels to object boundaries.- The value of the output pixel is the maximum value of all the pixels in the neighborhood. A pixel is set to 1 if any of     the neighboring pixels have the value 1.<jupyter_code>import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
def load_image():
    blank_image=np.zeros((600,600))
    font=cv.FONT_HERSHEY_SIMPLEX
    cv.putText(blank_image,text='TEXAS',org=(50,300),fontFace=font,fontScale=5,color=(255,255,255),thickness=20)
    return blank_image
def show_image(image_path):
    fig=plt.figure(figsize=(15,12))
    ax=fig.add_subplot(111)
    ax.imshow(image_path, cmap='gray')
img=load_image()
show_image(img)
# Erosion
kernel=np.ones((5,5),dtype=np.uint8)
kernel
resulted_image=cv.erode(img,kernel,iterations=2)
show_image(resulted_image)
# Dilation
img=load_image()
white_noise=np.random.randint(low=0,high=2,size=(600,600))
white_noise
show_image(white_noise)
img.max()
white_noise=white_noise*255
show_image(white_noise)
#adding noise to original images 
noise_image=white_noise+img
show_image(noise_image)
opening=cv.morphologyEx(noise_image,cv.MORPH_OPEN,kernel) #opening
show_image(opening)
img=load_image()
black_noise_img=np.random.randint(low=0,high=2,size=(600,600))
black_noise_img
black_noise_img=black_noise_img * -255
black_noise_img
black_noise_image=img+black_noise_img
black_noise_image
black_noise_image[black_noise_image == -255]=0
black_noise_image.min()
show_image(black_noise_image)
closing=cv.morphologyEx(black_noise_image,cv.MORPH_CLOSE,kernel)
show_image(closing)<jupyter_output><empty_output><jupyter_text>Morphological Gradient:- During dilation operation additional pixels are added to an image boundary and, during erosion operation, additional        pixels are removed from image boundaries, The total number of pixels added during the dilation process depends on the       dimensions of the structuring element used.- Morphological Gradient is the operation that is equal to the difference between dilation and erosion of an image. Each    pixel value in the resulting image indicates the contrast intensity in the nearby pixels. This is used in edge detection,   segmentation and to find the outline of an object.<jupyter_code>img=load_image()
show_image(img)
gradient=cv.morphologyEx(img,cv.MORPH_GRADIENT,kernel)
show_image(gradient)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07517862690276483, 'fraction_numerical': 0.02019260639950295, 'mean_word_length': 6.108167770419426, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '165092', 'license': 'MIT', 'n_tokens_mistral': 1053, 'n_tokens_neox': 962, 'n_words': 330, 'path': 'Morphological Operaters.ipynb', 'repo_name': 'sachinshubhams/Computer-Vision', 'size': '3219'}