Trending March 2024 # Working And Examples Of Numpy Norm # Suggested April 2024 # Top 3 Popular

You are reading the article Working And Examples Of Numpy Norm updated in March 2024 on the website Cattuongwedding.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 Working And Examples Of Numpy Norm

Introduction to NumPy norm

The error of a given model in machine learning and deep learning can be evaluated by using a function called norm which can be thought of as the length of the vector to map the vector to a given positive value, and the length of the vector can be calculated using three vector norms namely vector L1 norm, vector L2 norm and vector max norm where vector L1 norm represents the L1 norm of the vector which calculates the absolute vector values sum and vector L2 norm represents the L2 norm of the vector which calculates the squared vectored values sum and finds its square root and vector max norm calculates the vector’s maximum value. In this topic, we are going to learn about the NumPy norm.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax

The syntax for NumPy norm in Python is as follows:

and the syntax for the same is as follows:

norm(arrayname, normorder=1);

where arrayname is the name of the array whose L1 norm of the vector must be calculated and

normorder specifies the norm order of the vector, which is 1 for the L1 norm of a vector.

2. norm() function is used to calculate the L2 norm of the vector in NumPy using the formula:

and the syntax for the same is as follows:

norm(arrayname);

where array name is the name of the array whose L2 norm of the vector must be calculated.

3. norm() function is used to calculate the maximum value of the vector in NumPy using the formula:

and the syntax for the same is as follows:

norm(arrayname, inf);

where array name is the name of the array whose L2 norm of the vector must be calculated and inf represents infinity.

Working of NumPy norm

The error of a given model in machine learning and deep learning can be evaluated by using a function called norm which can be thought of as the length of the vector to map the vector to a given positive value.

The length of the vector can be calculated using three vector norms, namely vector L1 norm, vector L2 norm, and vector max norm,

The Vector L1 norm represents the L1 norm of the vector, which calculates the absolute vector values sum.

The Vector L2 norm represents the L2 norm of the vector, which calculates the squared vectored values sum and finds its square root.

The vector max norm is used to calculate the vector’s maximum value.

Examples of NumPy norm

Given below are the examples of NumPy norm:

Example #1

Python program to demonstrate NumPynorm function to calculate the L1 norm of the vector of the newly created array:

Code:

#importing the package numpy and importing the package for norm import numpy as nump from numpy.linalg import norm #Creating an array by making use of array function in NumPy and storing it in a variable called nameofthearray nameofthearray = nump.array([1,2,3,4]) #Displaying the elements of nameofthearray followed by one line space by making use of n print 'The elements of the given array are:' print nameofthearray print 'n' #using norm function of NumPy and passing the created array as the parameter to that function along with 1 to specify the order of norm to find the L1 norm of vector value and store it in a variable called L1norm L1norm = norm(nameofthearray,1) #Displaying the L1 norm of vector value stored in L1norm variable print 'The L1 norm of vector value is:' print L1norm

Output:

The package for NumPy is imported in the above program, and the package for using norm is imported. Then an array is created using the array function in NumPy, and it is stored in the variable called the name of the array. Then the elements of the array name of the array are displayed. Then the norm() function in NumPy is used to find the L1 norm of a vector bypassing the name of the array and the order of the norm, which is 1 as the parameter to the norm() function, and the result returned is stored in a variable called L1norm which is printed as the output on the screen. Finally, the output is shown in the snapshot above.

Example #2

Python program to demonstrate NumPy norm function to calculate the L2 norm of the vector of the newly created array:

#importing the package numpy and importing the package for norm import numpy as nump from numpy.linalg import norm #Creating an array by making use of array function in NumPy and storing it in a variable called nameofthearray nameofthearray = nump.array([1,2,3,4]) #Displaying the elements of nameofthearray followed by one line space by making use of n print 'The elements of the given array are:' print nameofthearray print 'n' #using norm function of NumPy and passing the created array as the parameter to that function to find the L2 norm of vector value and store it in a variable called L1norm L2norm = norm(nameofthearray) #Displaying the L2 norm of vector value stored in L2norm variable print 'The L2 norm of vector value is:' print L2norm

