日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

opencv python 图像测试上采样(升采样)(cv2.pyrUp()) 下采样(cv2.pyrDown()) 池化 滑动窗口(BorderTypes)

發(fā)布時(shí)間:2025/3/20 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv python 图像测试上采样(升采样)(cv2.pyrUp()) 下采样(cv2.pyrDown()) 池化 滑动窗口(BorderTypes) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

  • `from cv2.__init__.py`
  • 示例1:給圖片執(zhí)行兩次下采樣
  • 示例2:給圖片重復(fù)100次上下采樣

在學(xué)習(xí)tensorflow卷積神經(jīng)網(wǎng)絡(luò)時(shí),需要實(shí)現(xiàn)圖像的下采樣,于是便想手動(dòng)實(shí)現(xiàn)一下,但是發(fā)現(xiàn)有一點(diǎ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)情況下,輸出圖像的大小計(jì)算為`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)造的升采樣步驟,盡管實(shí)際上可以用來構(gòu)造拉普拉斯金字塔。 首先,它甚至通過注入零行和零列來對(duì)源圖像進(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)像素外推方法,請(qǐng)參見#BorderTypes(僅支持#BORDER_DEFAULT)"""pass

公式1:
mod表示取余操作

def pyrDown(src, dst=None, dstsize=None, borderType=None): # real signature unknown; restored from __doc__"""pyrDown(src[, dst[, dstsize[, borderType]]]) -> dst. @brief Blurs an image and downsamples it. 使圖像模糊并降低采樣率。. . By default, size of the output image is computed as `Size((src.cols+1)/2, (src.rows+1)/2)`, but in. any case, the following conditions should be satisfied:默認(rèn)情況下,輸出圖像的大小計(jì)算為`Size((src.cols + 1)/ 2,(src.rows + 1)/ 2)`,但是在任何情況下,都應(yīng)滿足以下條件:. . \f[\begin{array}{l} | \texttt{dstsize.width} *2-src.cols| \leq 2 \\ | \texttt{dstsize.height} *2-src.rows| \leq 2 \end{array}\f]. . The function performs the downsampling step of the Gaussian pyramid construction. First, it. convolves the source image with the kernel:該函數(shù)執(zhí)行高斯金字塔構(gòu)造的下采樣步驟。 首先,它將源映像與內(nèi)核進(jìn)行卷積:. . \f[\frac{1}{256} \begin{bmatrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4 & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix}\f]. . Then, it downsamples the image by rejecting even rows and columns.然后,它通過拒絕偶數(shù)行和列對(duì)圖像進(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 (#BORDER_CONSTANT isn't supported)像素外推方法,請(qǐng)參閱#BorderTypes(不支持#BORDER_CONSTANT)"""pass

公式1:
意思就是下采樣后的圖片尺寸的兩倍與原圖相比不會(huì)超過兩個(gè)像素

比如原圖尺寸為1920×1280,指定目標(biāo)圖片生成尺寸時(shí)
使用img = cv2.pyrDown(img, dstsize=(960, 640))可以
img = cv2.pyrDown(img, dstsize=(960, 641))可以
img = cv2.pyrDown(img, dstsize=(960, 642))就不行

公式2:

示例1:給圖片執(zhí)行兩次下采樣


代碼:

# -*- coding: utf-8 -*- """ @File : 20200119_圖像下采樣測(cè)試.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) img = cv2.pyrDown(img) img = cv2.pyrDown(img) # print(img.shape) # (320, 480, 3) cv2.imshow('win', img) cv2.waitKey(0)

結(jié)果:

示例2:給圖片重復(fù)100次上下采樣

# -*- coding: utf-8 -*- """ @File : 20200119_圖像下采樣測(cè)試.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é)果:圖片變模糊了(看見有一篇文章說在使用高斯變換處理上下采樣時(shí),只要圖像經(jīng)歷過下采樣,就一定會(huì)造成圖像信息損失)

參考文章1:OpenCV-Python——上采樣、下采樣與拉普拉斯金字塔

參考文章2:opencv cv::BorderTypes

總結(jié)

以上是生活随笔為你收集整理的opencv python 图像测试上采样(升采样)(cv2.pyrUp()) 下采样(cv2.pyrDown()) 池化 滑动窗口(BorderTypes)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。