To upscale the original image, the variable “image_scale”, which holds the value of percentages, has to be increased. In the above snippet, the image has been downscaled to 30% of its original size. The console output shows the original and resized image dimensions after downscaling. The “ cv2.destroyallwindows()” will destroy all the windows (including the one showing us our resized image) before exiting the program so that the PC’s memory is not being consumed. Note: The “ cv2.waitKey(0)” will display the image until a key is pressed, or it will only move to the next line once it has been pressed. The function “ cv2.imshow()” takes the value of variable “ resized_img” as an argument.The resized image will be stored in the variable named “ resized_img”.The third parameter, “ cv2.INTER_AREA”, resamples the image using pixel area relation. The first parameter takes the file of the image variable, and the second parameter takes the dimension variable. The “ cv2.resize()” function takes three parameter values.The width and height dimensions will be saved in a variable named “ dimension”.The “ image.shape” is used for width, and “ image.shape” is used for height. The image scale number is divided by “100” and multiplied by the height and width of the original image.To downscale the image, we input “ 30”, which is stored in the variable “ image_scale”.100% means that the value has its original dimension. The variable “ image_scale” is used to store the percentage value of the image size.The parameter “ pic.shape” gets the original image’s dimensions.The flags specify how the function reads the image, such as in grayscale or color. The function named “cv2.imread()” takes two parameter values, the first parameter takes the path of the image and the second parameter takes the flags of the image.The Python library named “ cv2” is imported.Print('Resized Dimensions of our image is : ',resized_img.shape) Resized_img = cv2.resize(pic, dimension, interpolation = cv2.INTER_AREA) Height_img = int(pic.shape * image_scale / 100) Width_img = int(pic.shape * image_scale / 100) Print('Original Dimensions of our Image is : ',pic.shape) Pic = cv2.imread('itslinuxfoss.png', cv2.IMREAD_UNCHANGED)
0 Comments
Leave a Reply. |