Output:

The package for NumPy is imported in the above program, and the package for using norm is imported. Then an array is created using the array function in NumPy, and it is stored in the variable called nameofthearray. Then the elements of the array nameofthearray are displayed. Then the norm() function in NumPy is used to find the L2 norm of the vector bypassing the nameofthearray array as the parameter to the norm() function, and the result returned is stored in a variable called L2norm, which is printed as the output on the screen. The output is shown in the snapshot above.

Example #3

Python program to demonstrate NumPy norm function to calculate the maximum value of the vector of the newly created array:

Code:

#importing the package numpy and importing the package for norm import numpy as nump from numpy.linalg import norm from numpy import inf #Creating an array by making use of array function in NumPy and storing it in a variable called nameofthearray nameofthearray = nump.array([1,2,3,4]) #Displaying the elements of nameofthearray followed by one line space by making use of n print 'The elements of the given array are:' print nameofthearray print 'n' #using norm function of NumPy and passing the created array as the parameter to that function to find the maximum value of vector and store it in a variable called mnorm mnorm = norm(nameofthearray,inf) #Displaying the maximum value of vector value stored in mnorm variable print 'The maximum value of vector is:' print mnorm

Output:

The package for NumPy is imported in the above program, and the package for using norm is imported. Then an array is created using the array function in NumPy, and it is stored in the variable called nameofthearray. Then the elements of the array nameofthearray are displayed. Then the norm() function in NumPy is used to find the maximum value of vector bypassing the nameofthearray array as the parameter to the norm() function, and the result returned is stored in a variable called mnorm, which is printed as the output on the screen. Finally, the output is shown in the snapshot above.

Recommended Articles

This is a guide to the NumPy norm. Here we discuss the concept of NumPynorm function in Python through definition, syntax, and working through programming examples and their outputs. You may also have a look at the following articles to learn more –

You're reading Working And Examples Of Numpy Norm

Working And Examples Of Pyspark Collect

Introduction to PySpark collect

PYSPARK COLLECT is an action in PySpark that is used to retrieve all the elements from the nodes of the Data Frame to the driver node. It is an operation that is used to fetch data from RDD/ Data Frame. The operation involves data that fetches the data and gets it back to the driver node.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The collect operation returns the data as an Array of Row Types to the driver; the result is collected and further displayed for PySpark operation. The data, once is available on the node, can be used in the loops and displayed. The collect operation is widely used for smaller Data Set the data which can be fit upon memory or post that can cause some certain memory exception too. Let’s check the Collect operation in detail and try to understand the functionality for the same.

The syntax for the COLLECT function is:-

cd = spark.sparkContext.parallelize(data1) cd.collect()

explanation:

Cd:- The RDD made from the Data

.collect () :- The function used for Collecting the RDD.

Screenshot:

Working of Collect in Pyspark

Let us see somehow the COLLECT operation works in PySpark:-

Collect is an action that returns all the elements of the dataset, RDD of a PySpark, to the driver program. It is basically used to collect the data from the various node to the driver program that is further returned to the user for analysis.

Retrieving the huge data set can sometimes cause an out-of-memory issue over data collection.

This is a network movement action call where all the elements from the different nodes are sent to the driver memory where the data is collected, so the data movement is much over the collect operation. Since it is an action call of PySpark so every time it is called, all the transformations are done prior to implementing its action.

It retrieves the element in the form of Array [Row] to the driver program.

Let’s check the creation and usage with some coding examples.

Example of PySpark collect

Let us see some Example of how the PYSPARK  COLLECT operation works:-

Let’s start by creating simple data in PySpark.

