cv2.convertScaleAbs
时间: 2024-01-01 13:03:44 浏览: 18
cv2.convertScaleAbs is a function in OpenCV library in Python used to convert an image from one data type to another and then apply an absolute transformation. This function is used for linear scaling of pixel values from one range to another range. It is commonly used to enhance the contrast of an image.
Syntax: cv2.convertScaleAbs(src, alpha, beta)
Parameters:
src: It is the source or input image of type uint8 or float32.
alpha: It is a scalar used to multiply pixel values.
beta: It is a scalar used to add to pixel values.
Return Value: It returns the converted image of type uint8.
Example:
import cv2
img = cv2.imread('image.jpg')
converted_img = cv2.convertScaleAbs(img, alpha=2, beta=50)
cv2.imshow('Original Image', img)
cv2.imshow('Converted Image', converted_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
In the above example, the input image is read using the imread() function. Then the convertScaleAbs() function is used to convert the image by multiplying pixel values by 2 and adding 50 to them. The converted image is then displayed using the imshow() function. Finally, the waitKey() function is used to wait until a key is pressed and the destroyAllWindows() function is used to close all windows.