Updated April 19, 2023
Introduction to OpenCV Normalize
The process in which we modify the intensity values of pixels in a given image to make the image more appealing to the senses is called normalization of image and image normalization is used to increase the contrast of the image that helps in better extraction of features from the image or segmentation of image and also to remove the noise content from the image and in order to perform image normalization, we make use of a function called normalize() function in OpenCV which returns the normalized image as the output based on the normalization type we have specified to the normalize() function.
The syntax to define normalize() function in OpenCV is as follows:
normalize(source_array, destination_array, alpha, beta, normalization_type)
where
- source_array is the array corresponding to the input image which is to be normalized,
- destination_array is the array corresponding to the output image which is normalized,
- alpha represents the lower range boundary value,
- beta represents the upper range boundary value and
- normalization_type represents the type of normalization.
Working of normalize() function in OpenCV
Working of normalize() function in OpenCV is as follows:
- The process in which we modify the intensity values of pixels in a given image to make the image more appealing to the senses is called normalization of the image.
- The contrast of the image can be increased which helps in extracting the features from the image and in image segmentation using image normalization.
- The noise content from the image can also be removed using Image Normalization.
- We make use of a function called normalize() function in OpenCV to perform the normalization of images.
- The normalize() function takes five parameters namely source_array, destination_array, alpha, beta and normalization_type.
- The parameter source_array is the array corresponding to the input image which is to be normalized.
- The parameter destination_array is the array corresponding to the output image which is normalized.
- The parameter alpha represents the lower range boundary value.
- The parameter beta represents the upper range boundary value.
- The parameter normalization_type represents the type of normalization.
- The normalize() function returns the normalized image as the output.
Example #1
OpenCV program in python to demonstrate normalize() function to read an image using imread() function and then normalize the given image normalize() function and then display the resulting image as the output on the screen:
#importing the modules cv2 and numpy
import cv2
import numpy as np
#reading the image to be normalized using imread() function
imageread = cv2.imread('C:/Users/admin/Desktop/educba.jpg')
#setting the array for resulting image after normalization
resultimage = np.zeros((800, 800))
#normalizing the given image using normalize() function
normalizedimage = cv2.normalize(imageread,resultimage, 0, 100, cv.NORM_MINMAX)
#displaying the normalized image as the output on the screen
cv2.imshow('Normalized_image', normalizedimage)
cv2.waitKey(0)
cv2.destroyAllWindows()
The output of the given program is shown in the snapshot below:
In the above program, we are importing the modules cv2 and NumPy. Then we are reading the image which is to be normalized using the imread() function. Then we making use of normalize() function by specifying the source_array, destination_array, alpha, beta, and normalization type which normalizes the given image. Then the normalized image is displayed as the output on the screen. The output is shown in the snapshot above.
Example #2
OpenCV program in python to demonstrate normalize() function to read an image using imread() function and then normalize the given image normalize() function and then display the resulting image as the output on the screen:
#importing the modules cv2 and numpy
import cv2
import numpy as np
#reading the image to be normalized using imread() function
imageread = cv2.imread('C:/Users/admin/Desktop/plane.jpg')
#setting the array for resulting image after normalization
resultimage = np.zeros((800, 800))
#normalizing the given image using normalize() function
normalizedimage = cv2.normalize(imageread, resultimage, 0, 100, cv.NORM_MINMAX)
#displaying the normalized image as the output on the screen
cv2.imshow('Normalized_image', normalizedimage)
cv2.waitKey(0)
cv2.destroyAllWindows()
The output of the given program is shown in the snapshot below:
In the above program, we are importing the module cv2 and numpy. Then we are reading the image which is to be normalized using imread() function. Then we making use of normalize() function by specifying the source_array, destination_array, alpha, beta, and normalization type which normalizes the given image. Then the normalized image is displayed as the output on the screen. The output is shown in the snapshot above.
Example #3
OpenCV program in python to demonstrate normalize() function to read an image using imread() function and then normalize the given image normalize() function and then display the resulting image as the output on the screen:
#importing the modules cv2 and numpy
import cv2
import numpy as np
#reading the image to be normalized using imread() function
imageread = cv2.imread('C:/Users/admin/Desktop/tree.jpg')
#setting the array for resulting image after normalization
resultimage = np.zeros((800, 800))
#normalizing the given image using normalize() function
normalizedimage = cv2.normalize(imageread, resultimage, 0, 100, cv.NORM_MINMAX)
#displaying the normalized image as the output on the screen
cv2.imshow('Normalized_image', normalizedimage)
cv2.waitKey(0)
cv2.destroyAllWindows()
The output of the given program is shown in the snapshot below:
In the above program, we are importing the modules cv2 and NumPy. Then we are reading the image which is to be normalized using imread() function. Then we making use of normalize() function by specifying the source_array, destination_array, alpha, beta, and normalization type which normalizes the given image. Then the normalized image is displayed as the output on the screen. The output is shown in the snapshot above.
Example #4
OpenCV program in python to demonstrate normalize() function to read an image using imread() function and then normalize the given image normalize() function and then display the resulting image as the output on the screen:
#importing the modules cv2 and numpy
import cv2
import numpy as np
#reading the image to be normalized using imread() function
imageread = cv2.imread('C:/Users/admin/Desktop/logo.png')
#setting the array for resulting image after normalization
resultimage = np.zeros((800, 800))
#normalizing the given image using normalize() function
normalizedimage = cv2.normalize(imageread, resultimage, 0, 100, cv.NORM_MINMAX)
#displaying the normalized image as the output on the screen
cv2.imshow('Normalized_image', normalizedimage)
cv2.waitKey(0)
cv2.destroyAllWindows()
The output of the given program is shown in the snapshot below:
In the above program, we are importing the modules cv2 and NumPy. Then we are reading the image which is to be normalized using imread() function. Then we making use of normalize() function by specifying the source_array, destination_array, alpha, beta, and normalization type which normalizes the given image. Then the normalized image is displayed as the output on the screen. The output is shown in the snapshot above.
Conclusion
In this article, we have learned the concept of normalize() function in OpenCV through definition, syntax, and working of normalize() function in OpenCV with corresponding programming examples and their outputs to demonstrate them.
Recommended Articles
We hope that this EDUCBA information on “OpenCV Normalize” was beneficial to you. You can view EDUCBA’s recommended articles for more information.