data1  = [{'Name':'Jhon','ID':2,'Add':'USA'},{'Name':'Joe','ID':3,'Add':'USA'},{'Name':'Tina','ID':2,'Add':'IND'},{'Name':'Jhon','ID':2, 'Add':'USA'},{'Name':'Joe','ID':5,'Add':'INA'}]

A sample data is created with Name, ID, and ADD as the field.

a = sc.parallelize(data1)

RDD is created using sc. parallelize.

b = spark.createDataFrame(a) b.show()

Screenshot:

Now let us try to collect the elements from the RDD.

a=sc.parallelize(data1) a.collect()

This collects all the data back to the driver node, and the result is then displayed as a result at the console.

Screenshot:

a.collect()[0] a.collect()[1] a.collect()[2]

The above code shows that we can also select a selected number of the column from an RDD/Data Frame using collect with index. The index is used to retrieve elements from it.

Screenshot:

Let’s try to understand this with more Example:-

data3 = sc.parallelize(data2) data2 = [1,2,3,4,5,6,7,8,9,10] data3 = sc.parallelize(data2) data3.collect()

This is a very simple way to understand more about collect where we have made a simple RDD of type Int. Post collecting, we can get the data back to driver memory as a result. All the data Frames are called back to the driver, and the result is displayed back. Once the data is available, we can use the data back for our purpose, data analysis and data modeling.

Screenshot:-

These are some of the Examples of PYSPARK ROW Function in PySpark.

Note:-

COLLECT is an action in PySpark.

COLLECT collects the data back to the driver node.

PySpark COLLECT returns the type as Array[Row].

COLLECT can return data back to memory so that excess data collection can cause Memory issues.

PySpark COLLECT causes the movement of data over the network and brings it back to the driver memory.

COLLECTASLIST() is used to collect the same but the result as List.

Conclusion

From the above article, we saw the use of collect Operation in PySpark. We tried to understand how the COLLECT method works in PySpark and what is used at the programming level from various examples and classification.

Recommended Articles

This is a guide to the PySpark collect. Here we discuss the use of collect Operation in PySpark with various examples and classification. You may also have a look at the following articles to learn more –

Working Of Md5() Functions In Php With Examples

Introduction to PHP md5()

The MD5() function of the PHP Programming Language will produce the hash of the string which is like encoding process. MD5() function works only on PHP 4, 5, 7 versions but for the other PHP version the hash encoder “md5()” may work or may not work mostly. Most of the times md5() function is not recommended to safely secure the passwords due to the function’s fast nature of encoding with the help of its inbuilt hashing algorithm. It accepts only two parameters. In those two only one is mandatory at all times.

Start Your Free Software Development Course

Syntax:

String md5 ($string, $getRawOutput)

Explanation of Parameters in brief:

MD5() function of the PHP Programming Language takes two parameters at max. They are: $string parameter and $getRawOutput parameter.

$string: $string parameter will help us to expect the string to be hashed.

$getRawOutput: $getRawOutput parameter will help us to expect a Boolean value. For the TRUE result the function is going to return the HASH in raw binary format which is of the length 16.

Return type: The md5() function of PHP will return the hashed string ( it can either be in lowercase hex format character sequence which is of length 32 ( 32 character hexadecimal number )or for raw binary form which is of the length 16).

How do MD5() Functions work in PHP?

MD5() function of the PHP Programming Language works for PHP 4, PHP 5 and PHP 7 versions up to now. Apart from these versions md5() function may not work mostly. It is a built-in function and by using the md5() function we initiate the HASHING algorithm inside of the PHP Programming Language. With the backend Hashing Algorithm, conversion of hashing of the specific numerical value/ string value/ any other will be done as needed. It is very helpful in the encoding process. MD5() function value will always be in 32 bit binary format unless second parameter is used inside of the md5() function. At that time md5() value will be 16 bit binary format.

Examples to Implement PHP md5()

Below are the examples:

Example #1

Code:

