Python | Numpy ndarray .__ ixor __ ()

Learn examples from DataCamp guru:

OpenCV-Python — is a Python bindings library for solving computer vision problems.  cv2.erode () is used for image erosion. The basic idea of ​​erosion is only similar to soil erosion, it blurs the boundaries of the foreground object (always try to keep the foreground white). This is usually done on binary images. It requires two inputs, one of which is our original image, the other is called a structuring element or core, which determines the nature of the operation. A pixel in the original image (either 1 or 0) will be considered 1 only if all pixels under the kernel are 1, otherwise it is blurred (zeroed out).

Syntax: cv2.erode (src, kernel [, dst [, anchor [, iterations [, borderType [, borderValue]]]]])
Parameters:
src: It is the image which is to be eroded.
kernel: A structuring element used for erosion. If element = Mat (), a 3 x 3 rectangular structuring element is used. Kernel can be created using >.
dst: It is the output image of the same size and type as src.
anchor: It is a variable of type integer representing anchor point and it`s default value Point is (-1, -1) which means that the anchor is at the kernel center.
borderType: It depicts what kind of border to be added. It is defined by flags like cv2.BORDER_CONSTANT , cv2.BORDER_REFLECT , etc.
iterations: It is number of times erosion is applied.
borderValue: It is border value in case of a constant border.
Return Value: It returns an image.

The image is used for all the examples below:

Example # 1:

Output:

Example # 2:

# Python program to explain the cv2.erode () method

 
# cv2 import

import cv2

 
# import numpy

  import numpy as np

 
# path

path = r `C: UsersRajnishDesktoppythonengineeringgeeks.png`

  
# Read image in default mode

image = cv2.imread (path) 

  
# Name of the window in which the image is displayed

window_name = `Image`

  
# Building the kernel

kernel = np.ones (( 5 , 5 ), np.uint8)

 
# Using the cv2.erode () method

image = cv2.erode (image, kernel) 

 
# Displaying an image
cv2.imshow (window_name, image) 

# Python program to explain the cv2.erode () method

 
< code class = "comments"> # cv2 import

import cv2

 
# numpy imports

import numpy as np

 
# path

path = r `C: UsersRajnishDesktoppythonengineeringgeeks.png`

  
# Read image in default mode

image = cv2.imread (path) 

 
# Name of the window in which the image is displayed

window_name = `Image`

  
# Building the kernel

kernel = np.ones (( 6 , 6 ), np.uint8)

  
# Using the cv2. erode ()

image = cv2. erode (image, kernel, cv2.BORDER_REFLECT) 

 
# Display image
cv2.imshow (window_name, image) 

Output:

Learn examples from DataCamp guru: