使用 OpenCV 降取樣影像
在本程式中,我們將對影像進行下采樣。下采樣是降低空間解析度但保留影像的 2D 表示。通常用於縮小影像。我們將使用 openCV 庫中的 pyrdown() 函式來完成此任務。
原始影像
演算法
Step 1: Fead the image. Step 2: Pass the image as a parameter to the pyrdown() function. Step 3: Display the output.
示例程式碼
import cv2 image = cv2.imread('testimage.jpg') print("Size of image before pyrDown: ", image.shape) image = cv2.pyrDown(image) print("Size of image after pyrDown: ", image.shape) cv2.imshow('DownSample', image)
輸出
Size of image before pyrDown: (350, 700, 3) Size of image after pyrDown: (175, 350, 3)
說明
如果我們觀察在使用 pyrDown 函式之前和之後影像的大小,會發現大小減小,即我們對影像進行了下采樣。
廣告