<?php $str1 = 'apples'; print "This is the value of HASH of apples :: "; $a1 = md5($str1); if (md5($str1) === '1f3870be274f6c49b3e31a0c6728957f') { echo "If the value of apples is :: 1f3870be274f6c49b3e31a0c6728957f then it will print :: "; } else{ }

Output:

Example #2

Code:

<?php $input_string1 = 'Pavan Kumar Sake'; echo '16 bit binary format :: '; $i1 = md5($input_string1,TRUE); echo $i1;

Output:

Example #3

Code:

<?php $k = 10; for($i=0;$i<=$k;$i++){ print "Hash code of $i :: "; print md5($i); }

Example #4

Code:

<?php $user1 = "Pavan Kumar Sake"; $pass1 = "pavansake123"; $user1_encode = md5($user1); $pass1_encode = md5($pass1); if (md5($user1)== "4c13476f5dd387106a2a629bf1a9a4a7"){ if(md5($pass1)== "20b424c60b8495fae92d450cd78eb56d"){ echo "Password is also correct so login will be successful"; } else{ echo "Incorrect Password is entered"; } } else{ echo "Incorrect Username is entered"; }

Output:

Conclusion

I hope you understood what is the definition of PHP md5() function with the syntax and its explanation, Info regarding the parameters in brief detail, Working of md5() function in PHP along with the various examples to understand the concept well.

Recommended Articles

This is a guide to PHP MD5(). Here we discuss the introduction, syntax, and working of MD5() in PHP along with different examples and code implementation. You can also go through our other related articles to learn more –

Parameters & Examples Of Powershell Test

Introduction to PowerShell Test-Path

Powershell test-path command checks for the path’s existence for all the elements. It always returns boolean values. It will return $True and $False. It will return $True as all the elements are there else; it will return $False. With the help of the Test-Path command, we can also identify the path types; that is, if the path is a container, leaf, or a terminal, it will always return $False if Path is whitespace, and it will return an error if the path is null. Real-Time uses, suppose you are checking any file in the directory, and you do not want to check, or you want to exclude one file from the directory because that particular file is in huge number, then you can use it.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax 1:

[-IsValid(return boolean true or false)]

Syntax 2:

[-IsValid(return boolean true or false)]

Parameters

1. -Exclude: This command disallows or omits a defined item. This parameter will be used for path parameters. We can define path element or any pattern like “*.txt,””*.pdf,” etc. And these defined patterns can be excluded from the path.

2. -Filter: Allow our command to define a filter for checking path elements. For example, if we have huge file systems and want to check whether the path exists, we can define some filter conditions. We can use Wildcard for it.

4. -IsValid: It checks for the path syntax; this command does not worry about whether the path exists. It will simply validate the path syntax, so if the path syntax is valid, it will return $True; if the path syntax is not valid, it will return $False.

5. -LiteralPath: This is also one kind of path checking, but here, in this case, we have to pass the exact match path; we can not use “*.txt”; we must pass a path like “ranjan.txt,” which is an exact name not like matching. The good thing is that we can also use escape characters in these cases. In the case of escape characters, we should use single quotation marks. As a single quotation, inform PowerShell to treat characters as escape characters.

6. -NewerThan: Defines any time as DateTime; simply, it will check for the file creation dates, it checks if the date of the file creation date, and if the date of creation is newer than the argument date provided, then it will return true. For example, take an argument passed as “August 13, 2023,” and the date of file creation is “August 15, 2023” Then it will return true as file creation is newer than the argument pass date.

7. -OlderThan: Defines any time as DateTime; simply, it will check for the file creation dates; it checks if the date of file creation date, and if the date of creation is older than the argument date provided, it will return true. For example, take an argument passed as “August 13, 2023,” and the date of file creation is “August 15, 2023,” then it will return false as an argument passed as newer than the creation date.

8. -Path: Defines any path that will be tested. We can also use a wildcard in this case. Also, if the path has spaces between them, we can use a single quotation to inform PowerShell.

