8/10/2023 0 Comments Pil image resize aspect ratio# We want the new image to be 60% of the original imageĬv2.destroyAllWindows() Original shape: (400, 600, 3) This way, you are sure that the aspect ratio of the original image will be the same as that of the new image. For example, if you want your new image to be half of the original image, then the scaling factor should be 0.5. Basically, a scaling factor is a number by which you multiply the dimension of the image. We can resize an image by using a scaling factor. Resizing with a Scaling Factor (Preserve Aspect Ratio) New_image = cv2.resize(image, dimensions, interpolation=cv2.INTER_LINEAR)Īs you can see, the new image is a bit distorted because we didn't take into account the aspect ratio. We can downscale or upscale an image when resizing it. Let's downscale the original image to 300x300 pixels: import cv2 Resizing with a Specific Width and Height (Don't Preserve Aspect Ratio) Edge and Contour Detection with OpenCV and Python.Morphological Operations with OpenCV and Python.Image Thresholding with OpenCV and Python.Image Filtering and Blurring with OpenCV and Python.Bitwise Operations and Image Masking with OpenCV and Python.How to Annotate Images with OpenCV and Python (coming soon).How to Rotate Images with OpenCV and Python.How to Crop Images with OpenCV and Python.How to Resize Images with OpenCV and Python (this article).How to Read and Write Videos with OpenCV and Python. How to Read, Write, and Save Images with OpenCV and Python.This article is part 3 of the tutorial series on computer vision and image processing with OpenCV: See InterpolationFlags for the list of options available. interpolation: (optional) The algorithm used to reconstruct the new pixels.fy: (optional) The scale factor along the vertical axis.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |