opencv python 图像测试上采样(升采样)(cv2.pyrUp()) 下采样(cv2.pyrDown()) 池化 滑动窗口(BorderTypes)
文章目錄
- `from cv2.__init__.py`
- 示例1:給圖片執(zhí)行兩次下采樣
- 示例2:給圖片重復(fù)100次上下采樣
在學(xué)習(xí)tensorflow卷積神經(jīng)網(wǎng)絡(luò)時,需要實現(xiàn)圖像的下采樣,于是便想手動實現(xiàn)一下,但是發(fā)現(xiàn)有一點麻煩,于是便尋找看opencv是否有下采樣方法,找了下,還真有
When I was young, I desired to be a scientist after I grow up, but things always go oppsite to people’s wish, after suffering a seriels of …
以上純屬閉著眼睛打的
from cv2.__init__.py
def pyrUp(src, dst=None, dstsize=None, borderType=None): # real signature unknown; restored from __doc__"""pyrUp(src[, dst[, dstsize[, borderType]]]) -> dst. @brief Upsamples an image and then blurs it. 上采樣圖像,然后使其模糊。. . By default, size of the output image is computed as `Size(src.cols\*2, (src.rows\*2)`, but in any. case, the following conditions should be satisfied:默認(rèn)情況下,輸出圖像的大小計算為`Size(src.cols \ * 2,(src.rows \ * 2)`),但是在任何情況下,都應(yīng)滿足以下條件:. . \f[\begin{array}{l} | \texttt{dstsize.width} -src.cols*2| \leq ( \texttt{dstsize.width} \mod 2) \\ | \texttt{dstsize.height} -src.rows*2| \leq ( \texttt{dstsize.height} \mod 2) \end{array}\f]. . The function performs the upsampling step of the Gaussian pyramid construction, though it can. actually be used to construct the Laplacian pyramid. First, it upsamples the source image by. injecting even zero rows and columns and then convolves the result with the same kernel as in. pyrDown multiplied by 4.該函數(shù)執(zhí)行高斯金字塔構(gòu)造的升采樣步驟,盡管實際上可以用來構(gòu)造拉普拉斯金字塔。 首先,它甚至通過注入零行和零列來對源圖像進(jìn)行升采樣,然后將結(jié)果與與pyrDown中相同的內(nèi)核乘以4進(jìn)行卷積。. . @param src input image.. @param dst output image. It has the specified size and the same type as src .輸出圖像。 它具有指定的大小,并且與src類型相同。. @param dstsize size of the output image.. @param borderType Pixel extrapolation method, see #BorderTypes (only #BORDER_DEFAULT is supported)像素外推方法,請參見#BorderTypes(僅支持#BORDER_DEFAULT)"""pass公式1:
mod表示取余操作
公式1:
意思就是下采樣后的圖片尺寸的兩倍與原圖相比不會超過兩個像素
比如原圖尺寸為1920×1280,指定目標(biāo)圖片生成尺寸時
使用img = cv2.pyrDown(img, dstsize=(960, 640))可以
img = cv2.pyrDown(img, dstsize=(960, 641))可以
img = cv2.pyrDown(img, dstsize=(960, 642))就不行
公式2:
示例1:給圖片執(zhí)行兩次下采樣
代碼:
結(jié)果:
示例2:給圖片重復(fù)100次上下采樣
# -*- coding: utf-8 -*- """ @File : 20200119_圖像下采樣測試.py @Time : 2020/1/19 9:35 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """ import cv2 img = cv2.imread('girl-3421489_1920.jpg') # print(img.shape) # (1280, 1920, 3) for i in range(100):img = cv2.pyrUp(img)img = cv2.pyrDown(img) # print(img.shape) # (320, 480, 3) cv2.imshow('win', img) cv2.waitKey(0)結(jié)果:圖片變模糊了(看見有一篇文章說在使用高斯變換處理上下采樣時,只要圖像經(jīng)歷過下采樣,就一定會造成圖像信息損失)
參考文章1:OpenCV-Python——上采樣、下采樣與拉普拉斯金字塔
參考文章2:opencv cv::BorderTypes
總結(jié)
以上是生活随笔為你收集整理的opencv python 图像测试上采样(升采样)(cv2.pyrUp()) 下采样(cv2.pyrDown()) 池化 滑动窗口(BorderTypes)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python opencv 官方文档里L
- 下一篇: opencv cv::BorderTyp