9. -PathType: It defines the exact types of the given element in the path. In simple it will check for paths elements types. It will return a boolean value. If the path of a given element is of the same type we defined in the command, then it will return $True, and if the type of path is not the same as what we defined in the command, then it will return $False. This command will take the parameters below, like the PathType command value.

Any container: It contains elements like registry and directories.

Lead Item: This element will not contain attributes like any file.

Combination: It can be both also, which is any container or any leaf.

Examples of PowerShell Test-Path

Below are the examples of PowerShell Test-Path:

Example #1

The below command is one example where we check for any files inside “ranjan1” directories other than “*.txt.”

Test-Path -Path "./ranjan1/" -Exclude *.txt

Output:

Test-Path -Path "./ranjan1/" -Exclude *.pdf

Output:

Test-Path -Path "./ranjan1/" -Include *.pdf

Output:

ls

Output:

Example #2

Below is an example for checking PathType. We contain PathType for $PROFILE by passing arguments like Any, Leaf, and Container.

Test-Path -Path $PROFILE -PathType Any

Output:

Test-Path -Path $PROFILE -PathType Container

Output:

Test-Path -Path $PROFILE -PathType leaf

Output:

Example #3

If the path is there, then it will return True; if the path does not exist, it will return False.

Test-Path -Path "./ranjan1/"

Output:

Test-Path -Path "./ranjan2/"

Output:

Test-Path -Path "./ranjan3/"

Output:

ls

Output:

Example #4

Here we are checking the file’s date of creation. It could be older or newer. I have created the file chúng tôi it was created in 2023 before August month, and we are checking it with various dates bypassing them.

Output:

Test-Path ./test2.txt -OlderThan "August 13, 2023"

Output:

Test-Path ./test2.txt -NewerThan "August 13, 2023"

Output:

Test-Path ./test2.txt -NewerThan "Jan 13, 2023"

Output:

Test-Path ./test2.txt -NewerThan "July 13, 2023"

Output:

ls

Output:

Conclusion – PowerShell Test-Path

From above all, we learned that the Test-Path command can be used to either check path type or to check the path syntax. We can identify if the path is a container, leaf, or mixed(Any).

Recommended Articles

This has been a guide to PowerShell Test-Path. Here we discuss the introduction, parameters, and examples of the Powershell test path. You may also have a look at the following articles to learn more –

Learn The Internal Working Of Explode

Introduction to PySpark explode

PYSPARK EXPLODE is an Explode function that is used in the PySpark data model to explode an array or map-related columns to row in PySpark. It explodes the columns and separates them not a new row in PySpark.  It returns a new row for each element in an array or map.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

It takes the column as the parameter and explodes up the column that can be further used for data modeling and data operation. The exploding function can be the developer the access the internal schema and progressively work on data that is nested. This explodes function usage avoids the loops and complex data-related queries needed.

Let us try to see about EXPLODE in some more detail.

The syntax for PySpark explode

The syntax for the EXPLODE function is:-

from pyspark.sql.functions import explode df2 = data_frame.select(data_frame.name,explode(data_frame.subjectandID)) df2.printSchema()

Df_inner: The Final data frame formed

Screenshot:

Working of Explode in PySpark with Example

Let us see some Example of how EXPLODE operation works:-

Let’s start by creating simple data in PySpark.

data1  = [("Jhon",[["USA","MX","USW","UK"],["23","34","56"]]),("Joe",[["IND","AF","YR","QW"],["22","35","76"]]),("Juhi",[["USA","MX","USW","UK"],["13","64","59"]]),("Jhony",[["USSR","MXR","USA","UK"],["22","44","76"]])]

The data is created with Array as an input into it.

data_frame = spark.createDataFrame(data=data1, schema = ['name','subjectandID'])

Creation of Data Frame.

data_frame.printSchema() data_frame.show(truncate=False)

Output:

Here we can see that the column is of the type array which contains nested elements that can be further used for exploding.

from pyspark.sql.functions import explode

Let us import the function using the explode function.

df2 = data_frame.select(data_frame.name,explode(data_frame.subjectandID))

Let’s start by using the explode function that is to be used. The explode function uses the column name as the input and works on the columnar data.

df2.printSchema() root |-- name: string (nullable = true) |-- col: array (nullable = true) |    |-- element: string (containsNull = true)

The schema shows the col being exploded into rows and the analysis of output shows the column name to be changed into the row in PySpark. This makes the data access and processing easier and we can do data-related operations over there.

df2.show()

The output breaks the array column into rows by which we can analyze the output being exploded based on the column values in PySpark.

The new column that is created while exploding an Array is the default column name containing all the elements of an Array exploded there.

The explode function can be used with Array as well the Map function also,

Let us check this with some example:-

data1  = [("Jhon",["USA","MX","USW","UK"],{'23':'USA','34':'IND','56':'RSA'}),("Joe",["IND","AF","YR","QW"],{'23':'USA','34':'IND','56':'RSA'}),("Juhi",["USA","MX","USW","UK"],{'23':'USA','34':'IND','56':'RSA'}),("Jhony",["USSR","MXR","USA","UK"],{'23':'USA','34':'IND','56':'RSA'})] data_frame = spark.createDataFrame(data=data1, schema = ['name','subjectandID']) data_frame.printSchema() root |-- name: string (nullable = true) |-- subjectandID: array (nullable = true) |    |-- element: string (containsNull = true) |-- _3: map (nullable = true) |    |-- key: string |    |-- value: string (valueContainsNull = true)

The data frame is created and mapped the function using key-value pair, now we will try to use the explode function by using the import and see how the Map function operation is exploded using this Explode function.

from pyspark.sql.functions import explode df2 = data_frame.select(data_frame.name,explode(data_frame.subjectandID)) df2.printSchema() root |-- name: string (nullable = true) |-- col: string (nullable = true) df2.show()

The  Output Example shows how the MAP KEY VALUE PAIRS are exploded using the Explode function.

Screenshot:-

These are some of the Examples of EXPLODE in PySpark.

Note:-

EXPLODE is a PySpark function used to works over columns in PySpark.

EXPLODE is used for the analysis of nested column data.

PySpark EXPLODE converts the Array of Array Columns to row.

EXPLODE can be flattened up post analysis using the flatten method.

EXPLODE returns type is generally a new row for each element given.

Conclusion

From the above article, we saw the working of EXPLODE in PySpark. From various examples and classification, we tried to understand how this EXPLODE function works and what are is used at the programming level. The various methods used showed how it eases the pattern for data analysis and a cost-efficient model for the same.

Recommended Articles

This is a guide to PySpark explode. Here we discuss the introduction, syntax, and working of EXPLODE in PySpark Data Frame along with examples. You may also look at the following articles to learn more –

Working Of Dilate() Function In Opencv

Introduction to OpenCV dilate

The following article provides an outline for OpenCV dilate. The set of operations that can process the images according to the shapes of the images are called morphological operations and performing morphological operations on a given image develops a structural element on the given image which removes noise from the image or settles down any imperfections to make the image very clear and performing convolution with kernel having an anchor point, of a particular shape in a given input image is called dilation using the size of the object in white color in the given image increases or the size of the object in black color in the given image decreases.

Start Your Free Software Development Course

Syntax to define dilate() function in OpenCV:

dilate(source_image, kernel)

Where,

source_image is the image which is to be dilated using dilate() function.

kernel represents the kernel matrix.

Working of dilate() Function in OpenCV

The process of performing convolution with kernel having anchor point of a particular shape in a given input image is called dilate() function in OpenCV.

The dilate() function starts with computing the minimum pixel value by overlapping the kernel over the input image.

And then the image is replaced by the kernel anchor at the center.

This causes the white regions in the image to grow bigger in size and the image size increases as well.

The dilate() function returns an image with increased size of white shade in the given image.

Examples of OpenCV dilate

Given below are the examples of OpenCV dilate:

Example #1

OpenCV program in python to demonstrate dilate() function to read the given image and increase the size of white region in the image and display the resulting image as the output on the screen.

Code:

#importing all the required modules import numpy as np import cv2 as cv #reading the image that is to be dilated using imread() function imageread = cv.imread('C:/Users/admin/Desktop/logo2.png') #defining the matrix for kernel to apply dilate() function on the image to dilate the image kernelmatrix = np.ones((5, 5), np.uint8) #applying dilate() function on the image to dilate the image and display it as the output on the screen resultimage = cv.dilate(imageread, kernelmatrix) cv.imshow('Dilated_image', resultimage) cv.waitKey(0) cv.destroyAllWindows()

Output:

In the above program, we are importing the required modules. Then we are reading the image which is to be dilated, using imread() function. Then we are making use of use of dilate() function to dilate the image. Then we are displaying the dilated image as the output on the screen.

Example #2

OpenCV program in python to demonstrate dilate() function to read the given image and increase the size of white region in the image and display the resulting image as the output on the screen.

#importing all the required modules import numpy as np import cv2 as cv #reading the image that is to be dilated using imread() function imageread = cv.imread('C:/Users/admin/Desktop/logo1.jpg') #defining the matrix for kernel to apply dilate() function on the image to dilate the image kernelmatrix = np.ones((5, 5), np.uint8) #applying dilate() function on the image to dilate the image and display it as the output on the screen resultimage = cv.dilate(imageread, kernelmatrix) cv.imshow('Dilated_image', resultimage) cv.waitKey(0) cv.destroyAllWindows()

Output:

In the above program, we are importing the required modules. Then we are reading the image which is to be dilated, using imread() function. Then we are making use of use of dilate() function to dilate the image. Then we are displaying the dilated image as the output on the screen.

Example #3

OpenCV program in python to demonstrate dilate() function to read the given image and increase the size of white region in the image and display the resulting image as the output on the screen.

Code:

#importing all the required modules import numpy as np import cv2 as cv #reading the image that is to be dilated using imread() function imageread = cv.imread('C:/Users/admin/Desktop/educba1.jpg') #defining the matrix for kernel to apply dilate() function on the image to dilate the image kernelmatrix = np.ones((5, 5), np.uint8) #applying dilate() function on the image to dilate the image and display it as the output on the screen resultimage = cv.dilate(imageread, kernelmatrix) cv.imshow('Dilated_image', resultimage) cv.waitKey(0) cv.destroyAllWindows()

Output:

In the above program, we are importing the required modules. Then we are reading the image which is to be dilated, using imread() function. Then we are making use of use of dilate() function to dilate the image. Then we are displaying the dilated image as the output on the screen.

Example #4

OpenCV program in python to demonstrate dilate() function to read the given image and increase the size of white region in the image and display the resulting image as the output on the screen.

Code:

#importing all the required modules import numpy as np import cv2 as cv #reading the image that is to be dilated using imread() function imageread = cv.imread('C:/Users/admin/Desktop/lo.jpg') #defining the matrix for kernel to apply dilate() function on the image to dilate the image kernelmatrix = np.ones((5, 5), np.uint8) #applying dilate() function on the image to dilate the image and display it as the output on the screen resultimage = cv.dilate(imageread, kernelmatrix) cv.imshow('Dilated_image', resultimage) cv.waitKey(0) cv.destroyAllWindows()

Output:

In the above program, we are importing the required modules. Then we are reading the image which is to be dilated, using imread() function. Then we are making use of use of dilate() function to dilate the image. Then we are displaying the dilated image as the output on the screen.

Recommended Articles

We hope that this EDUCBA information on “OpenCV dilate” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about Working And Examples Of Numpy Norm on the Cattuongwedding.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!